home: hub: mkinitfs

Download patch

ref: b287c9457c80c3dfa0d0ee5616f2f72058df7519
parent: e38a53c61d4d4abceffcae9bc5b47be8aaec3b16
author: Natanael Copa <ncopa@alpinelinux.org>
date: Wed Apr 29 09:27:16 CDT 2009

generate version string in scripts

--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,6 @@
 
-VERSION		:= $(shell awk -F= '$$1=="VERSION" {print($$2)}' mkinitfs)
+VERSION		:= 1.1
 
-
 SBIN_FILES	:= mkinitfs bootchartd
 SHARE_FILES	:= initramfs-init
 CONF_FILES	:= mkinitfs.conf \
@@ -16,22 +15,42 @@
 		files.d/bootchart \
 		files.d/base
 
-DISTFILES	:= $(SBIN_FILES) $(CONF_FILES) $(SHARE_FILES) Makefile
+SCRIPTS		:= $(SBIN_FILES) $(SHARE_FILES)
+IN_FILES	:= $(addsuffix .in,$(SCRIPTS))
 
+GIT_REV := $(shell git describe || echo exported)
+ifneq ($(GIT_REV), exported)
+FULL_VERSION    := $(patsubst $(PACKAGE)-%,%,$(GIT_REV))
+FULL_VERSION    := $(patsubst v%,%,$(FULL_VERSION))
+else
+FULL_VERSION    := $(VERSION)
+endif
+
+
+DISTFILES	:= $(IN_FILES) $(CONF_FILES) Makefile
+
 INSTALL		:= install
+SED		:= sed
+SED_REPLACE	:= -e 's:@VERSION@:$(FULL_VERSION):g'
 
+
+all:	$(SCRIPTS)
 help:
 	@echo mkinitfs $(VERSION)
 	@echo "usage: make install [DESTDIR=]"
 
-install:
+.SUFFIXES:	.in
+.in:
+	${SED} ${SED_REPLACE} ${SED_EXTRA} $< > $@
+
+install: $(SBIN_FILES) $(SHARE_FILES) $(CONF_FILES)
 	for i in $(SBIN_FILES); do \
-		$(INSTALL) -Dm755 $$i $(DESTDIR)/sbin/$$i || exit 1;\
+		$(INSTALL) -Dm755 $$i $(DESTDIR)/sbin/$$i;\
 	done
 	for i in $(CONF_FILES); do \
-		$(INSTALL) -Dm644 $$i $(DESTDIR)/etc/mkinitfs/$$i || exit 1;\
+		$(INSTALL) -Dm644 $$i $(DESTDIR)/etc/mkinitfs/$$i;\
 	done
 	for i in $(SHARE_FILES); do \
-		$(INSTALL) -D $$i $(DESTDIR)/usr/share/mkinitfs/$$i || exit 1;\
+		$(INSTALL) -D $$i $(DESTDIR)/usr/share/mkinitfs/$$i;\
 	done
 
