summaryrefslogtreecommitdiffstats
path: root/alpine-chroot
diff options
context:
space:
mode:
authorFabian Affolter <mail@fabian-affolter.ch>2013-10-28 18:26:56 +0100
committerFabian Affolter <mail@fabian-affolter.ch>2013-10-28 18:26:56 +0100
commit17b610dc9d143a3c5c3618027b1d5fc3a6a7c8ad (patch)
tree0180dc1f48fd7e455ce608a9ec72a2f79d6d87f6 /alpine-chroot
parent164b9ad75dda2e84ff163b6d6b6af0af0c7b40ff (diff)
downloadalpine-chroot-17b610dc9d143a3c5c3618027b1d5fc3a6a7c8ad.tar.bz2
alpine-chroot-17b610dc9d143a3c5c3618027b1d5fc3a6a7c8ad.tar.xz
rename script
Diffstat (limited to 'alpine-chroot')
-rw-r--r--alpine-chroot122
1 files changed, 122 insertions, 0 deletions
diff --git a/alpine-chroot b/alpine-chroot
new file mode 100644
index 0000000..5f47a78
--- /dev/null
+++ b/alpine-chroot
@@ -0,0 +1,122 @@
+#!/bin/bash
+#
+# alpine-chroot - Setup a Alpine Linux installation in a chroot.
+# Copyright (c) 2011-2013 Fabian Affolter <fabian at affolter-engineering.ch>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Most parts of this script are written down at
+# http://wiki.alpinelinux.org/wiki/Setting_up_the_build_environment_in_chroot
+
+MIRROR=http://dl-5.alpinelinux.org/alpine
+APK_TOOL=apk-tools-static-2.4.0-r0.apk
+
+usage() {
+ cat <<__EOF__
+usage: alpine-chroot [-h] [-d Directory] [-r Release] [-a Architecture]
+
+Setup an Alpine Installation in a chroot
+
+options:
+ -h Show this help
+ -a Choice of architecture, default: Host architecture
+ -d Directory to install the chroot
+ -r Release of Alpine Linux, default: Latest stable release
+__EOF__
+ exit 1
+}
+
+case $1 in
+ ""|"-h"|"--help") usage;;
+esac
+
+while getopts ":h:a:d:r:" opt; do
+ case $opt in
+ h) usage;;
+ a) ARCH="$OPTARG";;
+ d) CHROOT="$OPTARG";;
+ r) RELEASE="$OPTARG";;
+ \?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
+ :) echo "Option -$OPTARG requires an argument." >&2; exit 1;;
+ esac
+done
+
+if [ "$RELEASE" = "" ]; then
+ LATEST=`curl --silent $MIRROR/.latest.txt`
+ RELEASE=${LATEST:31:3}
+fi
+
+if [ "$ARCH" = "" ]; then
+ ARCH=`uname -i`
+fi
+
+if [ "$ARCH" != "x86" ] && [ "$ARCH" != "x86_64" ]; then
+ echo "$ARCH not supported. Only x86 and x86_64 are supported."
+ exit 1
+fi
+
+if [ "$CHROOT" = "" ]; then
+ CHROOT="alpinechroot-$RELEASE"
+fi
+
+# Root has $UID 0
+ROOT_UID=0
+if [ "$UID" != "$ROOT_UID" ]; then
+ echo "You are not root. Please use su to become root."
+ exit 0
+fi
+
+if [ -d $CHROOT ]; then
+echo "$CHROOT exists already."
+ exit 0
+else
+ mkdir -p $CHROOT
+fi
+
+build_chroot() {
+ curl --silent $MIRROR/v$RELEASE/main/$ARCH/$APK_TOOL -o $APK_TOOL
+ tar -xzf $APK_TOOL
+ ./sbin/apk.static \
+ -X $MIRROR/v$RELEASE/main \
+ -U \
+ --allow-untrusted \
+ --root ././$CHROOT \
+ --initdb add alpine-base alpine-sdk
+
+ mkdir -p $CHROOT{/root,/etc/apk,/proc}
+ mount --bind /proc $CHROOT/proc
+ mknod -m 0666 $CHROOT/dev/full c 1 7
+ mknod -m 0666 $CHROOT/dev/ptmx c 5 2
+ mknod -m 0644 $CHROOT/dev/random c 1 8
+ mknod -m 0644 $CHROOT/dev/urandom c 1 9
+ mknod -m 0666 $CHROOT/dev/zero c 1 5
+ mknod -m 0666 $CHROOT/dev/tty c 5 0
+ rm -f $CHROOT/dev/null
+ mknod -m 0666 $CHROOT/dev/null c 1 3
+
+ cp /etc/resolv.conf $CHROOT/etc/
+ echo "$MIRROR/v$RELEASE/main" > $CHROOT/etc/apk/repositories
+
+ # Cleaning up
+ rm -rf sbin
+ rm -f APK_TOOL
+
+ echo " "
+ echo "Your Alpine Linux installation in '$CHROOT' is ready now."
+ echo "To start Alpine chroot, run as root:"
+ echo " chroot $CHROOT /bin/sh -l"
+ echo " "
+}
+
+build_chroot