Subject: [alpine-devel] [PATCH] setup-disk.in: cleanups

From: Valery Kartel <[email-masked]>
Date: Sat, 6 Feb 2016 14:05:54 +0200

- 'mkfs_args' function added. It prints mkfs.<filesystem> specific arguments.
- in 'setup_boot_dev', 'setup_var' & 'setup_root' mkfs_args variable changed to mkfs_args(fs) function call.
- in 'init_progs' I replace all pkg-specific variables with a single $pkgs variable and made modules and fs-tools loading depends on install type (sys or data).

PS: don't know why additional package 'acct' hardcoded to dest-system install list. Does it really needs?
---
 setup-disk.in | 56 ++++++++++++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/setup-disk.in b/setup-disk.in
index ea3c590..30a3e09 100644
--- a/setup-disk.in
+++ b/setup-disk.in
@@ -32,6 +32,18 @@ all_in_list() {
 	return 0
 }
 
+# prints mkfs.* specific command-line arguments
+mkfs_args() {
+	local args=
+	case "$1" in
+		xfs) args="-f";;
+		ext*) args="-F";;
+		btrfs) args="-f";;
+	esac
+	[ -n "$VERBOSE" ] || args="$args -q"
+	echo $args
+}
+
 # wrapper to only show given device
 _blkid() {
 	blkid | grep "^$1:"
@@ -442,21 +454,20 @@ stop_all_raid() {
 
 # install needed programs
 init_progs() {
-	local raidpkg= lvmpkg= fs= fstools=
-	[ -n "$USE_RAID" ] && raidpkg="mdadm"
-	[ -n "$USE_LVM" ] && lvmpkg="lvm2"
-	for fs in $BOOTFS $ROOTFS $VARFS; do
-		# we need load btrfs module early to avoid the error message:
-		# 'failed to open /dev/btrfs-control'
+	local fs= fslist= pkgs="sfdisk syslinux"
+	[ -n "$USE_RAID" ] && pkgs="$pkgs mdadm"
+	[ -n "$USE_LVM" ] && pkgs="$pkgs lvm2"
+	[ "$answer" = "sys" ] && fslist="$BOOTFS $ROOTFS"
+	[ "$answer" = "data" ] && fslist="$VARFS"
+	for fs in $fslist; do
 		modprobe $fs
-
 		case $fs in
-		xfs) fstools="$fstools xfsprogs";;
-		ext*) fstools="$fstools e2fsprogs";;
-		btrfs) fstools="$fstools btrfs-progs";;
+		xfs) pkgs="$pkgs xfsprogs";;
+		ext*) pkgs="$pkgs e2fsprogs";;
+		btrfs) pkgs="$pkgs btrfs-progs";;
 		esac
 	done
-	apk add --quiet sfdisk $lvmpkg $raidpkg syslinux $fstools $@
+	apk add --quiet $pkgs $@
 }
 
 show_disk_info() {
@@ -533,11 +544,11 @@ find_lvm_partition() {
 
 # set up optional raid and create filesystem on boot device.
 setup_boot_dev() {
-	local disk= bootdev= mkfs_args="-q"
+	local disk= boot_dev=
 	local part=$(for disk in $@; do find_boot_partition $disk; done)
 	set -- $part
-	bootdev=$1
-	[ -z "$bootdev" ] && return 1
+	boot_dev=$1
+	[ -z "$boot_dev" ] && return 1
 	echo "Creating file systems..."
 	if [ -n "$USE_RAID" ]; then
 		local missing=
@@ -549,11 +560,10 @@ setup_boot_dev() {
 		# we only use raid level 1 for boot devices
 		mdadm --create /dev/md0 --level=1 --raid-devices=$num \
 			--metadata=0.90 --quiet --run $@ $missing || return 1
-		bootdev=/dev/md0
+		boot_dev=/dev/md0
 	fi
-	[ "$BOOTFS" = "btrfs" ] && mkfs_args=""
-	mkfs.$BOOTFS $mkfs_args $bootdev
-	BOOT_DEV="$bootdev"
+	mkfs.$BOOTFS $(mkfs_args $BOOTFS) $boot_dev
+	BOOT_DEV="$boot_dev"
 }
 
 # $1 = index
@@ -645,11 +655,10 @@ reset_var() {
 # set up /var on given device
 setup_var() {
 	local var_dev="$1"
-	local varfs=${VARFS}
 	echo "Creating file systems..."
-	mkfs.$varfs $var_dev >/dev/null || return 1
+	mkfs.$VARFS $(mkfs_args $VARFS) $var_dev || return 1
 	sed -i -e '/[[:space:]]\/var[[:space:]]/d' /etc/fstab
-	echo -e "${var_dev}\t/var\t\t${varfs}\tdefaults 1 2" >> /etc/fstab
+	echo -e "${var_dev}\t/var\t\t${VARFS}\tdefaults 1 2" >> /etc/fstab
 
 	mv /var /.var
 	mkdir /var
@@ -742,9 +751,8 @@ data_only_disk_install() {
 
 # setup
 setup_root() {
-	local root_dev="$1" boot_dev="$2" mkfs_args="-q"
-	[ "$ROOTFS" = "btrfs" ] && mkfs_args=""
-	mkfs.$ROOTFS $mkfs_args "$root_dev"
+	local root_dev="$1" boot_dev="$2"
+	mkfs.$ROOTFS $(mkfs_args $ROOTFS) $root_dev
 	mkdir -p "$SYSROOT"
 	mount -t $ROOTFS $root_dev "$SYSROOT" || return 1
 	if [ -n "$boot_dev" ]; then
-- 
2.7.0

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---