aboutsummaryrefslogtreecommitdiffstats
path: root/albootstrap.in
blob: 3f27f3baafffe7aaf7c0e3b8705b0638c76a6c8d (plain)
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
#!/bin/sh

# bootstrap an alpine installation

VERSION=@VERSION@

usage() {
	echo "usage: $(basename $0) TARGETDIR"
	exit 2
}

die () {
	echo "$@" >&2
	exit 3
}

# set up vars
: ${WGET:="/usr/bin/wget"}
: ${TAR:="/usr/bin/tar"}
: ${MIRROR:="http://dev.alpinelinux.org/alpine/v1.7"}
: ${BASE:="base.tar.bz2"}
target=$1

# main
[ -z "$target" ] && usage
[ "$target" = "/" ] && die "Bootstrapping Alpine to '/' is probably not a good idea. Aborting..."

mkdir -p "$target"

echo ">>> Fetching $MIRROR/$BASE..."
$WGET -q -O - "$MIRROR/$BASE" | tar -C "$target" -jx || die "Failed to fetch or unpack $BASE"

echo ">>> Creating missing dirs..."
for dir in proc sys dev home; do
	mkdir -p "$target/$dir"
done

echo ">>> Installing busybox links..."
# create fake /proc/self/exe
mkdir -p "$target/proc/self"
ln -s /bin/busybox "$target/proc/self/exe"
chroot "$target" /bin/busybox --install -s
rm -r "$target/proc/self"

if [ -f /etc/resolv.conf ]; then
	echo ">>> Copying /etc/resolv.conf..."
	cp /etc/resolv.conf "$target/etc/"
fi

echo ">>> Setting up APK_PATH..."
echo "export APK_PATH=$MIRROR/apks" >> "$target/etc/profile"

echo ">>> Alpine bootstrap complete."