Skip to content

Commit

Permalink
feat: start of install script for *nix
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrutchf committed Dec 10, 2024
1 parent fae7dda commit 46542fd
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Invoke-InstallScript {
# Determine OS and Architecture
$osPlatform = [System.Runtime.InteropServices.RuntimeInformation]::OSDescription

# Adjust the platform and architecture for the API call
# Adjust the platform and architecture for the downloaded package.
$platform = switch -Wildcard ($osPlatform) {
"*Windows*" { "win" }
"*Linux*" { "linux" }
Expand Down Expand Up @@ -51,6 +51,7 @@ function Invoke-InstallScript {
Write-Error "$assetName is not published. Please file an issue."
}

# Get the target directory
$homeDirectory = Get-Item ~
$gitLfsSynologyDirectory = ".git-lfs-synology"
$targetPath = Join-Path $homeDirectory $gitLfsSynologyDirectory
Expand Down
76 changes: 76 additions & 0 deletions scripts/install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#! /usr/bin/python3

import urllib.request
import json
import datetime
import platform
import os
import shutil
import zipfile

from pathlib import Path

def main():
# Get all releases
releases = json.load(urllib.request.urlopen("https://api.github.com/repos/ucsd-e4e/git-lfs-synology/releases"))

# Get the latest release
max_date = max(datetime.datetime.fromisoformat(r["published_at"]) for r in releases)
latest_release = [r for r in releases if datetime.datetime.fromisoformat(r["published_at"]) == max_date][0]

# Adjust the platform and architecture for the downloaded package.
if platform.system() == "Windows":
target_platform = "win"
elif platform.system() == "Linux":
target_platform = "linux"
elif platform.system() == "Darwin":
target_platform = "osx"
else:
target_platform = platform.system()

if platform.machine() == "AMD64":
arch = "x86_64"
else:
arch = platform.machine()

# Construct the asset name.
asset_name = f"git-lfs-synology.{target_platform}-{arch}.zip"

# Get the Asset
asset = [a for a in latest_release["assets"] if a["name"] == asset_name][0]

# Get the target directory
home_directory = Path.home()
gitLfsSynologyDirectory = ".git-lfs-synology"
target_path = home_directory / gitLfsSynologyDirectory

if target_path.exists:
shutil.rmtree(target_path)
target_path.mkdir(parents=True)

current_dir = os.getcwd()
os.chdir(target_path)

# Get the executable
urllib.request.urlretrieve(asset["browser_download_url"], asset["name"])
with zipfile.ZipFile(asset["name"], 'r') as zip_ref:
zip_ref.extractall(".")

os.chdir(current_dir)

# Update the Path Environment Variable
if target_path.as_posix() not in os.environ["PATH"]:
if target_path == "win":
seperator = ";"
else:
seperator = ":"

os.environ["PATH"] = f"{target_path}{seperator}{os.environ["PATH"]}"

# TODO: Update system PATH environment variable

# TODO Login and Configure.


if __name__ == "__main__":
main()

0 comments on commit 46542fd

Please sign in to comment.