Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restructure install.sh #1535

Merged
merged 7 commits into from
Mar 30, 2022
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
afonsojramos marked this conversation as resolved.
Show resolved Hide resolved
# 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"