-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddtheme.sh
More file actions
executable file
·225 lines (192 loc) · 6.15 KB
/
addtheme.sh
File metadata and controls
executable file
·225 lines (192 loc) · 6.15 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
#!/bin/bash
#Global variables
PATH_NAME=$()
FOLDER_NAME=$()
FOLDER_PREFIX=$()
FOLDER_SUFFIX=$()
PASTE_NUM=$()
ISZIP=$()
filename=$()
#Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
NC='\033[0m' # No Color
#starting function
initFunction() {
if [[ ${UID} -eq 0 ]]; then
printf "${ORANGE}Make sure you are running the script from where the folders are located ${NC}\n"
else
printf "${RED}ERROR ! start this script as root ${NC}\n"
printf "${RED}exiting now...${NC}\n"
exit 1
fi
}
#reading and saving the file you wanna copy
readFoldersFunction() {
dirs=(*/)
echo ""
printf "Select a folder you wanna copy: \n"
echo ""
select FOLDER_NAME in *.tar.xz *.tar.gz; do
test -n "$FOLDER_NAME" && break
printf "${RED}>>> Invalid Selection${NC}"
done
}
# printing the full path
getFolderPathFunction() {
# PATH_NAME=$(cd "$FOLDER_NAME" && pwd)
echo ""
printf "You selected ${FOLDER_NAME} \n"
filename=$(basename $FOLDER_NAME)
FOLDER_SUFFIX=${filename##*.}
echo ""
}
extractFolderFunction() {
#checking if its a tar file or normal so to extract
if [ "${FOLDER_SUFFIX}" == 'xz' ] || [ "${FOLDER_SUFFIX}" == 'gz' ]; then
read -p "Enter 1 if this is a => theme || Enter 2 if this is a => icon/cursor: " INPUTNUM
if [[ ${INPUTNUM} -eq 1 ]]; then
printf "unziping the file ... $FOLDER_NAME \n"
echo ""
tar -xf ${FOLDER_NAME} -C /usr/share/themes
if [[ ${?} -ne 0 ]]; then
printf "${RED}report errors at https://github.com/yashkathe/script-for-adding-themes-and-icons ${NC}"
echo ""
exit 1
else
printf "${GREEN}Successfully placed the folders${NC}\n"
fi
fi
if [[ ${INPUTNUM} -eq 2 ]]; then
printf "unziping the file ... $FOLDER_NAME \n"
echo ""
tar -xf ${FOLDER_NAME} -C /usr/share/icons
if [[ ${?} -ne 0 ]]; then
printf "${RED}report errors at https://github.com/yashkathe/script-for-adding-themes-and-icons ${NC}"
echo ""
exit 1
else
printf "${GREEN}Successfully placed the folders${NC}\n"
fi
fi
else
printf "${RED}Something Went Wrong${NC}"
fi
}
deleteFolderFunction() {
read -p "Delete the tar.xz folder now ? (Y/n): " DELETE_FOLDER
echo ""
if [[ ${DELETE_FOLDER} == "Y" ]] || [[ ${DELETE_FOLDER} == "y" ]] || [[ ${DELETE_FOLDER} == " " ]] || [[ ${DELETE_FOLDER} == "" ]]; then
rm -rf ${FOLDER_NAME}
printf "deleting ...\n"
printf "${GREEN}Deleted folder successfully ${NC}\n"
printf "${GREEN}All Operations Completed Successfully. ${NC}\n"
printf "${GREEN}exiting now. ${NC}\n"
elif [[ ${DELETE_FOLDER} == "N" ]] || [[ ${DELETE_FOLDER} == "n" ]]; then
printf "${RED}Not deleting the folder ${NC}\n"
printf "${GREEN}Operations Completed Successfully. ${NC}\n"
printf "${GREEN}exiting now. ${NC}\n"
else
printf "${RED}Not a valid option ${NC}\n"
printf "${RED}Ignoring deleteFolderFunc ... not deleting folder ${NC}\n"
fi
}
helpFunction() {
echo ""
echo "Flags:"
echo "1. --start -> install themes and icons package after installing the "
echo "2. --delete -> to delete themes and icons which are already installed in system"
echo ""
echo "Source Code: https://github.com/yashkathe/script-for-adding-themes-and-icons"
echo ""
}
#code for deleting themes and icons folder
deleteTheme() {
THEMES=$(ls /usr/share/themes)
select FOLDER_NAME in $THEMES; do
read -p "Do you surely want to delete ? $FOLDER_NAME (y/n): " FOLDER2DELETE
if [[ $FOLDER2DELETE == "y" || $FOLDER2DELETE == "Y" || $FOLDER2DELETE == "" ]]; then
sudo rm -rf /usr/share/themes/$FOLDER_NAME
if [[ ${?} -ne 0 ]]; then
printf "${RED}SOMETHING WENT WRONG ${NC}"
printf "${RED}report errors at https://github.com/yashkathe/script-for-adding-themes-and-icons ${NC}"
echo ""
exit 1
else
printf "${GREEN}SUCCESSFULLY DELETED $FOLDER_NAME ${NC}"
echo ""
break
fi
elif [[ $FOLDER2DELETE == "n" || $FOLDER2DELETE == "N" ]]; then
echo "NOT DELETING .."
echo ""
break
else
printf "${RED} INVALID COMMAND ${NC}"
echo ""
break
fi
break
done
}
deleteIcons() {
ICONS=$(ls /usr/share/icons)
select FOLDER_NAME in $ICONS; do
read -p "Do you surely want to delete ? $FOLDER_NAME (y/n): " FOLDER2DELETE
if [[ $FOLDER2DELETE == "y" || $FOLDER2DELETE == "Y" || $FOLDER2DELETE == "" ]]; then
sudo rm -rf /usr/share/icons/$FOLDER_NAME
if [[ ${?} -ne 0 ]]; then
printf "${RED}SOMETHING WENT WRONG ${NC}"
printf "${RED}report errors at https://github.com/yashkathe/script-for-adding-themes-and-icons ${NC}"
echo ""
exit 1
else
printf "${GREEN} DELETED SUCCESSFULLY $FOLDER_NAME ${NC}"
echo ""
break
fi
elif [[ $FOLDER2DELETE == "n" || $FOLDER2DELETE == "N" ]]; then
echo "NOT DELETING .."
echo ""
break
else
printf "${RED} INVALID COMMAND ${NC}"
echo ""
break
fi
break
done
}
mainDeleteFunction() {
read -p "Delete Themes or Icons folder || 1=>themes 2=>icons: " SELECTOPT
if [[ $SELECTOPT -eq 1 ]]; then
deleteTheme
elif [[ $SELECTOPT -eq 2 ]]; then
deleteIcons
else
printf "${RED}INVALID COMMAND ${NC}"
fi
}
error(){
printf "${RED}Invalid Argument${NC}"
exit 1
}
case "${1}" in
--start)
initFunction
readFoldersFunction
getFolderPathFunction
extractFolderFunction
deleteFolderFunction
;;
--help)
helpFunction
;;
--delete)
mainDeleteFunction
;;
*)
error
;;
esac