github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/contrib/mkimage-alpine.sh (about) 1 #!/bin/sh 2 3 set -e 4 5 [ $(id -u) -eq 0 ] || { 6 printf >&2 '%s requires root\n' "$0" 7 exit 1 8 } 9 10 usage() { 11 printf >&2 '%s: [-r release] [-m mirror] [-s] [-c additional repository] [-a arch]\n' "$0" 12 exit 1 13 } 14 15 tmp() { 16 TMP=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-XXXXXXXXXX) 17 ROOTFS=$(mktemp -d ${TMPDIR:-/var/tmp}/alpine-docker-rootfs-XXXXXXXXXX) 18 trap "rm -rf $TMP $ROOTFS" EXIT TERM INT 19 } 20 21 apkv() { 22 curl -sSL $MAINREPO/$ARCH/APKINDEX.tar.gz | tar -Oxz | 23 grep --text '^P:apk-tools-static$' -A1 | tail -n1 | cut -d: -f2 24 } 25 26 getapk() { 27 curl -sSL $MAINREPO/$ARCH/apk-tools-static-$(apkv).apk | 28 tar -xz -C $TMP sbin/apk.static 29 } 30 31 mkbase() { 32 $TMP/sbin/apk.static --repository $MAINREPO --update-cache --allow-untrusted \ 33 --root $ROOTFS --initdb add alpine-base 34 } 35 36 conf() { 37 printf '%s\n' $MAINREPO > $ROOTFS/etc/apk/repositories 38 printf '%s\n' $ADDITIONALREPO >> $ROOTFS/etc/apk/repositories 39 } 40 41 pack() { 42 local id 43 id=$(tar --numeric-owner -C $ROOTFS -c . | docker import - alpine:$REL) 44 45 docker tag $id alpine:latest 46 docker run -i -t --rm alpine printf 'alpine:%s with id=%s created!\n' $REL $id 47 } 48 49 save() { 50 [ $SAVE -eq 1 ] || return 0 51 52 tar --numeric-owner -C $ROOTFS -c . | xz > rootfs.tar.xz 53 } 54 55 while getopts "hr:m:sc:a:" opt; do 56 case $opt in 57 r) 58 REL=$OPTARG 59 ;; 60 m) 61 MIRROR=$OPTARG 62 ;; 63 s) 64 SAVE=1 65 ;; 66 c) 67 ADDITIONALREPO=$OPTARG 68 ;; 69 a) 70 ARCH=$OPTARG 71 ;; 72 *) 73 usage 74 ;; 75 esac 76 done 77 78 REL=${REL:-edge} 79 MIRROR=${MIRROR:-http://nl.alpinelinux.org/alpine} 80 SAVE=${SAVE:-0} 81 MAINREPO=$MIRROR/$REL/main 82 ADDITIONALREPO=$MIRROR/$REL/${ADDITIONALREPO:-community} 83 ARCH=${ARCH:-$(uname -m)} 84 85 tmp 86 getapk 87 mkbase 88 conf 89 pack 90 save