--- a/bootchartd
+++ /dev/null
@@ -1,198 +1,0 @@
-#!/bin/sh
-#
-# Bootchart logger script
-# Ziga Mahkovec  <ziga.mahkovec@klika.si>
-#
-# Modified heavily for Alpine Linux bootcharting
-# Timo Teras <timo.teras@iki.fi>
-#
-# This script is used for data collection for the bootchart
-# boot performance visualization tool (http://www.bootchart.org).
-#
-# This script is tied to Alpine Init scripts and charts the
-# bootup procedure only.
-#
-
-PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
-
-# Configuration for bootchartd, the bootchart logger script.
-TMPFS_SIZE=32m
-SAMPLE_PERIOD=0.2
-PROCESS_ACCOUNTING="yes"
-BOOTLOG_DEST=/var/log/bootchart.tgz
-LOGDIR=/bootchart
-EXIT_PROC="mingetty agetty rungetty getty fgetty"
-
-# Monitoring commands
-log_cmd_1="cat /proc/stat"
-log_target_1=proc_stat.log
-
-# /proc/diskstats is available in 2.6 kernels
-log_cmd_2="cat /proc/diskstats"
-log_target_2=proc_diskstats.log
-
-log_cmd_3="cat /proc/[1-9]*/stat 2>/dev/null"
-log_target_3=proc_ps.log
-
-# Uncomment this line for diskless stations
-#log_cmd_4="cat /proc/net/dev"
-#log_target_4=proc_netdev.log
-
-max_log=3
-
-do_logging()
-{
-	# Enable process accounting if configured
-	if [ "$PROCESS_ACCOUNTING" = "yes" ]; then
-		[ -e kernel_pacct ] || : > kernel_pacct
-		accton kernel_pacct
-	fi
-
-	# open file descriptors
-	i=1
-	while [ $i -le $max_log ]; do
-		eval target=\"\$log_target_$i\"
-		if [ -z "$target" ]; then
-			max_log=$i
-			break
-		fi
-
-		fd=$((2 + $i))
-		eval exec $fd'>>$target'
-		eval log_fd_$i=$fd
-		i=$(($i + 1))
-	done
-
-	not_stop_logging=true
-	while $not_stop_logging && \
-	{ ! pidof $EXIT_PROC >/dev/null; }; do
-		if [ -r /proc/uptime ]; then
-			# Write the time (in jiffies).
-			read uptime < /proc/uptime
-			uptime=${uptime%% [0-9]*}
-			uptime=${uptime%.*}${uptime#*.}
-
-			i=1
-			while [ $i -le $max_log ]; do
-				eval fd=\$log_fd_$i\; cmd=\$log_cmd_$i
-
-				{
-					echo $uptime
-					# Log the command output
-					eval $cmd
-					echo
-				} >&$fd
-				i=$(($i + 1))
-			done
-		fi
-
-		sleep $SAMPLE_PERIOD
-	done
-
-	# close file descriptors
-	i=1
-	while [ $i -le $max_log ]; do
-		eval fd=\$log_fd_$i
-		eval exec $fd'>&-'
-		i=$(($i + 1))
-	done
-
-	[ -e kernel_pacct ] && accton
-}
-
-# Stop the boot logger.  The lock file is removed to force the loggers in
-# background to exit.  Some final log files are created and then all log files
-# from the tmpfs are packaged and stored in $BOOTLOG_DEST.
-finalize()
-{
-	# Stop process accounting if configured
-	local pacct=
-	[ -e kernel_pacct ] && pacct=kernel_pacct
-
-	# Write system information
-	# Log some basic information about the system.
-	(
-		echo "version = $VERSION"
-		echo "title = Boot chart for $( hostname | sed q ) ($( date ))"
-		echo "system.uname = $( uname -srvm | sed q )"
-		if [ -f /etc/alpine-release ]; then
-			echo "system.release = $( sed q /etc/alpine-release )"
-		elif [ -f /etc/gentoo-release ]; then
-			echo "system.release = $( sed q /etc/gentoo-release )"
-		elif [ -f /etc/SuSE-release ]; then
-			echo "system.release = $( sed q /etc/SuSE-release )"
-		elif [ -f /etc/debian_version ]; then
-			echo "system.release = Debian GNU/$( uname -s ) $( cat /etc/debian_version )"
-		elif [ -f /etc/frugalware-release ]; then
-			echo "system.release = $( sed q /etc/frugalware-release )"
-		elif [ -f /etc/pardus-release ]; then
-			echo "system.release = $( sed q /etc/pardus-release )"
-		else
-			echo "system.release = $( sed 's/\\.//g;q' /etc/issue )"
-		fi
-
-		# Get CPU count
-		local cpucount=$(grep -c '^processor' /proc/cpuinfo)
-		if [ $cpucount -gt 1 -a -n "$(grep 'sibling.*2' /proc/cpuinfo)" ]; then
-			# Hyper-Threading enabled
-			cpucount=$(( $cpucount / 2 ))
-		fi
-		if grep -q '^model name' /proc/cpuinfo; then
-			echo "system.cpu = $( grep '^model name' /proc/cpuinfo | sed q )"\
-			     "($cpucount)"
-		else
-			echo "system.cpu = $( grep '^cpu' /proc/cpuinfo | sed q )"\
-			     "($cpucount)"
-		fi
-
-		echo "system.kernel.options = $( sed q /proc/cmdline )"
-	) >> header
-
-	# Package log files
-	tar -zcf "$BOOTLOG_DEST" header $pacct *.log
-	rm "$LOGDIR"/*
-	rmdir "$LOGDIR"
-}
-
-case "$1" in
-start-initfs)
-	NEWROOT="$2"
-	(
-		cleanup=true
-		trap "not_stop_logging=false" USR1
-		trap "cleanup=false; not_stop_logging=false" USR2
-
-		mkdir "$LOGDIR"
-		cd "$LOGDIR"
-		do_logging
-		if $cleanup; then
-			sleep $SAMPLE_PERIOD
-			finalize
-		fi
-	) &
-	echo $! > $LOGDIR/bootchart.pid
-	;;
-stop-initfs)
-	NEWROOT="$2"
-
-	cd "$LOGDIR"
-	mkdir "$NEWROOT$LOGDIR"
-	cp /sbin/bootchartd $NEWROOT/sbin
-	PID=`cat bootchart.pid`
-	kill -USR2 $PID
-	wait $PID
-	mv * "$NEWROOT$LOGDIR"
-	;;
-start-rootfs)
-	(
-		trap "not_stop_logging=false" USR1
-		cd "$LOGDIR"
-		do_logging
-		finalize
-	) &
-	shift
-	exec "$@"
-	;;
-esac
-
-exit 0
--- /dev/null
+++ b/bootchartd.in
@@ -1,0 +1,199 @@
+#!/bin/sh
+#
+# Bootchart logger script
+# Ziga Mahkovec  <ziga.mahkovec@klika.si>
+#
+# Modified heavily for Alpine Linux bootcharting
+# Timo Teras <timo.teras@iki.fi>
+#
+# This script is used for data collection for the bootchart
+# boot performance visualization tool (http://www.bootchart.org).
+#
+# This script is tied to Alpine Init scripts and charts the
+# bootup procedure only.
+#
+
+VERSION=@VERSION@
+PATH="/sbin:/bin:/usr/sbin:/usr/bin:$PATH"
+
+# Configuration for bootchartd, the bootchart logger script.
+TMPFS_SIZE=32m
+SAMPLE_PERIOD=0.2
+PROCESS_ACCOUNTING="yes"
+BOOTLOG_DEST=/var/log/bootchart.tgz
+LOGDIR=/bootchart
+EXIT_PROC="mingetty agetty rungetty getty fgetty"
+
+# Monitoring commands
+log_cmd_1="cat /proc/stat"
+log_target_1=proc_stat.log
+
+# /proc/diskstats is available in 2.6 kernels
+log_cmd_2="cat /proc/diskstats"
+log_target_2=proc_diskstats.log
+
+log_cmd_3="cat /proc/[1-9]*/stat 2>/dev/null"
+log_target_3=proc_ps.log
+
+# Uncomment this line for diskless stations
+#log_cmd_4="cat /proc/net/dev"
+#log_target_4=proc_netdev.log
+
+max_log=3
+
+do_logging()
+{
+	# Enable process accounting if configured
+	if [ "$PROCESS_ACCOUNTING" = "yes" ]; then
+		[ -e kernel_pacct ] || : > kernel_pacct
+		accton kernel_pacct
+	fi
+
+	# open file descriptors
+	i=1
+	while [ $i -le $max_log ]; do
+		eval target=\"\$log_target_$i\"
+		if [ -z "$target" ]; then
+			max_log=$i
+			break
+		fi
+
+		fd=$((2 + $i))
+		eval exec $fd'>>$target'
+		eval log_fd_$i=$fd
+		i=$(($i + 1))
+	done
+
+	not_stop_logging=true
+	while $not_stop_logging && \
+	{ ! pidof $EXIT_PROC >/dev/null; }; do
+		if [ -r /proc/uptime ]; then
+			# Write the time (in jiffies).
+			read uptime < /proc/uptime
+			uptime=${uptime%% [0-9]*}
+			uptime=${uptime%.*}${uptime#*.}
+
+			i=1
+			while [ $i -le $max_log ]; do
+				eval fd=\$log_fd_$i\; cmd=\$log_cmd_$i
+
+				{
+					echo $uptime
+					# Log the command output
+					eval $cmd
+					echo
+				} >&$fd
+				i=$(($i + 1))
+			done
+		fi
+
+		sleep $SAMPLE_PERIOD
+	done
+
+	# close file descriptors
+	i=1
+	while [ $i -le $max_log ]; do
+		eval fd=\$log_fd_$i
+		eval exec $fd'>&-'
+		i=$(($i + 1))
+	done
+
+	[ -e kernel_pacct ] && accton
+}
+
+# Stop the boot logger.  The lock file is removed to force the loggers in
+# background to exit.  Some final log files are created and then all log files
+# from the tmpfs are packaged and stored in $BOOTLOG_DEST.
+finalize()
+{
+	# Stop process accounting if configured
+	local pacct=
+	[ -e kernel_pacct ] && pacct=kernel_pacct
+
+	# Write system information
+	# Log some basic information about the system.
+	(
+		echo "version = $VERSION"
+		echo "title = Boot chart for $( hostname | sed q ) ($( date ))"
+		echo "system.uname = $( uname -srvm | sed q )"
+		if [ -f /etc/alpine-release ]; then
+			echo "system.release = $( sed q /etc/alpine-release )"
+		elif [ -f /etc/gentoo-release ]; then
+			echo "system.release = $( sed q /etc/gentoo-release )"
+		elif [ -f /etc/SuSE-release ]; then
+			echo "system.release = $( sed q /etc/SuSE-release )"
+		elif [ -f /etc/debian_version ]; then
+			echo "system.release = Debian GNU/$( uname -s ) $( cat /etc/debian_version )"
+		elif [ -f /etc/frugalware-release ]; then
+			echo "system.release = $( sed q /etc/frugalware-release )"
+		elif [ -f /etc/pardus-release ]; then
+			echo "system.release = $( sed q /etc/pardus-release )"
+		else
+			echo "system.release = $( sed 's/\\.//g;q' /etc/issue )"
+		fi
+
+		# Get CPU count
+		local cpucount=$(grep -c '^processor' /proc/cpuinfo)
+		if [ $cpucount -gt 1 -a -n "$(grep 'sibling.*2' /proc/cpuinfo)" ]; then
+			# Hyper-Threading enabled
+			cpucount=$(( $cpucount / 2 ))
+		fi
+		if grep -q '^model name' /proc/cpuinfo; then
+			echo "system.cpu = $( grep '^model name' /proc/cpuinfo | sed q )"\
+			     "($cpucount)"
+		else
+			echo "system.cpu = $( grep '^cpu' /proc/cpuinfo | sed q )"\
+			     "($cpucount)"
+		fi
+
+		echo "system.kernel.options = $( sed q /proc/cmdline )"
+	) >> header
+
+	# Package log files
+	tar -zcf "$BOOTLOG_DEST" header $pacct *.log
+	rm "$LOGDIR"/*
+	rmdir "$LOGDIR"
+}
+
+case "$1" in
+start-initfs)
+	NEWROOT="$2"
+	(
+		cleanup=true
+		trap "not_stop_logging=false" USR1
+		trap "cleanup=false; not_stop_logging=false" USR2
+
+		mkdir "$LOGDIR"
+		cd "$LOGDIR"
+		do_logging
+		if $cleanup; then
+			sleep $SAMPLE_PERIOD
+			finalize
+		fi
+	) &
+	echo $! > $LOGDIR/bootchart.pid
+	;;
+stop-initfs)
+	NEWROOT="$2"
+
+	cd "$LOGDIR"
+	mkdir "$NEWROOT$LOGDIR"
+	cp /sbin/bootchartd $NEWROOT/sbin
+	PID=`cat bootchart.pid`
+	kill -USR2 $PID
+	wait $PID
+	mv * "$NEWROOT$LOGDIR"
+	;;
+start-rootfs)
+	(
+		trap "not_stop_logging=false" USR1
+		cd "$LOGDIR"
+		do_logging
+		finalize
+	) &
+	shift
+	exec "$@"
+	;;
+esac
+
+exit 0
--- a/initramfs-init
+++ /dev/null
@@ -1,308 +1,0 @@
-#!/bin/busybox sh
-
-# this is the init script version
-VERSION=1.1
-NEWROOT=/newroot
-SINGLEMODE=no
-
-/bin/busybox --install -s
-
-# basic environment
-export PATH=/usr/bin:/bin:/usr/sbin:/sbin
-
-# needed devs
-[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
-
-# basic mounts
-mount -t proc -o noexec,nosuid,nodev proc /proc
-mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
-
-# some helpers
-ebegin() {
-	echo -n " * $*: "
-}
-eend() {
-	local msg
-	if [ "$1" = 0 ] || [ $# -lt 1 ] ; then
-		echo "ok."
-	else
-		shift
-		echo "failed. $*"
-		echo "initramfs emergency recovery shell launched. Type 'exit' to continue boot"
-		/bin/busybox sh
-	fi
-}
-
-scan_drivers() {
-	if [ "$AUTODETECT" != no ] ; then
-		find /sys -name modalias | xargs sort -u | xargs modprobe -a 2> /dev/null
-	fi
-}
-
-find_ovl() {
-	local mnt="$1"
-	local ovl
-	local lines
-
-	# look for apkovl's on mounted media
-	ovl=$( ls -1 "$mnt"/*.apkovl.tar.gz* 2>/dev/null ) || return 1
-	lines=$(echo "$ovl" | wc -l)
-
-	if [ $lines -gt 1 ] ; then
-		echo "ERROR: More than one apkovl file was found on $(basename $mnt). None will be read." >&2
-		return 1
-	fi
-	echo "$ovl"
-}
-
-retry_mount() {
-	# usb might need some time to settle so we retry a few times
-	for i in $(seq 0 19); do
-		mount $@ 2>&1 && return 0
-		sleep 1
-	done
-	return 1
-}
-
-unpack_apkovl() {
-	local ovl="$1"
-	local dest="$2"
-	local suffix=${ovl##*.}
-	local i
-	if [ "$suffix" = "gz" ]; then
-		tar -C "$dest" -zxf "$ovl"
-		return $?
-	fi
-
-	for i in $ALPINE_MNT/*/*/openssl-[0-9]*.apk $ALPINE_MNT/*/openssl-[0-9]*.apk; do
-		[ -f "$i" ] && tar --numeric-owner -C / -zxf $i && break
-	done
-
-	if ! openssl list-cipher-commands | grep "^$suffix$" > /dev/null; then
-		errstr="Cipher $suffix is not supported"
-		return 1
-	fi
-	local count=0
-	# beep
-	echo -e "\007"
-	while [ $count -lt 3 ]; do
-		openssl enc -d -$suffix -in "$ovl" | tar --numeric-owner \
-			-C "$dest" -zx 2>/dev/null && return 0
-		count=$(( $count + 1 ))
-	done
-	return 1
-}
-
-# gotta start from somewhere :)
-echo "Alpine Init $VERSION"
-
-# read the kernel options
-for i in `cat /proc/cmdline` ; do
-	case $i in
-		s|single|1)
-			SINGLEMODE=yes ;;
-		modules=*)
-			MODULES="`echo ${i#modules=} | tr ',' ' '`";;
-		noautodetect)
-			AUTODETECT=no;;
-		*=*)    eval KOPT_$i ;;
-		*)      eval KOPT_$i=yes ;;
-	esac
-done
-
-# start bootcharting if wanted
-if [ -n "$KOPT_chart" ]; then
-	ebegin "Starting bootchart logging"
-	/sbin/bootchartd start-initfs "$NEWROOT"
-	eend 0
-fi
-
-ALPINE_DEV=${KOPT_alpine_dev%%:*}
-ALPINE_DEV_FS=${KOPT_alpine_dev##*:}
-if [ "$ALPINE_DEV_FS" = "$ALPINE_DEV" ]; then
-	unset ALPINE_DEV_FS
-fi
-ALPINE_MNT=/media/$ALPINE_DEV
-
-# hide kernel messages
-dmesg -n 1
-
-# setup /dev
-ebegin "Starting mdev"
-mount -t tmpfs -o exec,nosuid,mode=0755 mdev /dev
-ln -s sr0 /dev/cdrom
-echo "/sbin/mdev" > /proc/sys/kernel/hotplug
-mdev -s
-RC=$?
-[ -d /dev/pts ] || mkdir -m 755 /dev/pts
-[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
-mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
-[ -d /dev/shm ] || mkdir /dev/shm
-mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
-eend $RC
-
-# load available drivers to get access to modloop media
-ebegin "Loading boot drivers"
-[ "$MODULES" ] && modprobe -a $MODULES 2> /dev/null
-if [ -f /etc/modules ] ; then
-	sed 's/\#.*//g' < /etc/modules |
-	while read module args; do
-		modprobe -q $module $args
-	done
-fi
-scan_drivers
-scan_drivers
-eend 0
-
-# check if root=... was set
-if [ -n "$KOPT_root" ]; then
-	if [ "$SINGLEMODE" = "yes" ]; then
-		echo "Entering single mode. Type 'exit' to continue booting."
-		sh
-	fi
-	case "$KOPT_root" in
-		/dev/md*) 
-			mknod $KOPT_root b 9 ${KOPT_root#/dev/md}
-			raidautorun "$KOPT_root"
-			;;
-	esac
-	ebegin "Mounting root"
-	retry_mount $KOPT_root $NEWROOT 2>/dev/null
-	eend $?
-	cat /proc/mounts | while read DEV DIR TYPE OPTS ; do
-		if [ "$DIR" != "/" -a "$DIR" != "$NEWROOT" -a -d "$DIR" ]; then
-			mkdir -p $NEWROOT/$DIR
-			mount -o move $DIR $NEWROOT/$DIR
-		fi
-	done
-	sync
-	exec /bin/busybox switch_root $NEWROOT $chart_init /sbin/init $KOPT_init_args
-	echo "initramfs emergency recovery shell launched"
-	exec /bin/busybox sh
-fi
-
-# locate boot media and mount it
-ebegin "Mounting boot media"
-mkdir -p $ALPINE_MNT
-if [ -n "$ALPINE_DEV_FS" ]; then
-	mount_opts="-t $ALPINE_DEV_FS"
-fi
-
-retry_mount $mount_opts /dev/$ALPINE_DEV $ALPINE_MNT >/dev/null 2>&1
-eend $?
-
-ebegin "Mounting loopback device for kernel modules"
-modprobe loop
-if [ -n "$KOPT_modloop" ]; then
-	modloop=$KOPT_modloop
-else
-	modloop=$KOPT_BOOT_IMAGE.cmg
-fi
-mount -o loop,ro -t cramfs $ALPINE_MNT/$modloop /.modloop
-rc=$?
-if [ "$rc" = 0 ]; then
-	rm -rf /lib/modules
-	ln -sf /.modloop/modules /lib
-fi
-eend $?
-
-if [ -d $ALPINE_MNT/firmware ]; then
-	ebegin "Copying firmware from $ALPINE_MNT/firmware"
-	mkdir -p /lib
-	cp -R -a $ALPINE_MNT/firmware /lib/
-	eend $?
-fi
-
-mkdir -p /etc/apk
-for i in $ALPINE_MNT/*/APK_INDEX.gz $ALPINE_MNT/*/*/APK_INDEX.gz; do
-	[ -r "$i" ] && echo ${i%/APK_INDEX.gz} >> /etc/apk/repositories
-done
-
-# early console?
-if [ "$SINGLEMODE" = "yes" ]; then
-	echo "Entering single mode. Type 'exit' to continue booting."
-	sh
-fi
-
-# more drivers
-ebegin "Loading hardware drivers"
-scan_drivers
-eend 0
-
-mount -t tmpfs tmpfs $NEWROOT
-
-# look for apkovl
-if dmesg | grep '^usb-storage: waiting' >/dev/null; then
-	ebegin "Waiting for USB device to settle"
-	while ! dmesg | grep 'usb-storage: device scan complete' >/dev/null; do
-		sleep 1
-	done
-	eend 0
-fi
-for i in usb floppy cdrom; do
-	mount /media/$i 2>/dev/null || continue
-	ovl=$(find_ovl /media/$i)
-	[ -f "$ovl" ] && break
-	umount /media/$i 2>/dev/null
-done
-if ! [ -f "$ovl" ]; then
-	ovl=$(find_ovl $ALPINE_MNT)
-fi
-
-if [ -f "$ovl" ]; then
-	ebegin "Loading user settings from $ovl"
-	unpack_apkovl "$ovl" $NEWROOT
-	eend $? $errstr
-	umount /media/$i 2>/dev/null &
-	pkgs=$(sed 's/\#.*//' $NEWROOT/etc/lbu/packages.list 2>/dev/null)
-fi
-
-# hack so we get openrc
-pkgs="$pkgs openrc"
-
-# install new root
-ebegin "Installing packages to root filesystem"
-if [ -n "$KOPT_chart" ]; then
-	pkgs="$pkgs acct"
-fi
-apkflags="--initdb --quiet --progress --force"
-if [ -z "$KOPT_keep_apk_new" ]; then
-	apkflags="$apkflags --clean-protected"
-fi
-apk add --root /newroot $apkflags $pkgs >/dev/null
-eend $?
-
-# copy alpine release info
-cp $ALPINE_MNT/.alpine-release $NEWROOT/
-ln -sf /.alpine-release $NEWROOT/etc/alpine-release
-
-# if there is no repositories file, then use the default
-if ! [ -f $NEWROOT/etc/apk/repositories ]; then
-	cp /etc/apk/repositories $NEWROOT/etc/apk/repositories
-fi
-
-# setup bootchart for switch_root
-chart_init=""
-if [ -n "$KOPT_chart" ]; then
-	/sbin/bootchartd stop-initfs "$NEWROOT"
-	chart_init="/sbin/bootchartd start-rootfs"
-fi
-
-# switch over to new root
-cat /proc/mounts | while read DEV DIR TYPE OPTS ; do
-	if [ "$DIR" != "/" -a "$DIR" != "$NEWROOT" -a -d "$DIR" ]; then
-		mkdir -p $NEWROOT/$DIR
-		mount -o move $DIR $NEWROOT/$DIR
-	fi
-done
-ln -sf /.modloop/modules $NEWROOT/lib/modules
-sync
-
-echo ""
-if [ -x $NEWROOT/sbin/init ]; then
-	exec /bin/busybox switch_root $NEWROOT $chart_init /sbin/init $KOPT_init_args
-fi
-
-echo "initramfs emergency recovery shell launched"
-exec /bin/busybox sh
-reboot
--- /dev/null
+++ b/initramfs-init.in
@@ -1,0 +1,308 @@
+#!/bin/sh
+
+# this is the init script version
+VERSION=@VERSION@
+NEWROOT=/newroot
+SINGLEMODE=no
+
+/bin/busybox --install -s
+
+# basic environment
+export PATH=/usr/bin:/bin:/usr/sbin:/sbin
+
+# needed devs
+[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3
+
+# basic mounts
+mount -t proc -o noexec,nosuid,nodev proc /proc
+mount -t sysfs -o noexec,nosuid,nodev sysfs /sys
+
+# some helpers
+ebegin() {
+	echo -n " * $*: "
+}
+eend() {
+	local msg
+	if [ "$1" = 0 ] || [ $# -lt 1 ] ; then
+		echo "ok."
+	else
+		shift
+		echo "failed. $*"
+		echo "initramfs emergency recovery shell launched. Type 'exit' to continue boot"
+		/bin/busybox sh
+	fi
+}
+
+scan_drivers() {
+	if [ "$AUTODETECT" != no ] ; then
+		find /sys -name modalias | xargs sort -u | xargs modprobe -a 2> /dev/null
+	fi
+}
+
+find_ovl() {
+	local mnt="$1"
+	local ovl
+	local lines
+
+	# look for apkovl's on mounted media
+	ovl=$( ls -1 "$mnt"/*.apkovl.tar.gz* 2>/dev/null ) || return 1
+	lines=$(echo "$ovl" | wc -l)
+
+	if [ $lines -gt 1 ] ; then
+		echo "ERROR: More than one apkovl file was found on $(basename $mnt). None will be read." >&2
+		return 1
+	fi
+	echo "$ovl"
+}
+
+retry_mount() {
+	# usb might need some time to settle so we retry a few times
+	for i in $(seq 0 19); do
+		mount $@ 2>&1 && return 0
+		sleep 1
+	done
+	return 1
+}
+
+unpack_apkovl() {
+	local ovl="$1"
+	local dest="$2"
+	local suffix=${ovl##*.}
+	local i
+	if [ "$suffix" = "gz" ]; then
+		tar -C "$dest" -zxf "$ovl"
+		return $?
+	fi
+
+	for i in $ALPINE_MNT/*/*/openssl-[0-9]*.apk $ALPINE_MNT/*/openssl-[0-9]*.apk; do
+		[ -f "$i" ] && tar --numeric-owner -C / -zxf $i && break
+	done
+
+	if ! openssl list-cipher-commands | grep "^$suffix$" > /dev/null; then
+		errstr="Cipher $suffix is not supported"
+		return 1
+	fi
+	local count=0
+	# beep
+	echo -e "\007"
+	while [ $count -lt 3 ]; do
+		openssl enc -d -$suffix -in "$ovl" | tar --numeric-owner \
+			-C "$dest" -zx 2>/dev/null && return 0
+		count=$(( $count + 1 ))
+	done
+	return 1
+}
+
+# gotta start from somewhere :)
+echo "Alpine Init $VERSION"
+
+# read the kernel options
+for i in `cat /proc/cmdline` ; do
+	case $i in
+		s|single|1)
+			SINGLEMODE=yes ;;
+		modules=*)
+			MODULES="`echo ${i#modules=} | tr ',' ' '`";;
+		noautodetect)
+			AUTODETECT=no;;
+		*=*)    eval KOPT_$i ;;
+		*)      eval KOPT_$i=yes ;;
+	esac
+done
+
+# start bootcharting if wanted
+if [ -n "$KOPT_chart" ]; then
+	ebegin "Starting bootchart logging"
+	/sbin/bootchartd start-initfs "$NEWROOT"
+	eend 0
+fi
+
+ALPINE_DEV=${KOPT_alpine_dev%%:*}
+ALPINE_DEV_FS=${KOPT_alpine_dev##*:}
+if [ "$ALPINE_DEV_FS" = "$ALPINE_DEV" ]; then
+	unset ALPINE_DEV_FS
+fi
+ALPINE_MNT=/media/$ALPINE_DEV
+
+# hide kernel messages
+dmesg -n 1
+
+# setup /dev
+ebegin "Starting mdev"
+mount -t tmpfs -o exec,nosuid,mode=0755 mdev /dev
+ln -s sr0 /dev/cdrom
+echo "/sbin/mdev" > /proc/sys/kernel/hotplug
+mdev -s
+RC=$?
+[ -d /dev/pts ] || mkdir -m 755 /dev/pts
+[ -c /dev/ptmx ] || mknod -m 666 /dev/ptmx c 5 2
+mount -t devpts -o gid=5,mode=0620,noexec,nosuid devpts /dev/pts
+[ -d /dev/shm ] || mkdir /dev/shm
+mount -t tmpfs -o nodev,nosuid,noexec shm /dev/shm
+eend $RC
+
+# load available drivers to get access to modloop media
+ebegin "Loading boot drivers"
+[ "$MODULES" ] && modprobe -a $MODULES 2> /dev/null
+if [ -f /etc/modules ] ; then
+	sed 's/\#.*//g' < /etc/modules |
+	while read module args; do
+		modprobe -q $module $args
+	done
+fi
+scan_drivers
+scan_drivers
+eend 0
+
+# check if root=... was set
+if [ -n "$KOPT_root" ]; then
+	if [ "$SINGLEMODE" = "yes" ]; then
+		echo "Entering single mode. Type 'exit' to continue booting."
+		sh
+	fi
+	case "$KOPT_root" in
+		/dev/md*) 
+			mknod $KOPT_root b 9 ${KOPT_root#/dev/md}
+			raidautorun "$KOPT_root"
+			;;
+	esac
+	ebegin "Mounting root"
+	retry_mount $KOPT_root $NEWROOT 2>/dev/null
+	eend $?
+	cat /proc/mounts | while read DEV DIR TYPE OPTS ; do
+		if [ "$DIR" != "/" -a "$DIR" != "$NEWROOT" -a -d "$DIR" ]; then
+			mkdir -p $NEWROOT/$DIR
+			mount -o move $DIR $NEWROOT/$DIR
+		fi
+	done
+	sync
+	exec /bin/busybox switch_root $NEWROOT $chart_init /sbin/init $KOPT_init_args
+	echo "initramfs emergency recovery shell launched"
+	exec /bin/busybox sh
+fi
+
+# locate boot media and mount it
+ebegin "Mounting boot media"
+mkdir -p $ALPINE_MNT
+if [ -n "$ALPINE_DEV_FS" ]; then
+	mount_opts="-t $ALPINE_DEV_FS"
+fi
+
+retry_mount $mount_opts /dev/$ALPINE_DEV $ALPINE_MNT >/dev/null 2>&1
+eend $?
+
+ebegin "Mounting loopback device for kernel modules"
+modprobe loop
+if [ -n "$KOPT_modloop" ]; then
+	modloop=$KOPT_modloop
+else
+	modloop=$KOPT_BOOT_IMAGE.cmg
+fi
+mount -o loop,ro -t cramfs $ALPINE_MNT/$modloop /.modloop
+rc=$?
+if [ "$rc" = 0 ]; then
+	rm -rf /lib/modules
+	ln -sf /.modloop/modules /lib
+fi
+eend $?
+
+if [ -d $ALPINE_MNT/firmware ]; then
+	ebegin "Copying firmware from $ALPINE_MNT/firmware"
+	mkdir -p /lib
+	cp -R -a $ALPINE_MNT/firmware /lib/
+	eend $?
+fi
+
+mkdir -p /etc/apk
+for i in $ALPINE_MNT/*/APK_INDEX.gz $ALPINE_MNT/*/*/APK_INDEX.gz; do
+	[ -r "$i" ] && echo ${i%/APK_INDEX.gz} >> /etc/apk/repositories
+done
+
+# early console?
+if [ "$SINGLEMODE" = "yes" ]; then
+	echo "Entering single mode. Type 'exit' to continue booting."
+	sh
+fi
+
+# more drivers
+ebegin "Loading hardware drivers"
+scan_drivers
+eend 0
+
+mount -t tmpfs tmpfs $NEWROOT
+
+# look for apkovl
+if dmesg | grep '^usb-storage: waiting' >/dev/null; then
+	ebegin "Waiting for USB device to settle"
+	while ! dmesg | grep 'usb-storage: device scan complete' >/dev/null; do
+		sleep 1
+	done
+	eend 0
+fi
+for i in usb floppy cdrom; do
+	mount /media/$i 2>/dev/null || continue
+	ovl=$(find_ovl /media/$i)
+	[ -f "$ovl" ] && break
+	umount /media/$i 2>/dev/null
+done
+if ! [ -f "$ovl" ]; then
+	ovl=$(find_ovl $ALPINE_MNT)
+fi
+
+if [ -f "$ovl" ]; then
+	ebegin "Loading user settings from $ovl"
+	unpack_apkovl "$ovl" $NEWROOT
+	eend $? $errstr
+	umount /media/$i 2>/dev/null &
+	pkgs=$(sed 's/\#.*//' $NEWROOT/etc/lbu/packages.list 2>/dev/null)
+fi
+
+# hack so we get openrc
+pkgs="$pkgs openrc"
+
+# install new root
+ebegin "Installing packages to root filesystem"
+if [ -n "$KOPT_chart" ]; then
+	pkgs="$pkgs acct"
+fi
+apkflags="--initdb --quiet --progress --force"
+if [ -z "$KOPT_keep_apk_new" ]; then
+	apkflags="$apkflags --clean-protected"
+fi
+apk add --root /newroot $apkflags $pkgs >/dev/null
+eend $?
+
+# copy alpine release info
+cp $ALPINE_MNT/.alpine-release $NEWROOT/
+ln -sf /.alpine-release $NEWROOT/etc/alpine-release
+
+# if there is no repositories file, then use the default
+if ! [ -f $NEWROOT/etc/apk/repositories ]; then
+	cp /etc/apk/repositories $NEWROOT/etc/apk/repositories
+fi
+
+# setup bootchart for switch_root
+chart_init=""
+if [ -n "$KOPT_chart" ]; then
+	/sbin/bootchartd stop-initfs "$NEWROOT"
+	chart_init="/sbin/bootchartd start-rootfs"
+fi
+
+# switch over to new root
+cat /proc/mounts | while read DEV DIR TYPE OPTS ; do
+	if [ "$DIR" != "/" -a "$DIR" != "$NEWROOT" -a -d "$DIR" ]; then
+		mkdir -p $NEWROOT/$DIR
+		mount -o move $DIR $NEWROOT/$DIR
+	fi
+done
+ln -sf /.modloop/modules $NEWROOT/lib/modules
+sync
+
+echo ""
+if [ -x $NEWROOT/sbin/init ]; then
+	exec /bin/busybox switch_root $NEWROOT $chart_init /sbin/init $KOPT_init_args
+fi
+
+echo "initramfs emergency recovery shell launched"
+exec /bin/busybox sh
+reboot
--- a/mkinitfs
+++ /dev/null
@@ -1,198 +1,0 @@
-#!/bin/sh
-
-VERSION=1.0
-
-_cp() {
-	local i
-	if [ -n "$list_sources" ]; then
-		for i in "$@"; do
-			echo $i
-		done
-		return
-	fi
-
-	for i in "$@"; do
-		local dest="$tmpdir"/${i%/*}
-		mkdir -p "$dest"
-		cp -flLpR "$i" "$dest" 2>/dev/null || cp -pR "$i" "$dest"
-	done
-}
-
-feature_files() {
-	local dir="$1"
-	local glob file 
-	for f in $features; do
-		if [ ! -f "$dir/$f" ]; then
-			continue
-		fi
-		for glob in $(cat "$dir/$f"); do
-			for file in $glob; do
-				echo $glob
-			done
-		done
-	done
-}
-
-initfs_base() {
-	local i= dirs= glob= file=
-	echo "==> initramfs: copying base files" >&2
-	for i in dev proc sys sbin bin .modloop lib/modules media/cdrom \
-	    media/floppy media/usb newroot; do
-		dirs="$dirs $tmpdir/$i"
-	done
-	[ -z "$list_sources" ] && mkdir -p $dirs
-
-	for file in $(feature_files "$filelists_dir"); do
-		_cp $file
-	done
-
-	# copy init
-	if [ -z "$list_sources" ]; then
-		cd $startdir
-		install -m755 "$init" "$tmpdir"/init
-	else
-		echo "$init"
-	fi
-}
-
-find_kmod_deps() {
-	awk '
-function recursedeps(k,		j) {
-	if (k in visited)
-		return;
-	visited[k] = 1;
-	split(deps[k], dep, " ");
-	for (j in dep)
-		recursedeps(dep[j]);
-	print(k);
-}
-
-BEGIN {
-	if (modulesdep == "")
-		modulesdep="modules.dep";
-	FS = ": ";
-	while ( (getline < modulesdep) > 0) {
-		deps[$1] = $2;
-	}
-}
-
-{
-	mod["/"$0] = 1;
-}
-
-END {
-	for (i in mod)
-		recursedeps(i);
-}' -v modulesdep="$basedir/lib/modules/$kernel/modules.dep"
-}
-
-initfs_kmods() {
-	local glob= file= files= dirs=
-	[ -z "$list_soruces" ] && rm -rf "$tmpdir"/lib/modules
-	cd "$kerneldir" || return 1
-	echo "==> initramfs: copying kernel $kernel modules" >&2
-	files=$(
-	for file in $(feature_files $modulelists_dir); do
-		if ! [ -e ${file} ]; then
-			echo "$file: No such file or directory" >&2
-			continue
-		fi
-		echo $file
-	done | find_kmod_deps)
-	for file in $files; do
-		_cp "$basedir"/lib/modules/$kernel/$file
-	done
-}
-
-initfs_cpio() {
-	[ -n "$list_sources" ] && return
-	echo "==> initramfs: creating $outfile" >&2
-	(cd "$tmpdir" && find . | cpio -o -H newc | gzip) > $outfile
-}
-
-usage() {
-	cat <<EOF
-usage: mkinitfs [-hkLl] [-b basedir] [-c configfile] [-f features] 
-		[-i initfile ] [-o outfile] [-t tempdir] [kernelversion]"
-options:
-	-b  prefix files and kernel modules with basedir
-	-c  use configfile instead of $config
-	-f  use specified features
-	-h  print this help
-	-i  use initfile as init instead of $init
-	-k  keep tempdir
-	-l  only list files that would have been used
-	-L  list available features
-	-o  set another outfile
-	-t  use tempdir when creating initramfs image
-
-EOF
-	exit 1
-}
-
-# main
-
-startdir=$PWD
-config=/etc/mkinitfs/mkinitfs.conf
-init=/usr/share/mkinitfs/initramfs-init
-
-while getopts "b:c:hi:kLlo:t:" opt; do
-	case "$opt" in
-		b) basedir="$OPTARG";;
-		c) config="$OPTARG";;
-		f) myfeatures="$OPTARG";;
-		h) usage;;
-		i) init=$OPTARG;;
-		k) keeptmp=1;;
-		L) list_features=1;;
-		l) list_sources=1;;
-		o) outfile="$OPTARG";;
-		t) tmpdir="$OPTARG";;
-		*) usage;;
-	esac
-done
-shift $(( $OPTIND - 1 ))
-
-. "$config"
-filelists_dir=${filelists_dir:-"/etc/mkinitfs/files.d"}
-modulelists_dir=${modules_dir:-"/etc/mkinitfs/modules.d"}
-[ -n "$myfeatures" ] && features="$myfeatures"
-
-if [ -n "$list_features" ]; then
-	for i in $filelists_dir $modulelists_dir; do
-		( [ -d "$i" ] && cd $i && ls )
-	done | sort | uniq
-	exit 0
-fi
-
-[ -n "$1" ] && kernel="$1"
-[ -z "$kernel" ] && kernel=$(uname -r)
-kerneldir="$basedir/lib/modules/$kernel"
-if [ -z "$outfile" ]; then
-	outfile="$basedir"/boot/${kernel##*-}.gz
-fi
-
-if [ ! -d "$kerneldir" ]; then
-	echo "$kerneldir does not exist or is not a directory"
-	exit 1
-fi
-
-if [ -z "$tmpdir" ]; then
-	tmpdir=$(mktemp -d /tmp/mkinitfs.XXXXXX)
-else
-	mkdir -p "$tmpdir"
-fi
-
-if [ -z "$keeptmp" ]; then
-	[ -d "$tmpdir" ] && rm -rf "$tmpdir"/*
-fi
-
-initfs_base
-initfs_kmods
-initfs_cpio
-
-# cleanup
-if [ -z "$keeptmp" ]; then
-	[ -d "$tmpdir" ] && rm -rf "$tmpdir"
-fi
-
--- /dev/null
+++ b/mkinitfs.in
@@ -1,0 +1,198 @@
+#!/bin/sh
+
+VERSION=@VERSION@
+
+_cp() {
+	local i
+	if [ -n "$list_sources" ]; then
+		for i in "$@"; do
+			echo $i
+		done
+		return
+	fi
+
+	for i in "$@"; do
+		local dest="$tmpdir"/${i%/*}
+		mkdir -p "$dest"
+		cp -flLpR "$i" "$dest" 2>/dev/null || cp -pR "$i" "$dest"
+	done
+}
+
+feature_files() {
+	local dir="$1"
+	local glob file 
+	for f in $features; do
+		if [ ! -f "$dir/$f" ]; then
+			continue
+		fi
+		for glob in $(cat "$dir/$f"); do
+			for file in $glob; do
+				echo $glob
+			done
+		done
+	done
+}
+
+initfs_base() {
+	local i= dirs= glob= file=
+	echo "==> initramfs: copying base files" >&2
+	for i in dev proc sys sbin bin .modloop lib/modules media/cdrom \
+	    media/floppy media/usb newroot; do
+		dirs="$dirs $tmpdir/$i"
+	done
+	[ -z "$list_sources" ] && mkdir -p $dirs
+
+	for file in $(feature_files "$filelists_dir"); do
+		_cp $file
+	done
+
+	# copy init
+	if [ -z "$list_sources" ]; then
+		cd $startdir
+		install -m755 "$init" "$tmpdir"/init
+	else
+		echo "$init"
+	fi
+}
+
+find_kmod_deps() {
+	awk '
+function recursedeps(k,		j) {
+	if (k in visited)
+		return;
+	visited[k] = 1;
+	split(deps[k], dep, " ");
+	for (j in dep)
+		recursedeps(dep[j]);
+	print(k);
+}
+
+BEGIN {
+	if (modulesdep == "")
+		modulesdep="modules.dep";
+	FS = ": ";
+	while ( (getline < modulesdep) > 0) {
+		deps[$1] = $2;
+	}
+}
+
+{
+	mod["/"$0] = 1;
+}
+
+END {
+	for (i in mod)
+		recursedeps(i);
+}' -v modulesdep="$basedir/lib/modules/$kernel/modules.dep"
+}
+
+initfs_kmods() {
+	local glob= file= files= dirs=
+	[ -z "$list_soruces" ] && rm -rf "$tmpdir"/lib/modules
+	cd "$kerneldir" || return 1
+	echo "==> initramfs: copying kernel $kernel modules" >&2
+	files=$(
+	for file in $(feature_files $modulelists_dir); do
+		if ! [ -e ${file} ]; then
+			echo "$file: No such file or directory" >&2
+			continue
+		fi
+		echo $file
+	done | find_kmod_deps)
+	for file in $files; do
+		_cp "$basedir"/lib/modules/$kernel/$file
+	done
+}
+
+initfs_cpio() {
+	[ -n "$list_sources" ] && return
+	echo "==> initramfs: creating $outfile" >&2
+	(cd "$tmpdir" && find . | cpio -o -H newc | gzip) > $outfile
+}
+
+usage() {
+	cat <<EOF
+usage: mkinitfs [-hkLl] [-b basedir] [-c configfile] [-f features] 
+		[-i initfile ] [-o outfile] [-t tempdir] [kernelversion]"
+options:
+	-b  prefix files and kernel modules with basedir
+	-c  use configfile instead of $config
+	-f  use specified features
+	-h  print this help
+	-i  use initfile as init instead of $init
+	-k  keep tempdir
+	-l  only list files that would have been used
+	-L  list available features
+	-o  set another outfile
+	-t  use tempdir when creating initramfs image
+
+EOF
+	exit 1
+}
+
+# main
+
+startdir=$PWD
+config=/etc/mkinitfs/mkinitfs.conf
+init=/usr/share/mkinitfs/initramfs-init
+
+while getopts "b:c:hi:kLlo:t:" opt; do
+	case "$opt" in
+		b) basedir="$OPTARG";;
+		c) config="$OPTARG";;
+		f) myfeatures="$OPTARG";;
+		h) usage;;
+		i) init=$OPTARG;;
+		k) keeptmp=1;;
+		L) list_features=1;;
+		l) list_sources=1;;
+		o) outfile="$OPTARG";;
+		t) tmpdir="$OPTARG";;
+		*) usage;;
+	esac
+done
+shift $(( $OPTIND - 1 ))
+
+. "$config"
+filelists_dir=${filelists_dir:-"/etc/mkinitfs/files.d"}
+modulelists_dir=${modules_dir:-"/etc/mkinitfs/modules.d"}
+[ -n "$myfeatures" ] && features="$myfeatures"
+
+if [ -n "$list_features" ]; then
+	for i in $filelists_dir $modulelists_dir; do
+		( [ -d "$i" ] && cd $i && ls )
+	done | sort | uniq
+	exit 0
+fi
+
+[ -n "$1" ] && kernel="$1"
+[ -z "$kernel" ] && kernel=$(uname -r)
+kerneldir="$basedir/lib/modules/$kernel"
+if [ -z "$outfile" ]; then
+	outfile="$basedir"/boot/${kernel##*-}.gz
+fi
+
+if [ ! -d "$kerneldir" ]; then
+	echo "$kerneldir does not exist or is not a directory"
+	exit 1
+fi
+
+if [ -z "$tmpdir" ]; then
+	tmpdir=$(mktemp -d /tmp/mkinitfs.XXXXXX)
+else
+	mkdir -p "$tmpdir"
+fi
+
+if [ -z "$keeptmp" ]; then
+	[ -d "$tmpdir" ] && rm -rf "$tmpdir"/*
+fi
+
+initfs_base
+initfs_kmods
+initfs_cpio
+
+# cleanup
+if [ -z "$keeptmp" ]; then
+	[ -d "$tmpdir" ] && rm -rf "$tmpdir"
+fi
+