-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglide.sh
executable file
·199 lines (162 loc) · 4 KB
/
glide.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
#!/usr/bin/env bash
# Copyright (C) 2023-present StellarSand
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
source /usr/local/lib/GLIDE/common_utils.sh
hasCommand() {
if ! (command -v "$1" > /dev/null)
then
echo -e "\n$1 package does not exist. Please install it first and try again."
echo -e "Exiting script ...\n"
exit 1
fi
}
# Show usage
usage() {
cat << EOF
Usage:
glide <distro name>
glide <distro name> -d <directory>
Description:
Download the latest ISO images for various GNU/Linux distributions directly from the terminal.
Available options:
-h, --help Show this help message
-l, --list Show available distro list
-D, --default-dir Change default download directory
-d, --directory Change directory for current download only
Examples:
glide ubuntu
glide ubuntu -d /home/user/Desktop
EOF
}
# Show list of available distros
listDistros() {
cat << EOF
Available distros:
arch
centosstream
debian
endeavouros
fedora
kali
linuxmint
manjaro
ubuntu
EOF
}
hasCommand "curl"
hasCommand "gpg"
distro=""
def_dnld_dir=$(xdg-user-dir DOWNLOAD)
config_dir="$HOME/.config/GLIDE"
config_file="$config_dir/dnld_dir"
distro_scripts_dir="/usr/local/lib/GLIDE/distros"
# Check config directory
if [ ! -d "$config_dir" ]
then
mkdir "$config_dir"
fi
# Check config file
if [ ! -f "$config_file" ]
then
echo "$def_dnld_dir" > "$config_file"
echo "Default download directory is set to $def_dnld_dir"
fi
# Check download directory
if [ ! -d "$def_dnld_dir" ]
then
echo -e "\nSet a default directory to download files."
echo "Try 'glide -h' for more information."
echo -e "Exiting script ...\n"
exit 1
fi
# If no options are provided, print usage
if [ $# -eq 0 ]
then
usage
exit 0
fi
# Process options
while [ $# -gt 0 ]
do
case "$1" in
-h | --help)
usage
exit 0
;;
-l | --list)
listDistros
exit 0
;;
-D | --default-dir)
if [ $# -gt 1 ]
then
if [ ! -d "$2" ]
then
echo -e "\n$2 does not exist."
echo -e "Exiting script ...\n"
exit 1
else
echo "$2" > "$config_file"
successFail
echo -e "All files will be downloaded in $2\n"
shift
fi
else
echo -e "\nThe -D or --default-dir option must be followed by a directory path."
echo -e "Try 'glide -h' for more information.\n"
exit 1
fi
;;
-d | --directory)
if [ $# -gt 1 ]
then
if [ ! -d "$2" ]
then
echo -e "\n$2 does not exist."
echo -e "Exiting script ...\n"
exit 1
else
echo "$2" > /tmp/curr_dnld_dir
shift
fi
else
echo -e "\nThe -d or --directory option must be followed by a directory path."
echo -e "Try 'glide -h' for more information.\n"
exit 1
fi
;;
-*)
echo -e "\nInvalid option: $1"
echo -e "Try 'glide -h' for more information.\n"
exit 1
;;
*)
distro=$1
;;
esac
shift
done
# Perform actual downloads
# Keep scripts separate for easier & better maintenance
if [ -n "$distro" ] # Only run this if script has "-n" input
then
if [ -f $distro_scripts_dir/"$distro".sh ]
then
execPerm $distro_scripts_dir/"$distro".sh
$distro_scripts_dir/"$distro".sh
else
echo -e "\nInvalid distro name."
echo -e "Try 'glide -l' to see the list of available distros.\n"
exit 1
fi
fi
exit 0