diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a98597..2e6e214 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,5 @@ +name: build and release + on: push: branch: @@ -12,16 +14,19 @@ jobs: - windows - macos architecture: ['x64'] - app: ['cli', 'api'] + app: ['cli', 'api', updater] include: - os: windows data-file: "data/schema.sql;schema.sql" + name: windows - os: macos data-file: "data/schema.sql:schema.sql" + name: macos - os: ubuntu data-file: "data/schema.sql:schema.sql" + name: linux runs-on: ${{ matrix.os }}-latest - name: ${{ matrix.app }}-${{ matrix.os }}-${{ matrix.architecture }} + name: ${{ matrix.app }}-${{ matrix.name }}-${{ matrix.architecture }} steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 @@ -31,11 +36,11 @@ jobs: - run: pip install -r requirements.txt pyinstaller - run: mkdir build - run: mkdir bin - - run: pyinstaller --distpath bin --clean --add-data "${{ matrix.data-file }}" --onefile --name npbc_${{ matrix.app }}-${{ matrix.os }}-${{ matrix.architecture }} npbc_${{ matrix.app }}.py + - run: pyinstaller --distpath bin --clean --add-data "${{ matrix.data-file }}" --onefile --name npbc_${{ matrix.app }}-${{ matrix.name }}-${{ matrix.architecture }} npbc_${{ matrix.app }}.py - uses: actions/upload-artifact@v2 with: path: bin - name: npbc_${{ matrix.app }}-${{ matrix.os }}-${{ matrix.architecture }} + name: npbc_${{ matrix.app }}-${{ matrix.name }}-${{ matrix.architecture }} release: needs: diff --git a/install/install.bat b/install/install.bat deleted file mode 100644 index e13523d..0000000 --- a/install/install.bat +++ /dev/null @@ -1,12 +0,0 @@ -git clone https://github.com/eccentricOrange/npbc.git "%APPDATA%\npbc" - -if exist "%USERPROFILE%\.npbc\" ( - echo "Not updating user directory." -) else ( - xcopy /s "%APPDATA%\npbc\data\." "%USERPROFILE%\.npbc\" -) - -@REM setx path "%PATH%;%APPDATA%\npbc\bin" -@REM -@REM This is disabled right now because I am struggling -@REM with the 1024 character limit of setx. \ No newline at end of file diff --git a/install/install.sh b/install/install.sh deleted file mode 100755 index 76b8b01..0000000 --- a/install/install.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -git clone https://github.com/eccentricOrange/npbc.git ~/bin/npbc -dir=~/.npbc -if [[ ! -d "$dir" ]]; then - cp -r ~/bin/npbc/data ~/.npbc/ -fi -chmod +x ~/bin/npbc/bin/linnpbc.sh -echo 'alias npbc=~/bin/npbc/bin/linnpbc.sh' >> ~/.bashrc -alias npbc=~/bin/npbc/bin/linnpbc.sh diff --git a/install/piinstall.sh b/install/piinstall.sh deleted file mode 100755 index fdc729b..0000000 --- a/install/piinstall.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -git clone https://github.com/eccentricOrange/npbc.git ~/bin/npbc -dir=~/.npbc -if [[ ! -d "$dir" ]]; then - cp -r ~/bin/npbc/data ~/.npbc/ -fi -chmod +x ~/bin/npbc/bin/pinpbc.sh -echo 'alias npbc=~/bin/npbc/bin/pinpbc.sh' >> ~/.bashrc -alias npbc=~/bin/npbc/bin/pinpbc.sh diff --git a/npbc_updater.py b/npbc_updater.py new file mode 100644 index 0000000..feb051d --- /dev/null +++ b/npbc_updater.py @@ -0,0 +1,62 @@ +from subprocess import call +from platform import system as get_platform_data +from sys import argv +from pathlib import Path +from urllib.request import urlopen + + +location_data = { + "Linux": { + "name": "ubuntu-x64", + "path": Path.home() / 'bin' / 'npbc' + }, + "Windows": { + "name": "win-x64.exe", + "path": Path('C:') / 'Program Files' / 'npbc' + }, + "Darwin": { + "name": "mac-x64", + "path": Path.home() / 'Applictaions' / 'npbc' + } +} + + +class NPBC_updater: + def __init__(self): + self.current_platform_data = location_data[get_platform_data()] + self.current_platform_data['path'].mkdir(parents=True, exist_ok=True) + self.cli_path = self.current_platform_data['path'] / \ + f"npbc_cli-{self.current_platform_data['name']}" + self.api_path = self.current_platform_data['path'] / \ + f"npbc_api-{self.current_platform_data['name']}" + self.cli_url = f"https://github.com/eccentricOrange/npbc/releases/latest/download/npbc_cli-{self.current_platform_data['name']}" + self.api_url = f"https://github.com/eccentricOrange/npbc/releases/latest/download/npbc_api-{self.current_platform_data['name']}" + + def read_args(self): + if argv[1].strip().lower() == "update": + self.update() + + else: + self.execute() + + def update(self): + cli_download = urlopen(self.cli_url).read() + api = urlopen(self.api_url).read() + + with open(self.cli_path, 'wb') as cli_file: + cli_file.write(cli_download) + + with open(self.api_path, 'wb') as api_file: + api_file.write(api) + + def execute(self): + call([self.cli_path, *argv[1:]]) + + +def main(): + updater = NPBC_updater() + updater.read_args() + + +if __name__ == "__main__": + main()