-
Notifications
You must be signed in to change notification settings - Fork 3
/
pkg
executable file
·136 lines (106 loc) · 2.89 KB
/
pkg
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
#!/bin/sh
source /etc/os-release
if [ -f /etc/default/pkg ]; then
source /etc/default/pkg
fi
: ${BUILDER:="ailispaw/barge-pkg"}
: ${PKG_DIR:="/opt/pkg"}
: ${PKG_URL:="https://github.com/bargees/barge-pkg/releases/download"}
BUILDER="${BUILDER}:${VERSION}"
PKG_DIR="${PKG_DIR}/${VERSION}"
PKG_URL="${PKG_URL}/${VERSION}"
usage() {
echo "Usage: $(basename $0) {build|install} [-f] <package-name> [build options]" >&2
echo " $(basename $0) show <package-name>" >&2
echo " $(basename $0) list" >&2
exit 1
}
download() {
echo -n "Downloading..."
trap "rm -rf ${PKG_FILE}" ERR
wget -qO ${PKG_FILE} ${PKG_URL}/${PKG_NAME}.tar.gz
[ -f ${PKG_FILE} ] && echo "DONE" || echo "FAIL"
}
build() {
ARCH=$(uname -m)
if [ "${ARCH}" != "x86_64" ]; then
echo "Building on ${ARCH} isn't supported." >&2
exit 1
fi
echo "Building..."
local TMP_DIR=/tmp/${PKG_NAME}
local TARGET_DIR=/build/buildroot/output/target
set -e
rm -rf ${TMP_DIR}
trap "rm -rf ${TMP_DIR}" EXIT
mkdir -p ${TMP_DIR}
for i in bin dev/pts etc/ld.so.conf.d etc/network lib sbin usr/bin usr/lib usr/sbin var/lib/misc; do
mkdir -p ${TMP_DIR}/$i
done
docker run --rm -v ${TMP_DIR}:${TARGET_DIR} "${OPTIONS[@]}" ${BUILDER} sh -c " \
cp .config .config.org && \
echo BR2_PACKAGE_$(echo ${PACKAGE} | tr a-z- A-Z_)=y >> .config && \
(env | grep ^BR2_ >> .config || true) && \
(make oldconfig >/dev/null 2>&1 || make oldconfig >/dev/null 2>&1) && \
(diff .config .config.org || true) && \
make --quiet ${PACKAGE} \
"
busybox tar -zc -f ${PKG_FILE} -C ${TMP_DIR} .
echo "DONE"
}
install() {
echo "Installing..."
busybox tar -zx -f ${PKG_FILE} -C /
echo "${PKG_NAME} has been installed into the system."
}
COMMAND=$1
[ -z "${COMMAND}" ] && usage
if [ "${COMMAND}" = "list" ]; then
ls -1l ${PKG_DIR} 2> /dev/null
exit
fi
shift
FORCE_BUILD=false
if [ "$1" = "-f" ]; then
FORCE_BUILD=true
shift
fi
PACKAGE=$1
[ -z "${PACKAGE}" ] && usage
PKG_NAME=barge-pkg-${PACKAGE}-${VERSION}
PKG_FILE=${PKG_DIR}/${PKG_NAME}.tar.gz
if [ "${COMMAND}" = "show" ]; then
busybox tar -zt -f ${PKG_FILE}
exit
fi
shift
OPTIONS=("$@")
if [ "$(id -u)" != "0" ]; then
echo "$(basename $0): Operation not permitted, must be root." >&2
exit 1
fi
mkdir -p ${PKG_DIR}
case "${COMMAND}" in
build)
[[ ("${FORCE_BUILD}" = false) && (! -f ${PKG_FILE}) ]] && download
[[ ("${FORCE_BUILD}" = true) || (! -f ${PKG_FILE}) ]] && build
if [ -f ${PKG_FILE} ]; then
echo "${PKG_NAME} has been in ${PKG_DIR}."
else
echo "Could not build/download ${PKG_NAME}" >&2
exit 1
fi
;;
install)
[[ ("${FORCE_BUILD}" = false) && (! -f ${PKG_FILE}) ]] && download
[[ ("${FORCE_BUILD}" = true) || (! -f ${PKG_FILE}) ]] && build
if [ -f ${PKG_FILE} ]; then
install
else
echo "Could not install ${PKG_NAME}" >&2
exit 1
fi
;;
*)
usage
esac