-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
215 lines (185 loc) · 6.53 KB
/
update.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
#!/usr/bin/bash
build_home='/build/amr'
repo_name='mingw-w64-testing'
chroot_dir="$build_home/build/chroot"
src_dir="$build_home/build"
script_dir="$build_home"
log_dir="$build_home/Dropbox/logs"
pkgbuilds_dir="$build_home/build/pkgbuilds"
test_dir="$build_home/Dropbox/repo-testing"
log_file="$build_home/Dropbox/update.log"
############# MODIFICATIONS TO PACKAGES #############################
before_build() {
#skudo ----------
# manual way to install qt4-dummy for now
if [ "$pkg" = 'mingw-w64-qt4-static' ]; then
pushd "$src_dir"
curl -O https://dl.dropboxusercontent.com/u/33784287/websharing/mingw-w64-qt4-dummy/PKGBUILD
makepkg --noconfirm --asroot 2>&1 | tee -a "$pkg.log"
rm -R pkg src PKGBUILD
yes | makechrootpkg -r "$chroot_dir" -I mingw-w64-qt4-dummy-1-1-any.pkg.tar.xz -l root -- --noprogressbar 2>&1 | tee -a "$pkg.log"
rm mingw-w64-qt4-dummy-1-1-any.pkg.tar.xz
popd
fi
[ "$last_pkg" = 'mingw-w64-qt4-static' ] && \
arch-nspawn "$chroot_dir/root" pacman -Rscnd --quiet --noconfirm mingw-w64-qt4-dummy 2>&1 | tee -a "$pkg.log"
# used if needing to do something after last build but before next build_home
last_pkg="$pkg"
# some source tarballs don't have the correct permissions
chmod 777 -R .
}
modify_ver() {
# manual changes to some packages to make them not auto update
[ "$npkg" = 'gyp-svn 1775-1' ] && nver='1847-1'
[ "$npkg" = 'mingw-w64-cal3d-svn 560-1' ] && nver='562-1'
[ "$npkg" = 'mingw-w64-headers-svn 6298-1' ] && nver='6638-1'
[ "$npkg" = 'mingw-w64-crt-svn 6362-1' ] && nver='6638-1'
[ "$npkg" = 'mingw-w64-winpthreads-svn 6362-1' ] && nver='6638-1'
}
############# FUNCTIONS #############################################
compile() {
for pkg in "${buildlist[@]}"; do
mkdir -p "$src_dir/$pkg"
echo "building $pkg" | tee -a $log_file
# download package
curl https://aur.archlinux.org/packages/${pkg:0:2}/$pkg/$pkg.tar.gz | tar xz -C "$src_dir"
pushd "$src_dir/$pkg"
source_package PKGBUILD
before_build
# compile package
arch-nspawn "$chroot_dir/root" pacman -Sy
makechrootpkg -c -r "$chroot_dir" -l mingw -- --noprogressbar 2>&1 | tee "$pkg.log"
# if package was created update temp repository
if [ -f *.pkg.tar.xz ]; then
for pkgtar in *.pkg.tar.xz; do
npkgtar=$(/build/amr/fixname.py $pkgtar)
echo "Renaming $pkgtar to $npkgtar"
# move to test dir and add to test repo
mv "$pkgtar" "$test_dir/$npkgtar"
repo-add "$test_dir/$repo_name.db.tar.gz" "$test_dir/$npkgtar"
done
else
sed -i '$ d' $log_file # delete last line and replace with failed
echo "$pkg failed to build" | tee -a $log_file
fi
# compress and store away log
tar -czf "$log_dir/$pkg.log.tar.gz" "$pkg.log"
popd
# delete the package directory
rm -fR "$src_dir/$pkg"
done
}
create_updatelist() {
unset updatelist
mkdir -p "$pkgbuilds_dir"
./downloalpkgs.py
# loop to check for packages that are outdated
echo "Find packages that need to be updated"
for pkg in ${pkglist[@]}; do
#echo "downloading PKGBUILD for $pkg"
#curl -s "https://aur.archlinux.org/packages/${pkg:0:2}/$pkg/PKGBUILD" > "$pkgbuilds_dir/$pkg"
source_package "$pkgbuilds_dir/$pkg"
curver=`pacman -Si $pkg 2>/dev/null | grep Version | tr -d ' ' | sed -e "s/Version://" | head -n 1`
modify_ver
if [ "$curver" != $nver ]; then
echo "updating $pkg from $curver to $nver" | tee -a $log_file
updatelist+=($pkg)
fi
done
}
create_buildlist() {
unset buildlist
for pkg in ${updatelist[@]}; do
echo -n "$pkg "
buildlist+=($pkg)
# check all packages and add the package to the list that depends on pkg
# this is not needed if the package does not exsist yet
if [[ `pacman -Si $pkg 2>/dev/null` ]]; then
for dep in ${pkglist[@]}; do
# if package hasn't been built yet don't add it as a reverse dependency
if [[ `pacman -Si $dep 2>/dev/null` ]]; then
source_package "$pkgbuilds_dir/$dep"
for rdep in "${depends[@]}" "${optdepends[@]}" "${makedepends[@]}"; do
# remove description from dependency
i=`expr index "${rdep}" ':><=' - 1`
if [ "$i" -eq '-1' ]; then i="${#rdep}"; fi
# if package in reverse dependencies then add to build list
if [ "${rdep:0:$i}" = "$pkg" ]; then buildlist+=($dep) ;fi
done
fi
done; fi
done
# loop and remove duplicates (only buld the last time needed)
echo -e '\nRemoving duplicates from build list'
x=0; buldlength=${#buildlist[@]}
while (( $x < $buldlength )); do
testpkg=${buildlist[x]}
y=0
while (( $y < $x )); do
[ "$testpkg" = "${buildlist[y]}" ] && unset buildlist[y]
let "y+=1"
done
let "x+=1"
done
echo -e "Update will now rebuild the following packages.\n${buildlist[@]}"
}
source_package() {
unset depends optdepends makedepends epoch nver
source $1
[[ "$epoch" ]] && nver="${epoch}:"
nver="${nver}${pkgver}-${pkgrel}"
npkg="$pkgname $nver"
}
clean_dirs() {
rm -fR "$chroot_dir"
rm -fR "$pkgbuilds_dir"
}
prepare_chroot() {
# create new chroot
clean_dirs
mkdir -p "$chroot_dir"
mkarchroot "$chroot_dir/root" base-devel
echo '
[multilib]
Include = /etc/pacman.d/mirrorlist
[mingw-w64-testing]
SigLevel = Optional TrustAll
Server = http://127.0.0.1/
[mingw-w64]
SigLevel = Optional TrustAll
Server = http://downloads.sourceforge.net/project/mingw-w64-archlinux/$arch
' >> "$chroot_dir/root/etc/pacman.conf"
sed 's|#PACKAGER="John Doe <[email protected]>"|PACKAGER="ant32 <[email protected]>"|' -i "$chroot_dir/root/etc/makepkg.conf"
arch-nspawn "$chroot_dir/root" pacman -Syu
}
# check for lock file and create one if it does not exsist
if [ ! -f "$script_dir/lock" ]; then
# create lock
touch "$script_dir/lock"
echo "STARTING UPDATE `date`" | tee -a $log_file
# start darkhttpd
darkhttpd "$test_dir" &
dpid=$!
pacman -Sy
prepare_chroot
# create package list
unset pkglist
while read pkg; do if [ "${pkg:0:1}" != "#" ]; then pkglist+=($pkg); fi; done < "$script_dir/buildlist.txt"
if [ "$1" = 'rebuild' ]; then
buildlist=( "${pkglist[@]}" )
else
echo "Creating update list ..."
create_updatelist
echo "Creating build list (This may take a while) ..."
#create_buildlist
buildlist=( "${updatelist[@]}" )
fi
echo "We will now start compiling ..."
compile
# stop darkhttpd
kill -s 9 $dpid
# remove lock
echo "Building packages completed at `date`" | tee -a $log_file
clean_dirs
rm "$script_dir/lock"
fi