-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_repo
executable file
·249 lines (221 loc) · 7.19 KB
/
update_repo
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
#!/bin/sh
#
# SlackPack
# Copyright (C) 2006-2023 Georgi D. Sotirov, [email protected]
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# DESCRIPTION:
# Script to update/create the service files for a Slackware packages repository
#
# The script is based on the example found on
# https://software.jaos.org/git/slapt-get/plain/FAQ
# See 17. How do I create my own package source?
#
TMPDIR=/tmp/slackpack
TOTAL_SIZE=0
TOTAL_USIZE=0
# These are the current possible package extensions
PKG_EXTS="tbz|tgz|tlz|txz"
# Wildcard for the current possible package extensions
PKG_EXTS_WCARD="*.t[bglx]z"
PKG_REGEX="^([\_\.\-\+\d\w]+)\-(\d[\d\w\.]+)\-([\w\d_]+)\-(\d)(\w*)\.($PKG_EXTS)$"
function gen_checksums_md5 {
echo "These are the MD5 message digests for the files in this directory." > $1
echo "" >> $1
echo "md5sum \`tree -fi --noreport\`" >> $1
echo "" >> $1
echo "If you want to test your files, use 'md5sum' and compare the values to" >> $1
echo "the ones listed here." >> $1
echo "" >> $1
echo "To test all these files, use this command:" >> $1
echo "" >> $1
echo "md5sum -c CHECKSUMS.md5 | less" >> $1
echo "" >> $1
echo "'md5sum' can be found in the GNU coreutils package on ftp.gnu.org in" >> $1
echo "/pub/gnu, or at any GNU mirror site." >> $1
echo "" >> $1
echo "MD5 message digest Filename" >> $1
md5sum `tree -fi --noreport` 2>/dev/null >> $1
}
function gen_filelist_txt {
date > $1
echo "" >> $1
echo "Here is the file list for this directory. Please, keep in mind that mirrors" >> $1
echo "are not updated instantly, but if you find a mirror that is inconsistent" >> $1
echo "for more than 24 hours write to the site maintainer or mirror administrator." >> $1
echo "" >> $1
echo "ls -lad \`tree -fi --noreport\`" >> $1
ls -lad `tree -fi --noreport` >> $1
}
function gen_meta {
PKG=$1
CWDNM=$2
OUTFILE=$3
HAS_META=0
# Check for the meta file in the temp directory
if [ -e $OUTFILE ]; then
if [ -s $OUTFILE ]; then
HAS_META=1
else
echo "warning: File '$OUTFILE' is empty. Will regenerate it."
fi
else
echo "info: Generating metadata for package '$PKG'."
fi
NAME=$(echo $PKG | sed -re "s/(.*\/)(.*)$/\2/")
if [ "x`echo $NAME | grep -P $PKG_REGEX`" == "x" ]; then
echo "warning: Package name '$NAME' could not be parsed!"
return;
fi
PKGEXT=$(echo $NAME | sed 's/.*\.//');
case $PKGEXT in
'txz' )
PKGCOMPR="xz"
;;
'tgz' )
PKGCOMPR="gzip"
;;
'tbz' )
PKGCOMPR="bzip2"
;;
'tlz' )
PKGCOMPR="lzma"
;;
esac
LOCATION=$(echo $PKG | sed -re "s/(.*)\/(.*.$PKGEXT)$/\1/")
SIZE=`stat --printf="%s" $PKG`
case $PKGEXT in
'txz' )
USIZE=`LANG=C $PKGCOMPR -lv $PKG | grep 'Uncompressed size' | awk -F'[(),]' '{ print $2 "" $3 "" $4 }' | awk '{ print $1 }'`
;;
'tgz' )
USIZE=`LANG=C $PKGCOMPR -l $PKG | grep -v 'uncompressed' | awk '{ print $2 }'`
;;
* )
# This could be very slow on large packages!!!
USIZE=`$PKGCOMPR -dc $PKG | wc -c`
;;
esac
((TOTAL_SIZE += SIZE))
((TOTAL_USIZE += USIZE))
if [ $HAS_META -eq 1 ]; then
return;
fi
# Calculate sizes in KB
((SIZE=SIZE/1024))
((USIZE=USIZE/1024))
# TODO: one shot extraction with --wildcards 'install/*
REQUIRED=$( tar xfO $PKG install/slack-required 2>/dev/null | xargs -r -iZ echo -n "Z," | sed -e "s/,$//")
CONFLICTS=$(tar xfO $PKG install/slack-conflicts 2>/dev/null | xargs -r -iZ echo -n "Z," | sed -e "s/,$//")
SUGGESTS=$( tar xfO $PKG install/slack-suggests 2>/dev/null | xargs -r -iZ echo -n "Z," | sed -e "s/,$//")
echo "PACKAGE NAME: $NAME" > $OUTFILE
echo "PACKAGE LOCATION: $LOCATION" >> $OUTFILE
echo "PACKAGE SIZE (compressed): $SIZE K" >> $OUTFILE
echo "PACKAGE SIZE (uncompressed): $USIZE K" >> $OUTFILE
echo "PACKAGE REQUIRED: $REQUIRED" >> $OUTFILE
echo "PACKAGE CONFLICTS: $CONFLICTS" >> $OUTFILE
echo "PACKAGE SUGGESTS: $SUGGESTS" >> $OUTFILE
echo "PACKAGE DESCRIPTION:" >> $OUTFILE
DESC_FILE=$(echo $PKG | sed -e "s/$PKGEXT/txt/")
if [ -e $DESC_FILE ]; then
cat $DESC_FILE >> $OUTFILE
else
# This could be very slow on large packages !!!
tar xfO $PKG install/slack-desc | grep -E '\w+\:' | grep -v '^#' >> $OUTFILE
fi
echo "" >> $OUTFILE
}
function gen_packages_txt {
# If the temp directory doesn't exists - create it
if [ ! -e $TMPDIR ]; then
mkdir $TMPDIR
fi
CWD=`pwd`
CWDNM=`basename $CWD`
if [ ! -e $TMPDIR/$CWDNM ]; then
mkdir $TMPDIR/$CWDNM
fi
for pkg in `find . -type f -name "$PKG_EXTS_WCARD" -print -maxdepth 1 | sort`; do
gen_meta $pkg $CWDNM $TMPDIR/$CWDNM/$pkg.meta
cat $TMPDIR/$CWDNM/$pkg.meta >> PACKAGES.TXT.TMP
done
# Calculate sizes in MB
((TOTAL_SIZE =TOTAL_SIZE/1024/1024))
((TOTAL_USIZE=TOTAL_USIZE/1024/1024))
echo "PACKAGES.TXT; `date`" > $1
echo "" >> $1
echo "This file provides details on the Slackware packages found" >> $1
echo "in the current directory." >> $1
echo "" >> $1
echo "Total size of all packages (compressed): $TOTAL_SIZE MB" >> $1
echo "Total size of all packages (uncompressed): $TOTAL_USIZE MB" >> $1
echo "" >> $1
cat PACKAGES.TXT.TMP >> $1
rm -f PACKAGES.TXT.TMP
}
function prepare_repo {
# cleanup unnecessary files
# - all logs
find . -type f -name '*.log*' -delete
# - all temporary files created by editors
find . -type f -name '*~' -delete
# - all hidden files (presumably created by CVS)
find . -type f -name '.*' -delete
# - all CVS service files and dirs
# - all SVN service files and dirs
# - all Git service files and dirs
for dir in `find . -type d \( -name 'CVS' -o -name '.svn' -o -name '.git' \)`;
do
rm --recursive $dir
done
# fix file and directory permissions and ownership
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chown root:root * --recursive
}
# Execute actions to update repository service data
case "$1" in
"packages")
echo -n "Generating PACKAGES.TXT... "
gen_packages_txt PACKAGES.TXT
gzip -9 -c PACKAGES.TXT >PACKAGES.TXT.gz
echo "Done."
;;
"checksums")
echo -n "Generating CHECKSUMS.md5... "
gen_checksums_md5 CHECKSUMS.md5
gzip -9 -c CHECKSUMS.md5 >CHECKSUMS.md5.gz
echo "Done."
;;
"filelist")
echo -n "Generating FILELIST.TXT... "
gen_filelist_txt FILELIST.TXT
gzip -9 -c FILELIST.TXT >FILELIST.TXT.gz
echo "Done."
;;
"prepare")
echo "Preparing repository: "
prepare_repo
echo "Done."
;;
*)
$0 prepare
$0 packages
$0 checksums
$0 filelist
echo "All done."
;;
esac