-
Notifications
You must be signed in to change notification settings - Fork 1
/
clone_Slackware_multilib_rsync_JBs.sh
executable file
·240 lines (199 loc) · 9.53 KB
/
clone_Slackware_multilib_rsync_JBs.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
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
#!/bin/bash
#
# Autor= João Batista Ribeiro
# Bugs, Agradecimentos, Criticas "construtivas"
# me envie um e-mail. Ficarei Grato!
# e-mail: [email protected]
#
# Este programa é um software livre; você pode redistribui-lo e/ou
# modifica-lo dentro dos termos da Licença Pública Geral GNU como
# publicada pela Fundação do Software Livre (FSF); na versão 2 da
# Licença, ou (na sua opinião) qualquer versão.
#
# Este programa é distribuído na esperança que possa ser útil,
# mas SEM NENHUMA GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a
# qualquer MERCADO ou APLICAÇÃO EM PARTICULAR.
#
# Veja a Licença Pública Geral GNU para mais detalhes.
# Você deve ter recebido uma cópia da Licença Pública Geral GNU
# junto com este programa, se não, escreva para a Fundação do Software
#
# Livre(FSF) Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Script: Clone some Slackware repository to a local source using rsync
#
# Last update: 29/06/2023
#
# Tip: Use this script with a "old" local mirror (or ISO) to download less files
#
# To run the script without any question, run as:
# echo | ./clone_Slackware_multilib_rsync_JBs.sh
#
input1=$1
if [ "$input1" == "noColor" ]; then
echo -e "\nColors disabled"
else
# Some colors for script output - Make it easier to follow
BLACK='\e[1;30m'
RED='\e[1;31m'
GREEN='\e[1;32m'
NC='\033[0m' # reset/no color
BLUE='\e[1;34m'
PINK='\e[1;35m'
CYAN='\e[1;36m'
WHITE='\e[1;37m'
fi
if [ "$input1" == "testColor" ]; then
echo -e "\n\tTest colors: $RED RED $WHITE WHITE $PINK PINK $BLACK BLACK $BLUE BLUE $GREEN GREEN $CYAN CYAN $NC NC\n"
fi
mirrorSource="rsync://rsync.slackware.org.uk/people/alien/multilib"
echo -e "$CYAN\nDefault mirror:$GREEN $mirrorSource$NC"
echo -en "$CYAN\nWant change the mirror?$NC\n(y)es - (n)o $GREEN(press enter to no):$NC "
read -r changeMirror
if [ "$changeMirror" == 'y' ]; then
mirrorSource=''
while echo "$mirrorSource" | grep -v -q "rsync"; do
echo -en "$CYAN\nType the new mirror:$NC "
read -r mirrorSource
if echo "$mirrorSource" | grep -v -q "rsync"; then
echo -e "$RED\nError: the mirror \"$mirrorSource\" is not valid.\nOne valid mirror has \"ftp\" or \"http\"$NC"
fi
done
echo -e "$CYAN\nNew mirror:$GREEN $mirrorSource$NC"
fi
if find . -maxdepth 1 -type d | grep -q "current"; then
defaultSuggest="current"
else
defaultSuggest="15.0"
fi
echo -en "\n$CYAN# Most downloaded versions:$GREEN 14.2, 15.0, current$CYAN\nWith version Slackware you want? $GREEN(press enter to $defaultSuggest):$NC "
read -r versionDownload
if [ "$versionDownload" == '' ]; then
versionDownload=$defaultSuggest
fi
echo -e "$CYAN\nWill download (by rsync) $GREEN\"$versionDownload\"$CYAN from $GREEN\"$mirrorSource\"$NC"
echo -en "$CYAN\nWant continue?$NC\n(y)es - (n)o $GREEN(press enter to yes):$NC "
read -r contineLftp
if [ "$contineLftp" == 'n' ]; then
echo -e "$CYAN\nJust exiting by user choice$NC\n"
else
if [ -e $versionDownload/ ]; then
echo -e "$CYAN\nOlder folder download found ($GREEN$versionDownload/$CYAN)$NC"
echo -en "$CYAN\nDownloading$BLUE ChangeLog.txt$CYAN to make a$BLUE fast check$CYAN (the$BLUE local$GREEN "
echo -en "ChangeLog.txt$CYAN with the$BLUE server$GREEN ChangeLog.txt$CYAN).$NC Please wait..."
rsync -aqz "$mirrorSource/ChangeLog.txt" ./ChangeLog.txt.new
changeLogLocalMd5sum=$(md5sum ChangeLog.txt)
checkChangeLogMd5sum=$(echo -e "$changeLogLocalMd5sum.new" | md5sum -c 2> /dev/null)
changeLogMd5sumResult=$(echo -e "$checkChangeLogMd5sum" | awk '{print $2}')
echo -en "$CYAN\nThe$BLUE ChangeLog.txt$CYAN in the server is"
contineOrJump='y'
if [ "$changeLogMd5sumResult" == "OK" ]; then
rm ChangeLog.txt.new
echo -e "$GREEN equal$CYAN with the$BLUE ChangeLog.txt$CYAN in local folder$NC"
echo -en "$CYAN\nWant continue/force the download or jump the download step?$NC\n(y)es to continue - (n)o to jump $GREEN(press enter to no):$NC "
read -r contineOrJump
else # $changeLogMd5sumResult == FAILED
echo -e "$RED different$CYAN from the$BLUE ChangeLog.txt$CYAN in local folder$NC"
echo -en "$CYAN\nWant view the diff between these files?$NC\n(y)es - (n)o $GREEN(press enter to yes):$NC "
read -r diffChangLog
if [ "$diffChangLog" != 'n' ]; then
echo
diff -u ChangeLog.txt ChangeLog.txt.new
fi
mv ChangeLog.txt.new ChangeLog.txt
fi
if [ "$contineOrJump" == 'y' ]; then
echo -en "$CYAN\nCreate a md5sum for all local files (${RED}can take a while$CYAN)? $NC\n(y)es or (n)o $GREEN(press enter no):$NC "
read -r useMd5sumCheckBeforeDownload
if [ "$useMd5sumCheckBeforeDownload" == 'y' ]; then
tmpMd5sumBeforeDownload=$(mktemp)
listOfFilesBeforeDownload=$(find $versionDownload/ -type f -print)
echo -en "$CYAN\nCreating a$BLUE md5sum$RED (before the download)$CYAN from files found (in the folder $GREEN$versionDownload/$CYAN).$NC Please wait..."
for file in $listOfFilesBeforeDownload; do
md5sum "$file" >> "$tmpMd5sumBeforeDownload"
done
echo -e "$CYAN\n\nThe$BLUE md5sum$RED (before the download)$CYAN was saved in the tmp file: $GREEN$tmpMd5sumBeforeDownload$NC"
else
tmpMd5sumBeforeDownload=''
fi
fi
else
contineOrJump='y'
fi
if [ "$contineOrJump" == 'y' ]; then
rsyncCommand="rsync -ahv --delete --progress $mirrorSource/$versionDownload ./"
# -a archive mode, equivalent to -rlptgoD - recursion and want to preserve almost everything
# -h output numbers in a human-readable format; -v increase verbosity
# --delete delete extraneous files from destination directories
# --progress print information showing the progress of the transfer
echo -en "$CYAN\nDownloading files.$NC Please wait...\n\n"
echo "$rsyncCommand"
eval "$rsyncCommand"
fi
if [ "$tmpMd5sumBeforeDownload" != '' ]; then
tmpMd5sumAfterDownload=$(mktemp)
listOfFilesAfterDownload=$(find $versionDownload/ -type f -print)
echo -en "$CYAN\nCreating a$BLUE md5sum$RED (after the download)$CYAN from files (in the folder $GREEN$versionDownload/$CYAN).$NC Please wait..."
for file in $listOfFilesAfterDownload; do
md5sum "$file" >> "$tmpMd5sumAfterDownload"
done
echo -e "$CYAN\n\nThe$BLUE md5sum$RED (after the download)$CYAN was saved in the tmp file: $GREEN$tmpMd5sumAfterDownload$NC"
echo -en "$CYAN\nChecking the changes in the files$BLUE before$CYAN with$BLUE after$CYAN download.$NC Please wait..."
changeResult=$(diff -w "$tmpMd5sumBeforeDownload" "$tmpMd5sumAfterDownload")
if [ "$changeResult" == '' ]; then
echo -e "$CYAN\nNone changes made in the local folder -$GREEN All files still the same after the download$NC\n"
else
echo -e "$RED\n\nChanges made in local files...$NC"
diffBeforeDownload=$(diff -u "$tmpMd5sumBeforeDownload" "$tmpMd5sumAfterDownload" | grep -v "^--" | grep "^-" | awk '{print $2}')
diffAfterDownload=$(diff -u "$tmpMd5sumBeforeDownload" "$tmpMd5sumAfterDownload" | grep -v "^++" | grep "^+" | awk '{print $2}')
for lineA in $diffBeforeDownload; do
for lineB in $diffAfterDownload; do
if [ "$lineA" == "$lineB" ]; then
filesUpdate+=$lineA\|
fi
done
done
if [ "$filesUpdate" != '' ]; then
echo -e "$GREEN\nFile(s) updated:$NC"
echo "$filesUpdate" | sed 's/|/\n/g' | sort
fi
for lineA in $diffBeforeDownload; do
diffLineDeleted=$(echo "$diffAfterDownload" | grep "$lineA")
if [ "$diffLineDeleted" == '' ]; then
filesDeleted+=$lineA\|
fi
done
if [ "$filesDeleted" != '' ]; then
echo -e "$RED\nFile(s) deleted:$NC"
echo "$filesDeleted" | sed 's/|/\n/g' | sort
fi
for lineB in $diffAfterDownload; do
diffLineNewFiles=$(echo "$diffBeforeDownload" | grep "$lineB")
if [ "$diffLineNewFiles" == '' ]; then
filesNew+=$lineB\|
fi
done
if [ "$filesNew" != '' ]; then
echo -e "$BLUE\nNew file(s) downloaded:$NC"
echo "$filesNew" | sed 's/|/\n/g' | sort
fi
fi
rm "$tmpMd5sumBeforeDownload" "$tmpMd5sumAfterDownload"
fi
cd "$versionDownload" || exit
echo -en "$CYAN\nWant check the integrity of downloaded files with the server?$NC\n(y)es - (n)o $GREEN(press enter to yes):$NC "
read -r checkFiles
if [ "$checkFiles" == 'y' ] || [ "$checkFiles" == '' ]; then
echo -en "$CYAN\nChecking the integrity of the files.$NC Please wait..."
checkFilesResult=$(tail +13 CHECKSUMS.md5 | md5sum -c --quiet)
echo -en "$CYAN\n\nFiles integrity:"
if [ "$checkFilesResult" == '' ]; then
echo -e "$GREEN Good $BLUE- Files are equal to the server$NC\n"
else
echo -e "$RED Bad $BLUE- Files are different to the server$NC"
echo -e "$RED$checkFilesResult$NC\n"
fi
else
echo -e "\nExiting...\n"
fi
fi