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