]> git.sev.monster Git - abchr.git/blob - abchr
apkgvers: replace grep/sed with awk
[abchr.git] / abchr
1 #!/bin/sh
2 [ "$(id | awk '{print $1}')" != 'uid=0(root)' ] && exec sudo "$0" "$@"
3
4 dir="$(realpath "$(dirname "$0")/../alpine")"
5 aports="$(realpath "$dir/../aports")"
6 if [ $# -gt 0 ]; then
7         cmd="$@"
8 else
9         cmd='/bin/ash -i'
10 fi
11
12 um=0
13 uma() {
14         : $((++um))
15         eval "um$um='$1'"
16 }
17 m() {
18         src="$1"; shift
19         dst="$1"; shift
20         mkdir -p "$dst"
21         mount $@ "$src" "$dst"
22         uma "$dst"
23 }
24 mb() {
25         src="$1"; shift
26         if [ $# -gt 0 -a "x$(echo "$1" | cut -c 1)" = x/ ]; then
27                 dst="$dir$1"; shift
28         else
29                 dst="$dir$src"
30         fi
31         src="$(realpath $src)"
32         [ ! -e "$src" ] && return
33         m "$src" "$dst" --bind --slave $@
34 }
35
36 mb /dev -oro
37 mb /dev/pts
38 mb /dev/shm
39 mb /dev/mqueue
40 m none "$dir/proc" -t proc
41 mb /sys
42 ln -f /etc/resolv.conf "$dir/etc/resolv.conf"
43 mb "$aports" /home/abuild/aports
44 mb /srv/alpine/edge /home/abuild/packages
45 mb /var/cache/distfiles
46 mb /etc/apk/cache
47
48 f="$(chroot "$dir" mktemp -p/tmp/)"
49
50 chrdir="$PWD/"
51 chrdir="${chrdir%/aports/*}"
52 if [ "$chrdir" != "$PWD/" ]; then
53         cmd="cd \"/home/abuild${PWD#$chrdir}\" && $cmd"
54 fi
55
56 echo "$cmd" | tee "$dir/$f"
57 chmod ugo+r "$dir/$f"
58 chroot "$dir" /bin/su abuild -l "$f"
59
60 rm -f "$dir/$f"
61
62 for x in $(seq $um -1 1); do
63         eval "umount \$um$x"
64 done
This page took 0.034356 seconds and 4 git commands to generate.