forked from yubrajbhoi/unstable-packages
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathstart-builder.sh
executable file
·67 lines (56 loc) · 2.05 KB
/
start-builder.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
#!/bin/sh
set -e -u
SCRIPT_NAME=$(basename "$0")
REPOROOT=$(dirname "$(realpath "$0")")
IMAGE_NAME="xeffyr/termux-advanced-builder"
if [ "$SCRIPT_NAME" = "start-builder-legacy.sh" ]; then
LOCK_FILE="/tmp/.termux-unstable-builder-legacy.lck"
CONTAINER_NAME="termux-unstable-buildenv-legacy"
BUILD_ENVIRONMENT="termux-packages-legacy"
else
LOCK_FILE="/tmp/.termux-unstable-builder.lck"
CONTAINER_NAME="termux-unstable-buildenv"
BUILD_ENVIRONMENT="termux-packages"
fi
cd "$REPOROOT"
if [ ! -e "$LOCK_FILE" ]; then
touch "$LOCK_FILE"
fi
(flock -n 3 || exit 0
docker stop "$CONTAINER_NAME" >/dev/null 2>&1 || true
echo "[*] Setting up repository submodules..."
git submodule deinit --all --force
git submodule update --init
echo "[*] Copying packages to build environment..."
for pkg in $(find "$REPOROOT"/packages "$REPOROOT"/manual-packages -mindepth 1 -maxdepth 1 -type d); do
if [ ! -d "${REPOROOT}/${BUILD_ENVIRONMENT}/packages/$(basename "$pkg")" ]; then
cp -a "$pkg" "${REPOROOT}/${BUILD_ENVIRONMENT}"/packages/
else
echo "[!] Package '$(basename "$pkg")' already exists in build environment. Skipping."
fi
done
) 3< "$LOCK_FILE"
(flock -n 3 || true
echo "[*] Running container '$CONTAINER_NAME' from image '$IMAGE_NAME'..."
if ! docker start "$CONTAINER_NAME" > /dev/null 2>&1; then
echo "Creating new container..."
docker run \
--detach \
--name "$CONTAINER_NAME" \
--volume "${REPOROOT}/${BUILD_ENVIRONMENT}:/home/builder/packages" \
--tty \
"$IMAGE_NAME"
if [ "$(id -u)" -ne 0 ] && [ "$(id -u)" -ne 1000 ]; then
echo "Changed builder uid/gid... (this may take a while)"
docker exec --tty "$CONTAINER_NAME" sudo chown -R $(id -u) "/home/builder"
docker exec --tty "$CONTAINER_NAME" sudo chown -R $(id -u) /data
docker exec --tty "$CONTAINER_NAME" sudo usermod -u $(id -u) builder
docker exec --tty "$CONTAINER_NAME" sudo groupmod -g $(id -g) builder
fi
fi
if [ $# -ge 1 ]; then
docker exec --interactive --tty "$CONTAINER_NAME" "$@"
else
docker exec --interactive --tty "$CONTAINER_NAME" bash
fi
) 3< "$LOCK_FILE"