-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectToInstall.sh
executable file
·152 lines (140 loc) · 3.26 KB
/
selectToInstall.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
#!/bin/bash
#
######################################################
# Script install all or select applications to install
######################################################
# Made by akerge
#
# TODO:
# * make POSIX compliant
# Array of applications to be installed via apt
apts=("neofetch" "glances" "vim" "curl" "git" "tree" "pwgen" "nmap" "iftop" "nethogs" "chrome-gnome-shell" "meson" "sassc" "libglib2.0-dev" "libxml2-utils" "gparted" "ncdu")
# meson to libxml2-utils are for Yaru shell appearance in tweaks on ubuntu
# https://www.linuxuprising.com/2019/10/how-to-get-dark-gnome-shell-menus-and.html
snaps=("spotify" "slack --classic")
function printElement(){
# print function for easier reading
printf "Install $1? [Y/n] "
}
function printArray(){
# passing array name as argument is from
# https://stackoverflow.com/a/26443029
local -n ref="$1"
for k in "${ref[@]}";
do
printf "\n * $k"
# echo -e " $k\n"
done
}
# global arrays
declare installApts
declare installSnaps
function loopOverApps(){
# loop over array and select application(s) to install
# add the selected application to another array (install apts/snaps)
echo "Selection from $1:"
local -n ref="$1"
for a in "${ref[@]}";
do
printElement $a
read response
case $response in
[nN])
echo " not adding $a"
;;
*)
echo " adding $a"
arrToAddTo+=("$a")
;;
esac
printf "\n"
done
if [ $1 == "apts" ]; then
installApts=( "${arrToAddTo[@]}" )
elif [ $1 == "snaps" ]; then
installSnaps=( "${arrToAddTo[@]}" )
else
echo " THIS SHOULD NOT HAPPEN"
fi
unset arrToAddTo
}
function installApps(){
# sanity check to install all or select apps
if [[ $1 == "apts" || ! -z $2 ]]; then
install="sudo apt-get -y install "
local -n ref="$1"
eval "$install ${ref[@]}"
elif [ $1 == "apts" ]; then
install="sudo apt-get -y install "
local -n ref="installApts"
eval "$install ${ref[@]}"
elif [[ $1 == "snaps" && ! -z $2 ]]; then
install="sudo snap install "
local -n ref="$1"
for l in "${ref[@]}";
do
eval "$install $l"
done
elif [ $1 == "snaps" ]; then
install="sudo snap install "
local -n ref="installSnaps"
for l in "${ref[@]}";
do
eval "$install $l"
done
else
echo " THIS SHOULD NOT HAPPEN"
fi
}
# was annoyed for repetetive lines
function printAll(){
if [ ! -z $1 ]; then
printArray "installApts"
printArray "installSnaps"
else
printArray "apts"
printArray "snaps"
fi
}
function loopAll(){
loopOverApps "apts"
loopOverApps "snaps"
}
function installAll(){
if [ ! -z $1 ]; then
echo "Installing all apps"
installApps "apts" "all"
installApps "snaps" "all"
else
echo "Installing selected apps"
installApps "apts"
installApps "snaps"
fi
}
printf "Install all apps? [Y/n]\n"
printAll
printf "\n\n[Y] to install all, [n] to select what to install. "
printf "\nCtrl+C to cancel. "
read ALL
case $ALL in
[nN])
loopAll
printf "Following have been selected to install:"
printAll "check"
printf "\nIs this correct? [Y/n] "
read YN
case $YN in
[nN])
echo -e "\nPlease re-run script to re-select applications to install or whatever."
echo " bash $0"
echo -e "Have a great day!"
;;
*)
installAll
;;
esac
;;
*)
installAll "yes"
;;
esac