-
Notifications
You must be signed in to change notification settings - Fork 0
/
sadm-random-suff.sh
121 lines (97 loc) · 2.28 KB
/
sadm-random-suff.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
#!/bin/bash
if [ "$UID" -ne 0 ]; then
echo "You should run this script as root in a chroot."
exit 1
fi
which aurman >/dev/null
if [ $? -ne 0 ]; then
echo "Please install aurman first."
exit 1
fi
echo
echo "==> WARNING: You should only run this in a clean chroot that you don't mind"
echo "==> wrecking."
echo
echo "Type 'OK.' to continue."
read input
if [ "$input" != "OK." ]; then
echo "Goodbye"
exit 0
fi
#-----------#
# Constants #
#-----------#
# pattern to match lines with official packages
RGX_OFF="^(?:\((?!(AUR|aur)).*\))?\*\s\S+$"
# pattern to match lines with aur packages
RGX_AUR="^\((?:(AUR|aur)).*\)\*\s\S+$"
SED_EXT="s/.*\*\ //"
#-----------#
# Functions #
#-----------#
generate_list() {
cat package_list_* | grep -Po "$1" | sed "$SED_EXT" | sort | uniq
}
check_official_package() {
pacman -Ss "^$1$">/dev/null
echo $?
}
check_aur_package() {
if [ "$(aurman --aur -Ss "^$1$" | wc -l)" -eq 0 ]; then
echo 1
else
echo 0
fi
}
#--------#
# Script #
#--------#
official_packages=$(generate_list "$RGX_OFF")
aur_packages=$(generate_list "$RGX_AUR")
count_official=$(echo $official_packages | wc -w)
count_aur=$(echo $aur_packages | wc -w)
fail_count=0
echo "- $count_official official packages"
echo "- $count_aur AUR packages"
echo
echo ":: Checking official packages..."
i=1
for p in $official_packages; do
echo -ne "$i/$count_official\r"
if [ "$(check_official_package $p)" -ne 0 ]; then
echo Inexisting package: $p
let "fail_count +=1 "
fi
let "i += 1"
done
echo -e "\n"
echo ":: Checking AUR packages..."
i=1
for p in $aur_packages; do
echo -ne "$i/$count_aur\r"
if [ "$(check_aur_package $p)" -ne 0 ]; then
echo Inexisting package: $p
let "fail_count +=1 "
fi
let "i += 1"
done
echo -e "\n"
echo ":: DONE"
echo "$fail_count failed package(s)"
if [ $fail_count -ne 0 ]; then
echo "Please fix the errors and run again the script to compile the AUR packages"
exit 1
fi
echo
echo ":: Compiling AUR packages..."
echo
echo "creating an user and configuring it to build packages..."
useradd -m packager
echo "packager ALL=(ALL) NOPASSWD: ALL">>/etc/sudoers
chown -R packager /export
mkdir -p /export
echo "PKGDEST=/export">/home/packager/.makepkg.conf
echo "compiling packages..."
for p in $aur_packages; do
su packager -c "aurman --noedit --noconfirm -S $p"
done