2014-04-13 18:52:21 +04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
[ $(id -u) -eq 0 ] || {
|
|
|
|
printf >&2 '%s requires root\n' "$0"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf >&2 '%s: [-r release] [-m mirror] [-s]\n' "$0"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp() {
|
2014-06-27 16:43:12 +04:00
|
|
|
TMP=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-XXXXXXXXXX)
|
|
|
|
ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-rootfs-XXXXXXXXXX)
|
2014-04-13 18:52:21 +04:00
|
|
|
trap "rm -rf $TMP $ROOTFS" EXIT TERM INT
|
|
|
|
}
|
|
|
|
|
|
|
|
apkv() {
|
2014-07-07 20:35:38 +04:00
|
|
|
curl -sSL $REPO/$ARCH/APKINDEX.tar.gz | tar -Oxz |
|
2014-04-13 18:52:21 +04:00
|
|
|
grep '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2
|
|
|
|
}
|
|
|
|
|
|
|
|
getapk() {
|
2014-07-07 20:35:38 +04:00
|
|
|
curl -sSL $REPO/$ARCH/apk-tools-static-$(apkv).apk |
|
2014-04-13 18:52:21 +04:00
|
|
|
tar -xz -C $TMP sbin/apk.static
|
|
|
|
}
|
|
|
|
|
|
|
|
mkbase() {
|
|
|
|
$TMP/sbin/apk.static --repository $REPO --update-cache --allow-untrusted \
|
|
|
|
--root $ROOTFS --initdb add alpine-base
|
|
|
|
}
|
|
|
|
|
|
|
|
conf() {
|
|
|
|
printf '%s\n' $REPO > $ROOTFS/etc/apk/repositories
|
|
|
|
}
|
|
|
|
|
|
|
|
pack() {
|
|
|
|
local id
|
|
|
|
id=$(tar --numeric-owner -C $ROOTFS -c . | docker import - alpine:$REL)
|
|
|
|
|
|
|
|
docker tag $id alpine:latest
|
|
|
|
docker run -i -t alpine printf 'alpine:%s with id=%s created!\n' $REL $id
|
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
|
|
|
[ $SAVE -eq 1 ] || return
|
|
|
|
|
|
|
|
tar --numeric-owner -C $ROOTFS -c . | xz > rootfs.tar.xz
|
|
|
|
}
|
|
|
|
|
|
|
|
while getopts "hr:m:s" opt; do
|
|
|
|
case $opt in
|
|
|
|
r)
|
|
|
|
REL=$OPTARG
|
|
|
|
;;
|
|
|
|
m)
|
|
|
|
MIRROR=$OPTARG
|
|
|
|
;;
|
|
|
|
s)
|
|
|
|
SAVE=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
REL=${REL:-edge}
|
|
|
|
MIRROR=${MIRROR:-http://nl.alpinelinux.org/alpine}
|
|
|
|
SAVE=${SAVE:-0}
|
|
|
|
REPO=$MIRROR/$REL/main
|
2015-02-13 15:37:21 +03:00
|
|
|
ARCH=${ARCH:-$(uname -m)}
|
2014-04-13 18:52:21 +04:00
|
|
|
|
|
|
|
tmp
|
|
|
|
getapk
|
|
|
|
mkbase
|
|
|
|
conf
|
|
|
|
pack
|
|
|
|
save
|