-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapplication.sh
executable file
·134 lines (127 loc) · 4.06 KB
/
application.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
#!/usr/bin/env bash
#> +------------------+
#> | application.sh |
#> +------------------+
#-
#- SYNOPSIS
#-
#- ./application.sh [-h]
#-
#- OPTIONS
#-
#- -y, all accept.
#- -h, --help print help information.
#-
#- EXAMPLES
#-
#- $ ./application.sh -y
#====================================================
# Part 1. Option Tool
#====================================================
# Print script help
function show_script_help(){
echo
head -17 $0 | # find this file top 16 lines.
grep "^#[-|>]" | # show the line that include "#-" or "#>".
sed -e "s/^#[-|>]*//1" # use nothing to replace "#-" or "#>" that the first keyword in every line.
echo
}
# Receive arguments in slient mode.
all_accept=0
if [ "$#" -gt 0 ]; then
while [ "$#" -gt 0 ]; do
case "$1" in
# Help
"-h"|"--help")
show_script_help
exit 1
;;
# All Accept
"-y")
all_accept=1
shift 1
;;
esac
done
fi
function Echo_Color(){
case $1 in
r* | R* )
COLOR='\033[0;31m'
;;
g* | G* )
COLOR='\033[0;32m'
;;
y* | Y* )
COLOR='\033[0;33m'
;;
b* | B* )
COLOR='\033[0;34m'
;;
*)
echo "$COLOR Wrong COLOR keyword!\033[0m"
;;
esac
echo -e "$COLOR$2\033[0m"
}
function Ask_yn(){
printf "\033[0;33m$1\033[0m\033[0;33m [y/n] \033[0m"
if [ $all_accept = 1 ]; then
echo '-y'
return 1
fi
read respond
if [ "$respond" = "y" -o "$respond" = "Y" -o "$respond" = "" ]; then
return 1
elif [ "$respond" = "n" -o "$respond" = "N" ]; then
return 0
else
Echo_Color r 'wrong command!!'
Ask_yn $1
return $?
fi
unset respond
}
#====================================================
# Part 2. Main
#====================================================
sudo apt-get update
sudo apt-get upgrade
declare -A Application_dict
Application_dict=([code]="VScode" [google-chrome]="Chrome" [vlc]="vlc" [gimp]="GIMP" [kolourpaint]="kolourpaint4" [obs]="obs-studio" )
for key in ${!Application_dict[*]}; do
app_root="$(command -v $key)" # get application root
if [ "$app_root" = "" ]; then
Ask_yn "Do you want to install ${Application_dict[$key]}?"; result=$? # get Ask_yn() return {Application_dict[$key]}
if [ $result = 1 ]; then
case ${Application_dict[$key]} in
"VScode" ) # install VScode
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -o root -g root -m 644 packages.microsoft.gpg /etc/apt/trusted.gpg.d/
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/trusted.gpg.d/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg
sudo apt install apt-transport-https -y
sudo apt update
sudo apt install code -y
;;
"Chrome" ) # install Chrome
wget -c https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i ./google-chrome-stable_current_amd64.deb
sudo apt-get install -f
rm ./google-chrome-stable_current_amd64.deb
;;
"GIMP" ) # install GIMP
sudo add-apt-repository ppa:ubuntuhandbook1/gimp
sudo apt-get update
sudo apt-get install gimp
;;
* )
sudo apt-get install ${Application_dict[$key]}
;;
esac
fi
else
Echo_Color g "You are already installed ${Application_dict[$key]} before~"
fi
done
Echo_Color g "Done!! $0"