-
Notifications
You must be signed in to change notification settings - Fork 0
/
multilibpkg
executable file
·171 lines (148 loc) · 4.25 KB
/
multilibpkg
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
#!/bin/bash
#
# multilibpkg
# Copyright(c) 2012 Eduardo Ramos <freedom.trinity@gmail.com>
# Copyright(c) 2012 Luiz Coura <luizcoura@gmail.com> - colaborator
# MIT Licensed
URL="http://www.slackware.com/~alien/multilib/current/"
LIB="/var/lib/multilibpkg"
CACHE="/var/cache/multilibpkg"
LOCK="/var/run/multilib.lock"
function checkuser() {
if [ "`whoami`" != "root" ] ; then
echo "You must be root."
_exit
fi
}
function invert() {
echo $1 | sed 's/./&\n/g' | tac | tr -d '\n'
}
function _exit() {
rm -rf $LOCK
exit
}
function cleanup() {
rm -rf $CACHE/*
echo "$CACHE is clean."
}
function checkupdate() {
if [ "`whoami`" != "root" ] ; then
echo "You must run as root"
_exit
fi
cd $LIB
> local
> local.db
> remote
> remote.db
> download.list
echo "[Check updates]"
echo " Downloading file list..."
curl -s http://www.slackware.com/~alien/multilib/current/PACKAGES.TXT | gawk 'match($0, /PACKAGE NAME: (.*)$/, a) { print a[1]}' > remote
curl -s http://www.slackware.com/~alien/multilib/current/PACKAGES.TXT | gawk 'match($0, /PACKAGE LOCATION: (.*)$/, a) { print a[1]}' > remote.location
find /var/log/packages \( -name '*compat32*' -o -name '*multilib*' \) | gawk -F'/' '{print $5}' > local
echo " Build indexes..."
while read line ; do
line=`basename $line`
inv=`invert $line`
build=$(invert `echo $inv | cut -d'-' -f'1'` | sed 's/\.t.z//g')
arch=$(invert `echo $inv | cut -d'-' -f'2'`)
version=$(invert `echo $inv | cut -d'-' -f'3'`)
name=$(invert `echo $inv | cut -d'-' -f'4,5,6,7'`)
echo "$name:$version:$arch:$build" >> local.db
done < local
while read line ; do
line=`basename $line`
inv=`invert $line`
build=$(invert `echo $inv | cut -d'-' -f'1'` | sed 's/\.t[gx]z//g')
arch=$(invert `echo $inv | cut -d'-' -f'2'`)
version=$(invert `echo $inv | cut -d'-' -f'3'`)
name=$(invert `echo $inv | cut -d'-' -f'4,5,6,7'`)
echo "$name:$version:$arch:$build" >> remote.db
done < remote
cat remote.db > remote.sort
cat local.db > local.sort
paste -d ':' remote.sort remote.location > remote.db
mv local.sort local.db
echo " Checking new packages and/or updates..."
for i in `cat remote.db` ; do
name=`echo $i | cut -d ':' -f1`
rversion=`echo $i | cut -d ':' -f 2`
rbuild=`echo $i | cut -d ':' -f 4`
url=`echo $i | cut -d ':' -f 5`
[[ -f local.db ]] && lversion=`grep "$name:" local.db | cut -d ':' -f 2`
[[ -f local.db ]] && lbuild=`grep "$name:" local.db | cut -d ':' -f 4`
if [ -z "$lversion" ] ; then
remotepath=`grep "$name-$rversion" remote`
package="`echo $i | sed 's/:/-/g'`.`echo $remotepath | cut -d '.' -f 3`"
echo "[*] $name"
echo $URL$url/$remotepath >> download.list
elif [[ "$rversion$rbuild" > "$lversion$lbuild" ]] ; then
remotepath=`grep "$name-$rversion" remote`
package="`echo $i | sed 's/:/-/g'`.`echo $remotepath | cut -d '.' -f 3`"
echo "[+] $name"
echo $URL$url/$remotepath >> download.list
else
echo "[=] $name"
fi
done
echo " `wc -l download.list | cut -d ' ' -f1` package(s) to update"
}
function downloadpackages() {
cd $LIB
np=`wc -l download.list | cut -d ' ' -f1`
echo "[Download]"
while read line ; do
package=$(basename $line)
echo "[$np] $package"
curl -# -L -f -C - -o $CACHE/$package $line
np=`expr $np - 1`
done < download.list
}
function installpackages() {
cd $CACHE
echo "[Install/Update]"
for i in * ; do
upgradepkg --reinstall --install-new $CACHE/$i
done
cleanup
}
function usage() {
echo "Usage: $0 command"
echo ""
echo " u | update Build repository index locally."
echo " d | download Download packages only, do not install."
echo " i | install Download and install packages."
echo " c | clean Remove donwloaded files."
echo " h | help Show this help."
echo ""
_exit
}
checkuser
touch $LOCK
trap _exit INT
if [ ! -d $LIB ] ; then
echo "Please create $LIB as root"
_exit
elif [ ! -d $CACHE ] ; then
echo "Please create $CACHE as root"
_exit
fi
case "$1" in
clean|c)
cleanup
;;
update|u)
checkupdate
;;
download|d)
downloadpackages
;;
install|i)
installpackages
;;
*)
usage
;;
esac
_exit