forked from spicetify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·120 lines (97 loc) · 2.99 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env sh
# Copyright 2022 khanhas. GPL license.
# Edited from project Denoland install script (https://github.com/denoland/deno_install)
set -e
# wipe existing log
> install.log
log() {
echo $1
echo "["$(date +'%H:%M:%S %Y-%m-%d')"]" $1 >> install.log
}
case $(uname -sm) in
"Darwin x86_64") target="darwin-amd64" ;;
"Darwin arm64") target="darwin-arm64" ;;
"Linux x86_64") target="linux-amd64" ;;
"Linux aarch64") target="linux-arm64" ;;
*) log "Unsupported platform $(uname -sm). x86_64 and arm64 binaries for Linux and Darwin are available."; exit ;;
esac
# check for dependencies
command -v curl >/dev/null || { log "curl isn't installed\!" >&2; exit 1; }
command -v tar >/dev/null || { log "tar isn't installed\!" >&2; exit 1; }
command -v grep >/dev/null || { log "grep isn't installed\!" >&2; exit 1; }
# download uri
releases_uri=https://github.com/spicetify/spicetify-cli/releases
if [ $# -gt 0 ]; then
tag=$1
else
tag=$(curl -LsH 'Accept: application/json' $releases_uri/latest)
tag=${tag%\,\"update_url*}
tag=${tag##*tag_name\":\"}
tag=${tag%\"}
fi
tag=${tag#v}
log "FETCHING Version $tag"
download_uri=$releases_uri/download/v$tag/spicetify-$tag-$target.tar.gz
# locations
spicetify_install="$HOME/.spicetify"
exe="$spicetify_install/spicetify"
tar="$spicetify_install/spicetify.tar.gz"
# installing
[ ! -d "$spicetify_install" ] && log "CREATING $spicetify_install" && mkdir -p "$spicetify_install"
log "DOWNLOADING $download_uri"
curl --fail --location --progress-bar --output "$tar" "$download_uri"
log "EXTRACTING $tar"
tar xzf "$tar" -C "$spicetify_install"
log "SETTING EXECUTABLE PERMISSIONS TO $exe"
chmod +x "$exe"
log "REMOVING $tar"
rm "$tar"
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
}
endswith_newline() {
[[ $(tail -c1 "$1" | wc -l) -gt 0 ]]
}
check() {
local path="export PATH=\$PATH:$spicetify_install"
local shellrc=$HOME/$1
if [ "$1" == ".zshrc" ] && [ ! -z "${ZDOTDIR}" ]; then
shellrc=$ZDOTDIR/$1
fi
# Create shellrc if it doesn't exist
if ! [ -f $shellrc ]; then
log "CREATING $shellrc"
touch $shellrc
fi
# Still checking again, in case touch command failed
if [ -f $shellrc ]; then
if ! grep -q $spicetify_install $shellrc; then
log "APPENDING $spicetify_install to PATH in $shellrc"
if ! endswith_newline $shellrc; then
echo >> $shellrc
fi
echo ${2:-$path} >> $shellrc
log "Restart your shell to have spicetify in your PATH."
else
log "spicetify path already set in $shellrc, continuing..."
fi
else
notfound
fi
}
case $SHELL in
*zsh) check ".zshrc" ;;
*bash)
[ -f "$HOME/.bashrc" ] && check ".bashrc"
[ -f "$HOME/.bash_profile" ] && check ".bash_profile"
;;
*fish) check ".config/fish/config.fish" "fish_add_path $spicetify_install" ;;
*) notfound ;;
esac
echo
log "spicetify v$tag was installed successfully to $spicetify_install"
log "Run 'spicetify --help' to get started"