From e753a4d1af740a3cfeb4a4c994395f3a0a5a3c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 2 Sep 2018 22:55:51 +0200 Subject: alpine-amd64: try to change how we do chroot --- jobs/alpine-amd64.run | 63 +-------------------------------------------------- jobs/alpine-amd64.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++ scripts/uchroot | 15 ++++++------ 3 files changed, 63 insertions(+), 70 deletions(-) create mode 100755 jobs/alpine-amd64.sh diff --git a/jobs/alpine-amd64.run b/jobs/alpine-amd64.run index 96bfb2b..80e8644 100755 --- a/jobs/alpine-amd64.run +++ b/jobs/alpine-amd64.run @@ -6,68 +6,7 @@ set -e if [ -n "$CLEAN" ]; then echo_stage "Remove root" flock --exclusive "$WORKSPACE/root.lock" uroot rm -rf "$WORKSPACE/root" - exit 0 fi -cat >abuild-system.conf < .abuild/abuild.conf -EEOF - uroot cp ~/alpinelinux.rsa.key "$ROOT/home/build/.abuild/key.rsa" - uchroot "$ROOT" root chown build:build "/home/build/.abuild/key.rsa" - uroot cp ~/alpinelinux.rsa.key.pub "$ROOT/etc/apk/keys/cynerd@email.cz-5b8aeb6d.rsa.pub" - uroot cp abuild-system.conf "$ROOT/etc/abuild.conf" - fi - - echo_stage "Update system" - uchroot "$ROOT" root /bin/sh -ce 'apk update && apk upgrade' - - echo_stage "Update package sources" - git_clone "git@cynerd.cz:alpine-personal-pkgs" "aports" - uroot rm -rf "$ROOT/home/build/aports" - uroot mv aports "$ROOT/home/build/aports" - uchroot "$ROOT" root chown -R build:build /home/build/aports - - echo_stage "Build packages" - # TODO generate list of repositories automatically - uchroot "$ROOT" build:build buildrepo --purge personal hacked -EOF +flock --exclusive "$WORKSPACE/root.lock" "$(readlink -f "$0" | sed 's/\.run$/\.sh/')" diff --git a/jobs/alpine-amd64.sh b/jobs/alpine-amd64.sh new file mode 100755 index 0000000..e5a6df3 --- /dev/null +++ b/jobs/alpine-amd64.sh @@ -0,0 +1,55 @@ +#!/bin/sh +. utils + +# TODO get latest uri from latest-releases.yml file + +if [ ! -d "$ROOT" ]; then + echo_stage "Setting up new root" + wget "http://dl-cdn.alpinelinux.org/alpine/edge/releases/x86_64/alpine-minirootfs-3.8.0-x86_64.tar.gz" -O alpine.tar.gz + gunzip alpine.tar.gz + tar -f alpine.tar --delete ./dev/null + mkdir "$ROOT" + uroot tar -xf alpine.tar -C "$ROOT" + chmod 755 "$ROOT" # This is intentional, tar changes access rights + uchroot "$ROOT" root /bin/sh < .abuild/abuild.conf' + uroot cp ~/alpinelinux.rsa.key "$ROOT/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa" + uchroot "$ROOT" root 'chown build:build "/build/.abuild/cynerd@email.cz-5b8aeb6d.rsa"' + uroot cp ~/alpinelinux.rsa.key.pub "$ROOT/etc/apk/keys/cynerd@email.cz-5b8aeb6d.rsa.pub" + uroot cat >"$ROOT/etc/abuild.conf" <&2 +[ $# -ge 1 ] || { + echo "Usage: uchroot ROOT [USER] [CMD]" >&2 exit 1 } @@ -11,8 +11,10 @@ fi ############################################################### ROOT="$1" -USERSPEC="$2" +USR="${2:-root}" shift 2 +[ $# -lt 1 ] && CMD="" || CMD="-c '$@'" + [ -d "$ROOT" ] || { echo "There is no such directory: $ROOT" >&2 exit 1 @@ -22,14 +24,11 @@ shift 2 exit 1 } - +mount --rbind "$ROOT" "$ROOT" mount -t proc none "$ROOT/proc" mount --rbind /dev "$ROOT/dev" mount --rbind /sys "$ROOT/sys" cp -f /etc/resolv.conf "$ROOT/etc/resolv.conf" cp -f /etc/hosts "$ROOT/etc/hosts" -if [ $# -lt 1 ]; then - set "/bin/sh" -fi -exec chroot --userspec="$USERSPEC" "$ROOT" "$@" +exec chroot "$ROOT" /bin/sh -c ". /etc/profile && exec su $CMD -l $USR" "$0" -- cgit v1.2.3