diff options
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | albootstrap | 54 | ||||
-rwxr-xr-x | libalpine.sh | 4 | ||||
-rw-r--r-- | setup-alpine | 2 | ||||
-rw-r--r-- | setup-keymap | 104 | ||||
-rwxr-xr-x | setup-sendbug | 41 |
6 files changed, 210 insertions, 3 deletions
@@ -1,4 +1,4 @@ -V=0.9 +V=1.0 P=alpine-conf PV=$(P)-$(V) APKF=$(PV).apk @@ -7,15 +7,17 @@ PREFIX=/usr/local TMP=$(PV) LIB_FILES=libalpine.sh -SBIN_FILES=lbu\ +SBIN_FILES=albootstrap\ + lbu\ setup-ads\ setup-alpine\ setup-cryptswap\ setup-dns\ setup-hostname\ setup-interfaces\ + setup-keymap\ setup-mta\ - setup-problem-reporting\ + setup-sendbug\ setup-webconf\ update-conf EXTRA_DIST=Makefile README diff --git a/albootstrap b/albootstrap new file mode 100644 index 0000000..2538fa3 --- /dev/null +++ b/albootstrap @@ -0,0 +1,54 @@ +#!/bin/sh + +# bootstrap an alpine installation + +VERSION=1.0 + +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." + diff --git a/libalpine.sh b/libalpine.sh index 871459f..8b68bd7 100755 --- a/libalpine.sh +++ b/libalpine.sh @@ -35,6 +35,10 @@ pkg_inst() { [ -z "$NOCOMMIT" ] && apk_add $* } +pkg_deinst() { + [ -z "$NOCOMMIT" ] && apk_delete $* +} + default_read() { local n read n diff --git a/setup-alpine b/setup-alpine index fc87e7b..b7df4e8 100644 --- a/setup-alpine +++ b/setup-alpine @@ -22,6 +22,7 @@ else PKGADD=apk_add fi +$PREFIX/sbin/setup-keymap $PREFIX/sbin/setup-hostname $PREFIX/sbin/setup-interfaces @@ -38,6 +39,7 @@ rc_add -s 04 modutils rc_add -s 06 procps rc_add -s 08 hostname +rc_add -s 20 keymap rc_add -s 20 syslog rc_add -s 22 bootmisc.sh rc_add -s 24 -k networking diff --git a/setup-keymap b/setup-keymap new file mode 100644 index 0000000..37654e2 --- /dev/null +++ b/setup-keymap @@ -0,0 +1,104 @@ +#!/bin/sh + +PREFIX= +. $PREFIX/lib/libalpine.sh + +MAPDIR="$ROOT/usr/share/bkeymaps" + +if [ -f "$ROOT/etc/conf.d/keymap" ]; then + . "$ROOT/etc/conf.d/keymap" + variant=$(basename $KEYMAP .bmap.gz) +fi + + +show_keymaps() { + local opwd="$PWD" + cd "$ROOT/usr/share/bkeymaps" + ls --color=never + cd "$opwd" +} + +select_layout() { + while true; do + if [ -z "$layout" ]; then + layout=none + fi + echo "Available keyboard layouts:" + show_keymaps + echon "Select keyboard layout [$layout]: " + default_read layout "$layout" + if [ "$layout" = "abort" ] || [ "$layout" = "none" ] ; then + goodbye 0 + elif [ -d "$MAPDIR/$layout" ] ; then + return 0 + fi + done +} + +setup_mapfile() { + local name=$(basename $1) + local conf="$ROOT/etc/conf.d/keymap" + mkdir -p "$ROOT/etc/keymap" + mkdir -p "$ROOT/etc/conf.d/" + if gzip -9 -c "$1" > "$ROOT/etc/keymap/$name.gz" ; then + [ -f "$conf" ] && sed -i '/^KEYMAP=/d' "$conf" + echo "KEYMAP=/etc/keymap/$name.gz" >> "$conf" + # we actually load the keymap now + zcat /etc/keymap/$name.gz | loadkmap + rc_add -s 20 keymap + goodbye 0 + fi +} + +select_variant() { + while true; do + echon "Available variants: " + for i in $(ls $MAPDIR/$layout) ; do + echon "$(basename $i .bmap) " + done + echo "" + if [ ! -f "$MAPDIR/$layout/$variant.bmap" ] ; then + variant="" + fi + echon "Select variant [$variant]: " + default_read variant "$variant" + if [ "$variant" = "abort" ] || [ "$variant" = "none" ]; then + break; + fi + if [ -f "$MAPDIR/$layout/$variant.bmap" ]; then + setup_mapfile "$MAPDIR/$layout/$variant.bmap" + fi + done +} + +goodbye() { + if [ $was_installed -ne 0 ]; then + pkg_deinst bkeymaps + fi + exit $1 +} + +apk_info -e bkeymaps +was_installed=$? + +pkg_inst bkeymaps + +deflayout="$1" +while true; do + + if [ -n "$deflayout" ]; then + layout="$deflayout" + unset deflayout + else + select_layout + fi + + # if there is only one variant, just pick it + count=$(ls $MAPDIR/$layout | wc -l) + if [ $count -eq 1 ]; then + setup_mapfile "$MAPDIR/$layout/$(ls $MAPDIR/$layout)" + continue + fi + + select_variant +done diff --git a/setup-sendbug b/setup-sendbug new file mode 100755 index 0000000..9ce94d8 --- /dev/null +++ b/setup-sendbug @@ -0,0 +1,41 @@ +#!/bin/sh + +PREFIX= +. "$PREFIX/lib/libalpine.sh" + +conf="$ROOT/etc/sendbug/sendbug.conf" + +cfgval() { + awk -F= "/^$1/ {print \$2}" "$ROOT/etc/ssmtp/ssmtp.conf" 2>/dev/null +} + +email=$(awk -F= '/^mailfrom/ {print $2}' "$conf" 2>/dev/null) + +if [ -z "$email" ] ; then + hostname=$(cfgval hostname) + if [ -z "$hostname" ]; then + hostname=$(hostname -f 2>/dev/null || cat /etc/hostname) + fi +else + hostname=$(hostname -f 2>/dev/null || cat /etc/hostname) +fi +domain=$(hostname -d $hostname 2>/dev/null) +if [ -n "$hostname" -a -z "$email" ] ; then + email=$(whoami)@$hostname +fi + +echon "Sender email address for problem reports? [$email] " +default_read email $email + +if grep ^mailfrom "$conf" > /dev/null 2>&1; then + sed -i "s/^mailfrom.*/mailfrom=$email/" "$conf" +else + mkdir -p $(dirname "$conf") + echo "mailfrom=$email" >> "$conf" +fi + +setup-mta + +echo "" +echo "Please run 'sendbug' to submit problem reports" + |