-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
executable file
·250 lines (204 loc) · 7.85 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env bash
#################
# app installer #
# COMPILE #
#################
VER="v0.12"
CYAN='\033[0;36m'
GREEN='\033[1;32m'
NC='\033[0m'
echo -e "\n📦️ Installing:"
echo -e "${CYAN}
_____ ______ ______
\__ \ \____ \\____ \
/ __ \| |_> > |_> >
(____ / __/| __/
\/|__| |__|
${NC}"
echo -e "🚀️ ${GREEN}The Cross-Platform Package Management Assistant with Super Powers${NC}\n"
USEROS=""
echo -e "🐧️ Detecting OS..."
if [[ "$OSTYPE" == "linux"* ]]; then
USEROS="linux"
echo -e "\n🐧️ Linux\n"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
USEROS="freebsd"
echo -e "\n🅱️ FreeBSD\n"
elif [[ "$OSTYPE" == "darwin"* ]]; then
USEROS="darwin"
echo -e "\n🍎️ MacOS"
else
echo -e "❌️ Operating System not supported... Exiting...\n"
exit 1
fi
echo -e "💻️ Detecting CPU arch...\n"
CPUARCH=""
UNAMEM=$(uname -m)
echo -e "🏰️: $UNAMEM\n"
if [[ "$UNAMEM" == "x86_64" ]] || [[ "$UNAMEM" == "amd64" ]]; then
CPUARCH="amd64"
elif [[ "$UNAMEM" == "arm" ]]; then
CPUARCH="arm64"
else
echo -e "❌️ CPU Architecture not supported... Exiting...\n"
exit 1
fi
echo -e "✅️ Dependencies check...\n"
UCHECK="$(whereis unzip)"
UL=${#UCHECK}
if [[ $UL -lt 7 ]]; then
echo -e "\n❌️ unzip is not installed on this system. Install it and run the install command again...\n"
exit 1
fi
CCHECK="$(whereis curl 2>&1)"
CL=${#CCHECK}
if [[ $CL -lt 6 ]]; then
echo -e "\n❌️ curl is not installed on this system. Install it and run the install command again...\n"
exit 1
fi
echo -e "✅️ Detecting shell...\n"
SHELLTYPE=$(basename ${SHELL})
echo -e "🐚️ shell: $SHELLTYPE"
SHELLRC="none"
SHELLPROFILE="$HOME/.config/app/.app_profile"
if [[ $SHELLTYPE == "sh" ]]; then
SHELLRC="$HOME/.shrc"
fi
if [[ $SHELLTYPE == "csh" ]]; then
SHELLRC="$HOME/.cshrc"
fi
if [[ $SHELLTYPE == "ksh" ]]; then
SHELLRC="$HOME/.kshrc"
fi
if [[ $SHELLTYPE == "tcsh" ]]; then
SHELLRC="$HOME/.tcshrc"
fi
if [[ $SHELLTYPE == "bash" ]]; then
SHELLRC="$HOME/.bashrc"
fi
if [[ $SHELLTYPE == "zsh" ]]; then
SHELLRC="$HOME/.zshrc"
fi
if [[ $SHELLTYPE == "fish" ]]; then
SHELLRC="$HOME/.config/fish/config.fish"
fi
if [[ $SHELLRC == "none" ]]; then
echo -e "\n❌️ Unrecognized shell... app only supports sh, csh, ksh, tcsh, bash, zsh, and fish... exiting...\n"
exit 1
fi
echo -e "🐚️ config: $SHELLRC\n"
echo -e "✅️ Create app config dir if not already created...\n"
if [[ ! -d "$HOME/.config/app" ]]; then
mkdir -p $HOME/.config/app
if [[ $? -ne 0 ]] ; then
echo -e "\n❌️ Failed to create $HOME/.config/app... Exiting...\n"
exit 1
fi
fi
echo -e "✅️ Making sure there's a $HOME/.local/bin...\n"
if [[ ! -d "$HOME/.local/bin" ]]; then
mkdir -p $HOME/.local/bin
if [[ $? -ne 0 ]] ; then
echo -e "\n❌️ Failed to create $HOME/.local/bin... Exiting...\n"
exit 1
fi
fi
echo -e "✅️ Making sure $HOME/.local/bin is in PATH...\n"
if [[ -f $SHELLPROFILE ]]; then
PCHECK=$(grep ".local/bin" $SHELLPROFILE)
if [[ "$PCHECK" == "" ]]; then
echo -e "\nif [ -d \"$HOME/.local/bin\" ]; then\n\tPATH=\"$HOME/.local/bin:\$PATH\"\nfi" >> $SHELLPROFILE
echo -e "\n# Added by app (https://github.com/hkdb/app) installation\nsource $SHELLPROFILE" >> $SHELLRC
fi
else
echo -e "\nif [ -d \"$HOME/.local/bin\" ]; then\n\tPATH=\"$HOME/.local/bin:\$PATH\"\nfi" >> $SHELLPROFILE
echo -e "\n# Added by app (https://github.com/hkdb/app) installation\nsource $SHELLPROFILE" >> $SHELLRC
fi
DISTRO=""
PKGMGR=""
IFLAG=""
if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "linux" ]]; then
echo -e "🐧️ Detecting distro...\n"
OSR=$(cat /etc/os-release |grep ^NAME)
OSRNV=${OSR:5}
DIST=${OSRNV:1:${#OSRNV}-2}
echo -e "\nOS: Linux\n"
DISTRO=$(cat /etc/*-release | grep "^ID=" | head -1 | cut -d '=' -f 2)
if [[ "$DISTRO" == "\"opensuse\"" ]] || [[ "$DISTRO" == "\"opensuse-leap\"" ]] || [[ "$DISTRO" == "\"suse\"" ]]; then
DISTRO="opensuse-leap"
fi
if [[ "$DISTRO" == "debian" ]] || [[ "$DISTRO" == "ubuntu" ]] || [[ "$DISTRO" == "pop" ]] || [[ "$DISTRO" == "linuxmint" ]]; then
PKGMGR="apt"
IFLAG="install"
elif [[ "$DISTRO" == "fedora" ]] || [[ "$DISTRO" == "rocky" ]] || [[ "$DISTRO" == "almalinux" ]] || [[ "$DISTRO" == "centos" ]] || [[ "$DISTRO" == "RedHatEnterpriseServer" ]] || [[ "$DISTRO" == "ol" ]] || [[ "$DISTRO" == "clear-linux-os" ]] || [[ "$DISTRO" == "AmazonAMI" ]]; then
PKGMGR="dnf"
IFLAG="install"
elif [[ "$DISTRO" == "arch" ]] || [[ "$DISTRO" == "garuda" ]] || [[ "$DISTRO" == "manjaro" ]] || [[ "$DISTRO" == "Endeavour" ]]; then
PKGMGR="pacman"
IFLAG="-S"
elif [[ "$DISTRO" == "opensuse" ]] || [[ "$DISTRO" == "opensuse-leap" ]] || [[ "$DISTRO" == "suse" ]]; then
PKGMGR="zypper"
IFLAG="install"
fi
echo -e "\n🛸️ Distro: $DISTRO"
echo -e "📦️ Native: $PKGMGR\n"
if [[ "$DISTRO" == "debian" ]] || [[ "$DISTRO" == "ubuntu" ]] || [[ "$DISTRO" == "pop" ]]; then
read -p "❔️ Add longsleep-ubuntu-golang-backports? (Y/n) " BACKPORTS
if [[ "$BACKPORTS" != "N" ]] && [[ "$BACKPORTS" != "n" ]]; then
# sudo echo -e "deb https://ppa.launchpadcontent.net/longsleep/golang-backports/ubuntu/ jammy main\n# deb-src https://ppa.launchpadcontent.net/longsleep/golang-backports/ubuntu/ jammy main" |sudo tee /etc/apt/sources.list.d/longsleep-ubuntu-golang-backports-jammy.list
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6BC817356A3D45E
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update -y
fi
fi
if [[ $DISTRO == "nixos" ]]; then
GCHECK="$(whereis go)"
GL=${#GCHECK}
if [[ $GL -lt 3 ]]; then
echo -e "\n❌️ Golang is not installed on this system. Install it and run the install command again...\n"
exit 1
fi
else
read -p "❔️ Install Go? Only say no if you already have it installed... (Y/n) " GOLANG
if [[ "$GOLANG" != "N" ]] && [[ "$GOLANG" != "n" ]]; then
if [[ "$DISTRO" == "fedora" ]] || [[ "$DISTRO" == "rocky" ]] || [[ "$DISTRO" == "almalinux" ]] || [[ "$DISTRO" == "centos" ]] || [[ "$DISTRO" == "RedHatEnterpriseServer" ]] || [[ "$DISTRO" == "ol" ]] || [[ "$DISTRO" == "clear-linux-os" ]] || [[ "$DISTRO" == "AmazonAMI" ]]; then
wget -O /tmp/go1.22.4.linux-amd64.tar.gz https://go.dev/dl/go1.22.4.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf /tmp/go1.22.4.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo -e "if [[ -d /usr/local/go/bin ]]; then\n\tPATH=$PATH:/usr/local/go/bin\nfi" >> $HOME/.bashrc
elif [[ "$DISTRO" == "opensuse" ]] || [[ "$DISTRO" == "opensuse-leap" ]] || [[ "$DISTRO" == "suse" ]]; then
sudo $PKGMGR $IFLAG go1.22
else
sudo $PKGMGR $IFLAG golang
fi
fi
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "\nOS: macos\n"
PKGMGR="brew"
read -p "❔️ Install Homebrew? (Y/n) " HOMEBREW
if [[ "$HOMEBREW" != "N" ]] && [[ "$HOMEBREW" != "n" ]]; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
read -p "❔️ Install Go? Only say no if you already have it installed (Y/n) " GOLANG
if [[ "$GOLANG" != "N" ]] && [[ "$GOLANG" != "n" ]]; then
echo -e "Installing Go...\n"
brew install golang
fi
elif [[ "$OSTYPE" == "freebsd"* ]]; then
read -p "❔️ Install Go? Only say no if you already have it installed (Y/n) " GOLANG
if [[ "$GOLANG" != "N" ]] && [[ "$GOLANG" != "n" ]]; then
echo -e "Installing Go...\n"
sudo pkg install golang
fi
fi
echo -e "\n🛰️ Getting modules...\n"
go mod tidy
echo -e "🛠️ Compiling app...\n"
go build
echo -e "💾️ Copying app to $HOME/.local/bin...\n"
cp app $HOME/.local/bin/
echo -e "\n${GREEN}**************"
echo -e " 💯️ COMPLETED"
echo -e "**************${NC}\n"
echo -e "⚠️ You may need to close and reopen your existing terminal windows for app to work as expected...\n"