-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·260 lines (234 loc) · 7.56 KB
/
setup.sh
File metadata and controls
executable file
·260 lines (234 loc) · 7.56 KB
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
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env bash
# by: Sheldonimo
# global variable
export log_path=$PWD/installation_log_$(date +%Y-%m-%d_%H-%M-%S).log
function main() {
#download scripts and create folder
begin
#print banner
banner
#read inputs
read_input
# $? is limited between 0 and 255, so we can use it to return the user's choice
let answer=$?
case "$answer" in
1)
# Require sudo access
sudo -v
#echo "run Install All Customizations..."
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installation All Customizations." | tee -a $log_path
ask_to_run_script "desktop_customization.sh" "false"
install_pip_and_git
ask_to_run_script "install_developer_apps.sh" "false"
ask_to_run_script "install_general_purpose_apps.sh" "false"
;;
2)
# Require sudo access
sudo -v
#echo "run Install Desktop Customization..."
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installation Desktop Customization." | tee -a $log_path
ask_to_run_script "desktop_customization.sh" "false"
install_pip_and_git
;;
3)
# Require sudo access
sudo -v
#echo "run Install Developer Apps..."
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installation Developer Apps." | tee -a $log_path
install_pip_and_git
ask_to_run_script "install_developer_apps.sh" "false"
;;
4)
# Require sudo access
sudo -v
#echo "run Install General Purpose Apps..."
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installation General Purpose Apps." | tee -a $log_path
install_pip_and_git
ask_to_run_script "install_general_purpose_apps.sh" "false"
;;
5)
# Require sudo access
sudo -v
#echo "Multi-Selection setup..."
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installation Custom Selection setup." | tee -a $log_path
install_pip_and_git
ask_to_run_script "desktop_customization.sh" "true"
ask_to_run_script "install_developer_apps.sh" "true"
ask_to_run_script "install_general_purpose_apps.sh" "true"
;;
6)
#echo "exit setup..."
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Exit setup." | tee -a $log_path
exitScript
;;
esac
}
begin() {
touch $log_path
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} running." | tee -a $log_path
}
# Function to execute the script
# Arguments: 1=script_name
run_script() {
local script_name=$1
local root=./scripts
local script_path="$root/$script_name"
wait_second 2
if [ -f "$script_path" ]; then
echo "$script_path Found..."
chmod +x "$script_path"
else
error "$script_name not Found..."
fi
# Create tmp folder
create_tmp_folder
# Validate if $script_path is equal to desktop_customization.sh
if [ "$script_name" == "desktop_customization.sh" ]; then
# Function to execute the script
iconColorBanner
#read inputs
read_input_color
let choose=$?
iconColor=$(change_iconColor $choose)
wait_second 2
# run script
bash "$script_path" "$iconColor"
else
bash "$script_path"
fi
unset script_path
}
function iconColorBanner() {
local iconColorBanner_path="$PWD/images/iconColorBanner"
if [ -f $iconColorBanner_path ];then
clear && echo ""
cat $iconColorBanner_path
echo ""
else
error "iconColorBanner not Found..."
fi
unset iconColorBanner_path
}
function read_input_color() {
while true ;do
read -p "[choose an option]$ " choose
choose=${choose:-0} # default value is 0
if [[ "$choose" =~ ^([0-9]|1[0-4])$ ]];then
break
fi
warning "choose a number between 0 to 14"
done
return $choose
}
function change_iconColor(){
local iconColor=""
case $1 in
0) iconColor="green" ;;
1) iconColor="yellow" ;;
2) iconColor="blue" ;;
3) iconColor="red" ;;
4) iconColor="purple" ;;
5) iconColor="grey" ;;
6) iconColor="dracula" ;;
7) iconColor="black" ;;
8) iconColor="brown" ;;
9) iconColor="orange" ;;
10) iconColor="pink" ;;
11) iconColor="standard" ;;
12) iconColor="manjaro" ;;
13) iconColor="ubuntu" ;;
14) iconColor="nord" ;;
*) iconColor="unknown" ;; # this should never happen
esac
echo $iconColor
unset iconColor
}
function wait_second() {
for (( i=0 ; i<$1 ; i++ ));do
echo -n "."
sleep 1
done
echo ""
}
function read_input() {
while true ;do
read -p "[choose an option]$ " choose
if [[ "$choose" =~ (^[1-6]$) ]];then
break
fi
warning "choose a number between 1 to 6"
done
return $choose
}
function exitScript() {
echo "Good Bye :)"
}
function banner() {
# print banner
# How can I make a banner?
# cat iconColorBanner.txt | lolcat -p 3 -F 0.12 -S 0 --force > iconColorBanner
local banner_path="$PWD/images/banner"
if [ -f $banner_path ];then
clear && echo ""
cat $banner_path
echo ""
else
error "banner not Found..."
fi
unset banner_path
}
# Function to prompt the user and execute a script
# Arguments: 1=script_name(script.sh), 2=ask_confirmation(true/false)
function ask_to_run_script() {
local script_name=$1
local ask_confirmation=$2
if [[ $ask_confirmation == "true" ]]; then
read -p "Do you want to execute the script $script_name? (Y/n): " choice
# Default to 'yes' if the input is empty, 'y', or 'Y'
if [[ -z $choice || $choice == "y" || $choice == "Y" ]]; then
run_script "$script_name"
else
echo "Skipping $script_name."
fi
else
run_script "$script_name"
fi
}
function install_pip_and_git() {
# Check if Python3 pip and Git are installed
pip_installed=$(command -v pip3 &> /dev/null && echo "yes" || echo "no")
git_installed=$(command -v git &> /dev/null && echo "yes" || echo "no")
if [ "$pip_installed" = "yes" ] && [ "$git_installed" = "yes" ]; then
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} pip3 and git are already installed." | tee -a $log_path
echo "Both pip3 and Git are already installed."
elif [ "$pip_installed" = "yes" ] && [ "$git_installed" = "no" ]; then
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installing git." | tee -a $log_path
sudo apt-get update
sudo apt-get install -y git
elif [ "$pip_installed" = "no" ] && [ "$git_installed" = "yes" ]; then
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installing pip3." | tee -a $log_path
sudo apt-get update
sudo apt-get install -y python3-pip
else
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Installing pip3 and git." | tee -a $log_path
sudo apt-get update
sudo apt-get install -y python3-pip git
fi
}
function create_tmp_folder() {
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Creating temporary folder." | tee -a $log_path
# check if exit the folder tmp and create it if not exist.
if [ ! -d "./tmp" ]; then
mkdir ./tmp
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} tmp folder created." | tee -a $log_path
fi
echo "$(date +%Y-%m-%d_%H:%M:%S) : ${0##*/} Temporary folder created: $tmp." | tee -a $log_path
}
function error() {
echo -e "\033[1;31merror:\e[0m $@"
exit 1
}
function warning() {
echo -e "\033[1;33mWarning:\e[0m $@"
}
main