-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacbrew.sh
executable file
·200 lines (170 loc) · 5.89 KB
/
pacbrew.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
#!/bin/bash
set -e
COL_GREEN='\033[0;32m'
COL_NONE='\033[0m'
function check_pacman {
if ! command -v pacman &> /dev/null
then
echo -e "${COL_GREEN}check_pacman:${COL_NONE} pacman not found, exiting..."
exit 1
fi
echo -e "${COL_GREEN}check_pacman:${COL_NONE} synching repositories..."
sudo -E pacman -Syy #&> /dev/null
echo -e "${COL_GREEN}check_pacman:${COL_NONE} ok"
}
# get_pkg_info PKGBUILD ARCH
function get_pkg_info() {
pushd $(dirname "$1") &> /dev/null || exit 1
local pkginfo=`CARCH=$2 makepkg --printsrcinfo` &> /dev/null || exit 1
popd &> /dev/null || exit 1
echo "$pkginfo"
}
# get_pkg_var PKGINFO VAR
function get_pkg_var() {
echo `echo "$1" | grep "$2 =" | cut -d= -f2 | xargs`
}
# get_pkg_name PKGINFO
function get_pkg_name() {
echo `get_pkg_var "$1" "pkgname"`
}
# get_pkg_ver PKGINFO
function get_pkg_ver() {
echo `get_pkg_var "$1" "pkgver"`
}
# get_pkg_rel PKGINFO
function get_pkg_rel() {
echo `get_pkg_var "$1" "pkgrel"`
}
# get_pkg_arch PKGINFO
function get_pkg_arch() {
echo `get_pkg_var "$1" "arch"`
}
# get_pkg_deps PKGINFO
function get_pkg_deps() {
echo `get_pkg_var "$1" "depends"`
}
# get_pkg_groups PKGINFO
function get_pkg_groups() {
echo `get_pkg_var "$1" "groups"`
}
# is_android_portlibs_pkg LINE
function is_android_portlibs_pkg() {
if [[ "$1" == *"android-portlibs"* ]]; then
# 0 = true
return 0
else
# 1 = false
return 1
fi
}
function install_local_package {
sudo pacman --noconfirm -U $1 || exit 1
#&> /dev/null
}
function install_remote_package {
sudo pacman --noconfirm --needed -S $1 || exit 1
#&> /dev/null
}
# clean_package PKGPATH
function clean_package {
pushd "$1" &> /dev/null || exit 1
#rm -rf *.pkg.tar.* || exit 1
#git clean -fd -x .
popd &> /dev/null || exit 1
}
# build_package PKGPATH ARCH
function build_package {
# build package
pushd "$1" &> /dev/null || exit 1
rm -rf *.pkg.tar.* &> /dev/null || exit 1
CARCH=$2 makepkg -C -f --clean || exit 1
popd &> /dev/null || exit 1
}
function build_packages {
PACBREW_SSH_HOST="mydedibox.fr"
remote_packages=`pacman -Sl | grep pacbrew`
# parse args
while test $# -gt 0
do
case "$1" in
-f) echo -e "${COL_GREEN}build_packages${COL_NONE}: force rebuild all packages"
PACBREW_BUILD_ALL=true
;;
-u) echo -e "${COL_GREEN}build_packages${COL_NONE}: uploading packages to pacbrew repo with specified user"
PACBREW_UPLOAD=true
shift && PACBREW_SSH_USER="$1"
;;
-h) echo -e "${COL_GREEN}build_packages${COL_NONE}: uploading packages to pacbrew repo with specified host"
PACBREW_UPLOAD=true
shift && PACBREW_SSH_HOST="$1"
;;
esac
shift
done
# download repo files from server, if needed
if [ $PACBREW_UPLOAD ]; then
echo -e "${COL_GREEN}build_packages:${COL_NONE} downloading pacbrew repo..."
rm -rf pacbrew-repo && mkdir -p pacbrew-repo
scp $PACBREW_SSH_USER@$PACBREW_SSH_HOST:/var/www/pacbrew/packages/pacbrew.* pacbrew-repo || exit 1
fi
while read line; do
# skip empty lines and comments
if [ -z "$line" ] || [[ $line == \#* ]] ; then
continue
fi
# set target arch
ARCHS="any"
# android portlibs can be aarch64 or armv7a
if is_android_portlibs_pkg $line; then
ARCHS="aarch64 armv7a x86_64"
fi
for ARCH in $ARCHS; do
# get local package info string
PKGINFO=$(get_pkg_info "$line/PKGBUILD" $ARCH)
# get local package name and version from info string
local_pkgname=$(get_pkg_name "$PKGINFO")
local_pkgver=$(get_pkg_ver "$PKGINFO")
local_pkgrel=$(get_pkg_rel "$PKGINFO")
local_pkgdeps=$(get_pkg_deps "$PKGINFO")
local_pkggrps=$(get_pkg_groups "$PKGINFO")
local_pkgverrel="$local_pkgver-$local_pkgrel"
#echo "name: $local_pkgname, version: $local_pkgverrel, groups: $local_pkggrps, depends: $local_pkgdeps"
#continue
# get remote package name and version
remote_pkgname=`echo "$remote_packages" | grep "$local_pkgname " | awk '{print $2}'`
remote_pkgverrel=`echo "$remote_packages" | grep "$local_pkgname " | awk '{print $3}'`
if [ -z "$remote_pkgverrel" ]; then
remote_pkgverrel="n/a"
fi
# only build packages that are not available (version differ)
if [ $PACBREW_BUILD_ALL ] || [ "$local_pkgverrel" != "$remote_pkgverrel" ]; then
echo -e "${COL_GREEN}build_packages:${COL_NONE} new package: ${COL_GREEN}$local_pkgname${COL_NONE} ($remote_pkgverrel => $local_pkgverrel)"
echo -e "${COL_GREEN}build_packages:${COL_NONE} building ${COL_GREEN}$local_pkgname${COL_NONE} ($local_pkgverrel)"
build_package "$line" $ARCH
# install built package
echo -e "${COL_GREEN}build_packages:${COL_NONE} installing ${COL_GREEN}$line/$local_pkgname-$local_pkgverrel.pkg.tar.xz${COL_NONE}"
install_local_package $line/*.pkg.tar.xz
if [ $PACBREW_UPLOAD ]; then
echo -e "${COL_GREEN}build_packages:${COL_NONE} uploading ${COL_GREEN}$local_pkgname${COL_NONE} to pacbrew repo"
scp $line/*.pkg.tar.xz $PACBREW_SSH_USER@$PACBREW_SSH_HOST:/var/www/pacbrew/packages/ || exit 1
repo-add pacbrew-repo/pacbrew.db.tar.gz $line/*.pkg.tar.xz || exit 1
fi
# cleanup
clean_package "$line"
else
# always install deps for later packges build
echo -e "${COL_GREEN}build_packages: $local_pkgname${COL_NONE} is up to date, installing if needed..."
install_remote_package "$local_pkgname"
fi
done
done < pacbrew-packages.cfg
# upload updated repo files and cleanup
if [ $PACBREW_UPLOAD ]; then
echo -e "${COL_GREEN}build_packages:${COL_NONE} updating pacbrew repo with new packages..."
scp pacbrew-repo/* $PACBREW_SSH_USER@$PACBREW_SSH_HOST:/var/www/pacbrew/packages/ || exit 1
rm -rf pacbrew-repo
fi
echo -e "${COL_GREEN}build_packages:${COL_NONE} all done !"
}
check_pacman
build_packages "$@"