-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: scripts to install or update uosc with a single command (#691)
- Loading branch information
1 parent
7467e18
commit b7529ea
Showing
3 changed files
with
184 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/bin/bash | ||
zip_url=https://github.com/tomasklaen/uosc/releases/latest/download/uosc.zip | ||
conf_url=https://github.com/tomasklaen/uosc/releases/latest/download/uosc.conf | ||
zip_file=/tmp/uosc.zip | ||
|
||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
cleanup() { | ||
if [ -f "$zip_file" ]; then | ||
echo "Deleting: $zip_file" | ||
rm -f $zip_file | ||
fi | ||
} | ||
|
||
abort() { | ||
cleanup | ||
echo "Error: $1" | ||
exit 1 | ||
} | ||
|
||
# Check OS | ||
OS="$(uname)" | ||
if [ "${OS}" == "Linux" ]; then | ||
data_dir="${XDG_CONFIG_HOME:-$HOME/.config}/mpv" | ||
elif [ "${OS}" == "Darwin" ]; then | ||
data_dir=~/Library/Preferences/mpv | ||
else | ||
abort "This install script works only on linux and macOS." | ||
fi | ||
|
||
# Ensure directory exists | ||
mkdir -pv $data_dir | ||
|
||
# Remove old and deprecated folders & files | ||
echo "Deleting old and deprecated uosc files and directories." | ||
rm -rf "$data_dir/scripts/uosc_shared" || abort "Couldn't cleanup old files." | ||
rm -rf "$data_dir/scripts/uosc" || abort "Couldn't cleanup old files." | ||
rm -f "$data_dir/scripts/uosc.lua" || abort "Couldn't cleanup old files." | ||
|
||
# Install new version | ||
echo "Downloading: $zip_url" | ||
curl -L -o $zip_file $zip_url || abort "Couldn't download the archive." | ||
echo "Extracting: $zip_file" | ||
unzip -od $data_dir $zip_file || abort "Couldn't extract the archive." | ||
cleanup | ||
|
||
# Download default config if one doesn't exist yet | ||
scriptopts_dir="$data_dir/script-opts" | ||
conf_file="$scriptopts_dir/uosc.conf" | ||
if [ ! -f "$conf_file" ]; then | ||
echo "Config not found, downloading default one..." | ||
mkdir -pv $scriptopts_dir | ||
echo "Downloading: $conf_url" | ||
curl -L -o $conf_file $conf_url || abort "Couldn't download the config file, but uosc should be installed correctly." | ||
fi | ||
|
||
echo "uosc has been installed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
$ZipURL = "https://github.com/tomasklaen/uosc/releases/latest/download/uosc.zip" | ||
$ConfURL = "https://github.com/tomasklaen/uosc/releases/latest/download/uosc.conf" | ||
|
||
# Portable vs AppData install | ||
if (Test-Path "$PWD/portable_config") { | ||
$DataDir = "$PWD/portable_config" | ||
Write-Output "Portable mode: $DataDir" | ||
} | ||
elseif ((Get-Item -Path $PWD).BaseName -eq "portable_config") { | ||
$DataDir = "$PWD" | ||
Write-Output "Portable mode: $DataDir" | ||
} | ||
else { | ||
$DataDir = "$env:APPDATA/mpv" | ||
Write-Output "AppData mode: $DataDir" | ||
if (!(Test-Path $DataDir)) { | ||
Write-Output "Creating folder: $DataDir" | ||
New-Item -ItemType Directory -Force -Path $DataDir > $null | ||
} | ||
} | ||
|
||
$ZipFile = "$DataDir/uosc_tmp.zip" | ||
|
||
Function Cleanup() { | ||
try { | ||
if (Test-Path $ZipFile) { | ||
Write-Output "Deleting: $ZipFile" | ||
Remove-Item -LiteralPath $ZipFile -Force | ||
} | ||
} | ||
catch {} | ||
} | ||
|
||
Function Abort($Message) { | ||
Cleanup | ||
Write-Output "Error: $Message" | ||
Exit 1 | ||
} | ||
|
||
# Remove old or deprecated folders & files | ||
try { | ||
$UoscDir = "$DataDir/scripts/uosc" | ||
$UoscDeprecatedDir = "$DataDir/scripts/uosc_shared" | ||
$UoscDeprecatedFile = "$DataDir/scripts/uosc.lua" | ||
if (Test-Path $UoscDir) { | ||
Write-Output "Deleting old: $UoscDir" | ||
Remove-Item -LiteralPath $UoscDir -Force -Recurse | ||
} | ||
if (Test-Path $UoscDeprecatedDir) { | ||
Write-Output "Deleting deprecated: $UoscDeprecatedDir" | ||
Remove-Item -LiteralPath $UoscDeprecatedDir -Force -Recurse | ||
} | ||
if (Test-Path $UoscDeprecatedFile) { | ||
Write-Output "Deleting deprecated: $UoscDeprecatedFile" | ||
Remove-Item -LiteralPath $UoscDeprecatedFile -Force | ||
} | ||
} | ||
catch { | ||
Abort("Couldn't cleanup old files.") | ||
} | ||
|
||
# Install new version | ||
try { | ||
Write-Output "Downloading: $ZipURL" | ||
Invoke-WebRequest -OutFile $ZipFile -Uri $ZipURL > $null | ||
} | ||
catch { | ||
Abort("Couldn't download the archive.") | ||
} | ||
try { | ||
Write-Output "Extracting: $ZipFile" | ||
Expand-Archive $ZipFile -DestinationPath $DataDir -Force > $null | ||
} | ||
catch { | ||
Abort("Couldn't extract the archive.") | ||
} | ||
Cleanup | ||
|
||
# Download default config if one doesn't exist yet | ||
try { | ||
$ScriptOptsDir = "$DataDir/script-opts" | ||
$ConfFile = "$ScriptOptsDir/uosc.conf" | ||
if (!(Test-Path $ConfFile)) { | ||
Write-Output "Config not found, downloading default one..." | ||
New-Item -ItemType Directory -Force -Path $ScriptOptsDir > $null | ||
Write-Output "Downloading: $ConfURL" | ||
Invoke-WebRequest -OutFile $ConfFile -Uri $ConfURL > $null | ||
} | ||
} | ||
catch { | ||
Abort("Couldn't download the config file, but uosc should be installed correctly.") | ||
} | ||
|
||
Write-Output "uosc has been installed." |