Skip to content

Commit

Permalink
chore: restructure install.sh (spicetify#1535)
Browse files Browse the repository at this point in the history
* change script

* add adding to shell profile

* add arm64

* remove arm64 and add aarch64

Co-authored-by: Afonso Jorge Ramos <[email protected]>
  • Loading branch information
apprehensions and afonsojramos authored Mar 30, 2022
1 parent 19628ea commit a82586b
Showing 1 changed file with 62 additions and 56 deletions.
118 changes: 62 additions & 56 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,75 +1,81 @@
#!/bin/sh
#!/usr/bin/env sh
# Copyright 2022 khanhas. GPL license.
# Edited from project Denoland install script (https://github.com/denoland/deno_install)

set -e

case $(uname -sm) in
"Darwin x86_64") target="darwin-amd64" ;;
"Darwin arm64") target="darwin-arm64" ;;
"Linux x86_64") target="linux-amd64" ;;
*)
echo "Unsupported platform $(uname -sm). Only Darwin x86_64, Darwin arm64 and Linux x86_64 binaries are available."
exit
;;
"Darwin x86_64") target="darwin-amd64" ;;
"Darwin arm64") target="darwin-arm64" ;;
"Linux x86_64") target="linux-amd64" ;;
"Linux aarch64") target="linux-arm64" ;;
*) echo "Unsupported platform $(uname -sm). x86_64 and arm64 binaries for Linux and Darwin are available."; exit ;;
esac

if [ $# -eq 0 ]; then
latest_release_uri="https://api.github.com/repos/spicetify/spicetify-cli/releases/latest"
echo "DOWNLOADING $latest_release_uri"
spicetify_asset_path=$(
command curl -sSf "$latest_release_uri" |
command grep -o "/spicetify/spicetify-cli/releases/download/.*/spicetify-.*-${target}\\.tar\\.gz" |
command head -n 1
)
if [ ! "$spicetify_asset_path" ]; then exit 1; fi
download_uri="https://github.com${spicetify_asset_path}"
else
download_uri="https://github.com/spicetify/spicetify-cli/releases/download/v${1}/spicetify-${1}-${target}.tar.gz"
fi
# check for dependencies
command -v curl >/dev/null || { echo "curl isn't installed\!" >&2; exit 1; }
command -v tar >/dev/null || { echo "tar isn't installed\!" >&2; exit 1; }
command -v grep >/dev/null || { echo "grep isn't installed\!" >&2; exit 1; }

spicetify_install="$HOME/.spicetify"
path="export PATH=\"\$PATH:\$HOME/.spicetify\""

if (grep -q "bash" $SHELL || [[ -f "$HOME/.bashrc" ]]) && ! grep -q "$path" "$HOME/.bashrc"; then echo "${path}" >>"$HOME/.bashrc" && echo "SAVING ${spicetify_install} to \$PATH (bash)"; fi
if (grep -q "zsh" $SHELL || [[ -f "$HOME/.zshrc" ]]) && ! grep -q "$path" "$HOME/.zshrc"; then echo "${path}" >>"$HOME/.zshrc" && echo "SAVING ${spicetify_install} to \$PATH (zsh)"; fi
if [[ -f "$HOME/.config/fish/config.fish" ]] && ! grep -q "$path" "$HOME/.config/fish/config.fish"; then echo "${path}" >>"$HOME/.config/fish/config.fish" && echo "SAVING ${spicetify_install} to \$PATH (fish)"; fi
# download uri
shortcut=https://github.com/spicetify/spicetify-cli/releases
tag=$(curl -LsH 'Accept: application/json' $shortcut/latest)
tag=${tag%\,\"update_url*}
tag=${tag##*tag_name\":\"}
tag=${tag%\"}
download_uri=$shortcut/download/$tag/spicetify-${tag#v}-$target.tar.gz

# locations
spicetify_install="$HOME/.spicetify"
exe="$spicetify_install/spicetify"
tar="$spicetify_install/spicetify.tar.gz"

if [ ! -d "$spicetify_install" ]; then
echo "Creating $spicetify_install"
mkdir -p "$spicetify_install"
fi

tar_file="$exe.tar.gz"
# installing
[ ! -d "$spicetify_install" ] && echo "CREATING $spicetify_install" && mkdir -p "$spicetify_install"

echo "DOWNLOADING $download_uri"
curl --fail --location --progress-bar --output "$tar_file" "$download_uri"
cd "$spicetify_install"
echo "DOWNLOADING $download_uri"
curl --fail --location --progress-bar --output "$tar" "$download_uri"

echo "EXTRACTING $tar_file"
tar xzf "$tar_file"
echo "EXTRACTING $tar"
tar xzf "$tar" -C "$spicetify_install"

echo "SETTING EXECUTABLE PERMISSIONS TO $exe"
chmod +x "$exe"

echo "REMOVING $tar_file"
rm "$tar_file"
echo "REMOVING $tar"
rm "$tar"

echo ""
echo "spicetify was installed successfully to $exe"
echo ""
notfound() {
cat << EOINFO
Manually add the directory to your \$PATH through your shell profile
export SPICETIFY_INSTALL="$spicetify_install"
export PATH="\$PATH:$spicetify_install"
EOINFO
}

check() {
local path="export PATH=\$PATH:$spicetify_install"
local shellrc=$HOME/$1
if [ -f $shellrc ]; then
if ! grep -q $spicetify_install $shellrc; then
echo "APPENDING $spicetify_install to PATH in $shellrc"
echo ${2:-$path} >> $shellrc
echo "Restart your shell to have spicetify in your PATH."
else
echo "spicetify path already set in $shellrc, continuing..."
fi
else
notfound
fi
}

case $SHELL in
*zsh) check ".zshrc" ;;
*bash) check ".bashrc" ;;
*fish) check ".config/fish/config.fish" "fish_add_path $spicetify_install" ;;
*) notfound ;;
esac

if command -v spicetify >/dev/null; then
echo "Run 'spicetify --help' to get started"
elif [[ "$spicetify_install" == *".spicetify"* ]]; then
echo "Please restart your Terminal to have spicetify in your PATH."
echo "Then you can run:"
echo "'spicetify --help' to get started"
else
echo "Manually add the directory to your \$HOME/.bash_profile (or similar)"
echo " export SPICETIFY_INSTALL=\"$spicetify_install\""
echo " export PATH=\"\$SPICETIFY_INSTALL:\$PATH\""
echo ""
echo "Run '$exe --help' to get started"
fi
echo
echo "spicetify $tag was installed successfully to $spicetify_install"
echo "Run 'spicetify --help' to get started"

0 comments on commit a82586b

Please sign in to comment.