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 2 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
94 changes: 38 additions & 56 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,75 +1,57 @@
#!/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" ;;
*) echo "Unsupported platform $(uname -sm). Only Darwin x86_64, Darwin arm64 and Linux x86_64 binaries are available."; exit ;;
afonsojramos marked this conversation as resolved.
Show resolved Hide resolved
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
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; }

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
tag=$(curl -LsH 'Accept: application/json' $shortcut/releases/latest)
tag=${tag%\,\"update_url*}
tag=${tag##*tag_name\":\"}
tag=${tag%\"}
download_uri="$shortcut/releases/download/$tag/spicetify-${tag#v}-$target.tar.gz"
unset tag
afonsojramos marked this conversation as resolved.
Show resolved Hide resolved

# locations
spicetify_install="${XDG_DATA_HOME:-$HOME/.local/share}/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
[ ! -d "$spicetify_install" ] && echo "CREATING $spicetify_install" && mkdir -p "$spicetify_install"
echo "DOWNLOADING $download_uri"
curl --fail --location --progress-bar --output "$tar" "$download_uri"

tar_file="$exe.tar.gz"
echo "EXTRACTING $tar"
tar xzf "$tar" -C "$spicetify_install"

echo "DOWNLOADING $download_uri"
curl --fail --location --progress-bar --output "$tar_file" "$download_uri"
cd "$spicetify_install"
echo "SETTING EXECUTABLE PERMISSIONS TO $exe"
chmod +x "$exe"

echo "EXTRACTING $tar_file"
tar xzf "$tar_file"
echo "REMOVING $tar"
rm "$tar"

chmod +x "$exe"
echo "spicetify was installed successfully to $spicetify_install"

cat << EOINFO

Manually add the directory to your \$PATH through your shell profile
export SPICETIFY_INSTALL="$spicetify_install"
export PATH="\$PATH:$spicetify_install"

echo "REMOVING $tar_file"
rm "$tar_file"
for zsh: $HOME/.zshrc
for bash: $HOME/.bashrc
for fish: $HOME/.config/fish/config.fish

echo ""
echo "spicetify was installed successfully to $exe"
echo ""
EOINFO

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