diff options
-rw-r--r-- | .gitignore | 16 | ||||
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | albootstrap.in | 54 | ||||
-rw-r--r-- | setup-bootable-usb.in | 52 | ||||
-rw-r--r-- | setup-bootable.in | 212 | ||||
-rw-r--r-- | setup-disk.in | 2 | ||||
-rwxr-xr-x | setup-interfaces.in | 9 | ||||
-rwxr-xr-x | setup-problem-reporting | 40 | ||||
-rwxr-xr-x | setup-sendbug.in | 41 |
9 files changed, 236 insertions, 195 deletions
@@ -1 +1,17 @@ *.tar.gz +lbu +libalpine.sh +setup-acf +setup-ads +setup-alpine-web +setup-alpine +setup-bootable +setup-cryptswap +setup-desktop +setup-disk +setup-dns +setup-hostname +setup-interfaces +setup-keymap +setup-mta +update-conf @@ -1,4 +1,4 @@ -VERSION := 2.3 +VERSION := 2.4 sysconfdir ?= /etc/lbu @@ -20,9 +20,8 @@ SBIN_FILES := lbu\ setup-interfaces\ setup-keymap\ setup-mta\ - setup-sendbug\ setup-acf\ - setup-bootable-usb\ + setup-bootable\ update-conf SCRIPTS := $(LIB_FILES) $(SBIN_FILES) diff --git a/albootstrap.in b/albootstrap.in deleted file mode 100644 index 3f27f3b..0000000 --- a/albootstrap.in +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh - -# bootstrap an alpine installation - -VERSION=@VERSION@ - -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/setup-bootable-usb.in b/setup-bootable-usb.in deleted file mode 100644 index 32d40b2..0000000 --- a/setup-bootable-usb.in +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh - -cleanup() { - if [ "$install_syslinux" = "yes" ]; then - apk del -q syslinux - fi - if [ "$mount_dest" = "yes" ]; then - umount "$dest" - fi -} - -die() { - echo "$@" >&2 - cleanup - exit 1 -} - -apk info -q -e syslinux || install_syslinux=yes - - -if [ "$install_syslinux" = "yes" ]; then - apk add -q syslinux -fi - -src=${1:-/media/cdrom} - -[ -f "$src"/.alpine-release ] || die "$src/.alpine-release not found" - - -dest=${2:-/media/usb} - -if ! awk '{print $2}' /proc/mounts | grep -q "^$dest\$"; then - mount "$dest" || die "Failed to mount $dest" - mount_dest=yes -fi - -echo "Copying files..." -cp -r "$src"/* "$src"/.[a-z]* "$dest" || die "Failed to copy files" - -echo "Making usb bootable..." -dev=$(awk "\$2 == \"$dest\" {print \$1}" /proc/mounts) -parent=$(basename $(dirname /sys/block/*/$(basename $dev))) - -syslinux $dev - -if [ -b /dev/$parent ]; then - dd if=/usr/share/syslinux/mbr.bin of=/dev/$parent -else - echo "Warning: Could not find the parent device for $dev" -fi - -cleanup diff --git a/setup-bootable.in b/setup-bootable.in new file mode 100644 index 0000000..7143ee7 --- /dev/null +++ b/setup-bootable.in @@ -0,0 +1,212 @@ +#!/bin/sh + +prog=${0##*/} +version=@VERSION@ + +cleanup() { + if [ -n "$uninstalls" ]; then + apk del -q syslinux + fi + if [ -n "$umounts" ]; then + umount $umounts + fi +} + +die() { + echo "$@" >&2 + cleanup + exit 1 +} + +# find device for mountpoint +find_dev() { + local mnt="${1%/}" # strip trailing / + awk "\$2 == \"$mnt\" {print \$1}" /proc/mounts +} + +# check if given device is on usb bus +on_usb_bus() { + local dev="$1" + [ -e /sys/block/$dev ] || return 1 + local sysdev=$(readlink -f /sys/block/$dev/device) + test "${sysdev##*/usb[0-9]}" != "$sysdev" +} + + +usage() { + cat <<__EOF__ +$prog $version +usage: $prog [-hu] SOURCE [DEST] + +Copy the contents of SOURCE to DEST and make DEST bootable. + +SOURCE can be a directory or a ISO image. DEST can be a mounted directory +or a device. If DEST is ommitted /media/usb will be used. + +Options: + -f Force overwrite existing files. Will overwrite syslinux.cfg if upgrade. + -h Show this help. + -u Upgrade mode. Keep existing syslinux.cfg and don't run syslinux. + -s Force run syslinux, even if upgrade mode. + -v Verbose mode. Display whats going on. + +__EOF__ + exit 1 +} + +while getopts "fhusv" opt; do + case "$opt" in + f) force=1;; + h) usage;; + u) upgrade=1;; + s) syslinux=1;; + v) verbose=1;; + esac +done + +shift $(($OPTIND - 1)) + +src=${1} +dest=${2:-/media/usb} + +srcmnt=${MNT:-/mnt} + +[ -z "$src" ] && usage + +# Find the srcdir, mount loopback if needed +if [ -f "$src"/.alpine-release ]; then + srcdir="$src" +else + mount -o loop -t iso9660 "$src" $srcmnt \ + || die "Failed to mount loopback $src" + umounts="$srcmnt" + srcdir="$srcmnt" + [ -f "$srcdir"/.alpine-release ] || die "No .alpine-release found on image $src" +fi +to_version=$(cat "$srcdir"/.alpine-release) + +# find target device +if [ -d "$dest" ]; then + dest=${dest%/} # strip trailing / + if ! awk '{print $2}' /proc/mounts | grep -q "^$dest\$"; then + mount "$dest" || die "Failed to mount $dest" + umounts="$umounts $dest" + fi + destdir="$dest" + dest=$(find_dev "$destdir") +elif [ -b "$dest" ]; then + destdir="/media/${dest##*/}" + mkdir -p "$destdir" + mount "$dest" "$destdir" || die "Failed to mount $dest on $destdir" + umounts="$umounts $destdir" +fi +[ -n "$verbose" ] && echo "Using $dest as target (mounted on $destdir)" + + +# find parent device (i.e sda) +dev="$dest" +while [ -L "$dev" ]; do + dev=$(readlink -f $dev) +done +parent_dev=/dev/$(basename $(dirname /sys/block/*/$(basename $dev))) + +# check if this files exist and not in upgrade mode +if [ -z "$upgrade" ] && [ -z "$force" ]; then + for i in boot apks syslinux.cfg .alpine-release; do + [ -e "$destdir"/$i ] && die "$destdir/$i already exists. Aborting" + done +fi + +# check if its same version +if [ -n "$upgrade" ] && [ -e "$destdir"/.alpine-release ]; then + from_version=$(cat "$destdir"/.alpine-release) + if [ -z "$force" ] && [ "$from_version" = "$to_version" ]; then + die "Source and target seems to have same version ($from_version). Aborting." + fi +fi + +# Display what versions we are installing/upgrading +if [ -n "$from_version" ]; then + echo "Upgrading $dest from $from_version to $to_version" +else + echo "Copying $to_version to $dest (mounted on $destdir)" +fi + +# remove partial upgrades if any. +rm -rf "$destdir"/.new "$destdir"/.old + +# check that we have the space we need +needed_space=$(cd "$srcdir" && du -s -c boot apks syslinux.cfg .alpine-release | awk '$2 == "total" {print $1}') +[ -n "$verbose" ] && echo "Needed space: $needed_space kB" + +available_space=$(df -k "$destdir" | tail -n 1 | awk '{print $4}') +[ -n "$verbose" ] && echo "Available space: $available_space kB" +[ $available_space -lt $needed_space ] && die "Not enough space on $destdir. Aborting." + +# copy the files to .new +mkdir -p "$destdir"/.new || die "Failed to create $destdir/.new" +for i in boot apks syslinux.cfg .alpine-release; do + [ -n "$verbose" ] && echo "Copying $srcdir/$i to $destdir/.new/" + cp -a "$srcdir"/$i "$destdir"/.new/ +done + +# make sure files are really there before we replace existing +[ -n "$verbose" ] && echo "Flushing cache..." +sync + +[ -n "$verbose" ] && echo "Replacing existing files..." +mkdir -p "$destdir"/.old || die "Failed to create $destdir/.old" + +# do we want keep existing syslinux.cfg? +tomove="boot apks .alpine-release" +if [ -n "$force" ] || ! [ -e "$destdir"/syslinux.cfg ]; then + tomove="$tomove syslinux.cfg" + # update syslinux.cfg unless device is on usb bus + # this is so we can boot from CF's and harddisk + if ! on_usb_bus $parent_dev; then + [ -n "$verbose" ] && echo "Updating syslinux.cfg to use $dest" + sed -i -e "s/usbdisk/${dest##*/}/g" \ + "$destdir"/.new/syslinux.cfg + fi +fi + +# move current files to .old +for i in $tomove; do + if [ -e "$destdir"/$i ]; then + mv "$destdir"/$i "$destdir"/.old/ || die "Failed to move $destdir/$i to $destdir/.old/" + fi +done + +# move .new to current +for i in $tomove; do + mv "$destdir"/.new/$i "$destdir"/ || die "Failed to move $destdir/.new/ to $destdir" +done + +# cleanup +[ -z "$keep_old" ] && rm -rf "$destdir"/.old "$destdir"/.new +sync + + +# If we only copy then we are done. +if [ -n "$upgrade" ] && [ -z "$syslinux" ]; then + cleanup + exit 0 +fi + +echo "Making $dest bootable..." + +if ! [ -x "$(which syslinux)" ]; then + apk add -q syslinux || die "Failed to install syslinux" + uninstalls="syslinux" +fi + +syslinux $dest + +if [ -b $parent_dev ]; then + dd if=/usr/share/syslinux/mbr.bin of=$parent_dev +else + echo "Warning: Could not find the parent device for $dest" +fi + +cleanup +sync diff --git a/setup-disk.in b/setup-disk.in index 1e8e758..96e8e99 100644 --- a/setup-disk.in +++ b/setup-disk.in @@ -419,7 +419,7 @@ while getopts "hk:o:r" opt; do *) usage;; esac done -shift $(( OPTIND - 1)) +shift $(( $OPTIND - 1)) if [ -d "$1" ]; then # install to given mounted root diff --git a/setup-interfaces.in b/setup-interfaces.in index cfb4ad0..df8f231 100755 --- a/setup-interfaces.in +++ b/setup-interfaces.in @@ -20,7 +20,7 @@ get_default_addr() { echo dhcp else ip addr show $1 | awk '/inet / {print $2}' | head -n 1 | sed 's:/.*::' - fi + fi } get_default_mask() { @@ -43,6 +43,7 @@ config_iface() { local gateway while invalid_ip $address ; do address=`get_default_addr $iface` + [ -z "$address" ] && address="dhcp" echon "Ip address for $iface? (or 'dhcp') [$address] " default_read address $address [ "$address" = "abort" ] && return @@ -112,9 +113,9 @@ for i in *.conf ; do echo "auto $iface" >> interfaces echo "iface $iface inet $type" >> interfaces [ "$type" = "static" ] || continue - echo " address $address" >> interfaces - echo " netmask $netmask" >> interfaces - [ "$gateway" ] && echo " gateway $gateway" >> interfaces + echo -e "\taddress $address" >> interfaces + echo -e "\tnetmask $netmask" >> interfaces + [ "$gateway" ] && echo -e "\tgateway $gateway" >> interfaces done while [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; do diff --git a/setup-problem-reporting b/setup-problem-reporting deleted file mode 100755 index 0b24a30..0000000 --- a/setup-problem-reporting +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -PREFIX= -. "$PREFIX/lib/libalpine.sh" - -conf="$ROOT/etc/gnats/send-pr.conf" - -cfgval() { - awk -F= "/^$1/ {print \$2}" "$ROOT/etc/ssmtp/ssmtp.conf" 2>/dev/null -} - -email=$(awk -F= '/^FROM/ {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 ^FROM "$conf" > /dev/null ; then - sed -i "s/FROM.*/FROM=$email/" "$conf" -else - echo "FROM=$email" >> "$conf" -fi - -setup-mta - -echo "" -echo "Please run 'send-pr' to submit problem reports" - diff --git a/setup-sendbug.in b/setup-sendbug.in deleted file mode 100755 index 9ce94d8..0000000 --- a/setup-sendbug.in +++ /dev/null @@ -1,41 +0,0 @@ -#!/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" - |