arch-create-system: posix cleanup
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
progname="${0##*/}"
|
progname="${0##*/}"
|
||||||
|
prog="$0"
|
||||||
version="0.1.0"
|
version="0.1.0"
|
||||||
|
|
||||||
# global variables
|
# global variables
|
||||||
@@ -132,7 +133,7 @@ create_btrfs () {
|
|||||||
--data single \
|
--data single \
|
||||||
--metadata single \
|
--metadata single \
|
||||||
/dev/disk/by-partlabel/$LABEL"
|
/dev/disk/by-partlabel/$LABEL"
|
||||||
cmd=`echo $cmd | tr -s "[:blank:]"`
|
cmd=`echo $cmd | tr -s \"[:blank:]\"`
|
||||||
if [ $dryrun -eq 1 ]; then
|
if [ $dryrun -eq 1 ]; then
|
||||||
printf "${MAGENTA}Would run: ${GREEN}'%s'${NO_COLOR}\n" \
|
printf "${MAGENTA}Would run: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||||
"$cmd"
|
"$cmd"
|
||||||
@@ -243,7 +244,7 @@ create_fs_structure () {
|
|||||||
printf "${MAGENTA}Would mount target root at ${GREEN}'%s'${NO_COLOR}\n" \
|
printf "${MAGENTA}Would mount target root at ${GREEN}'%s'${NO_COLOR}\n" \
|
||||||
"$SUBVOL"
|
"$SUBVOL"
|
||||||
else
|
else
|
||||||
printf "${BLUE} - mount target root${NO_COLOR\n"
|
printf "${BLUE} - mount target root${NO_COLOR}\n"
|
||||||
mount_target /dev/disk/by-partlabel/${PREFIX}-${LABEL} $MOUNT_POINT btrfs $SUBVOL
|
mount_target /dev/disk/by-partlabel/${PREFIX}-${LABEL} $MOUNT_POINT btrfs $SUBVOL
|
||||||
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
||||||
die "Can't mount root filesystem ${PREFIX}-${LABEL}"
|
die "Can't mount root filesystem ${PREFIX}-${LABEL}"
|
||||||
@@ -305,6 +306,8 @@ create_swapfs () {
|
|||||||
local PREFIX=$1
|
local PREFIX=$1
|
||||||
local MOUNT_POINT=$2
|
local MOUNT_POINT=$2
|
||||||
|
|
||||||
|
local RamSize
|
||||||
|
local SwapSize
|
||||||
local cmd
|
local cmd
|
||||||
|
|
||||||
printf "${BLUE}create_swapfs${NO_COLOR}\n"
|
printf "${BLUE}create_swapfs${NO_COLOR}\n"
|
||||||
@@ -327,7 +330,8 @@ create_swapfs () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# prepare the swapfile (size: 2x RAM)
|
# prepare the swapfile (size: 2x RAM)
|
||||||
RamSize=`cat /proc/meminfo | gawk 'NR==1 {print $2}'`
|
cmd='gawk '/^MemTotal:/{print $2}' /proc/meminfo'
|
||||||
|
RamSize=$(eval $cmd)
|
||||||
SwapSize=$(expr 2 '*' $RamSize)
|
SwapSize=$(expr 2 '*' $RamSize)
|
||||||
SwapFile=$MOUNT_POINT/swap/swapfile
|
SwapFile=$MOUNT_POINT/swap/swapfile
|
||||||
|
|
||||||
@@ -368,7 +372,7 @@ create_fat () {
|
|||||||
-F 32 \
|
-F 32 \
|
||||||
-n $LABEL \
|
-n $LABEL \
|
||||||
/dev/disk/by-partlabel/$LABEL"
|
/dev/disk/by-partlabel/$LABEL"
|
||||||
cmd=`echo $cmd | tr -s "[:blank:]"`
|
cmd="echo $cmd | tr -s \"[:blank:]\""
|
||||||
if [ $dryrun -eq 1 ]; then
|
if [ $dryrun -eq 1 ]; then
|
||||||
printf "${MAGENTA}Would run ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
printf "${MAGENTA}Would run ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
||||||
else
|
else
|
||||||
@@ -395,7 +399,7 @@ create_vfat () {
|
|||||||
cmd="mkfs -t vfat \
|
cmd="mkfs -t vfat \
|
||||||
-n $PREFIX-$LABEL \
|
-n $PREFIX-$LABEL \
|
||||||
/dev/disk/by-partlabel/$LABEL"
|
/dev/disk/by-partlabel/$LABEL"
|
||||||
cmd=`echo $cmd | tr -s "[:blank:]"`
|
cmd="echo $cmd | tr -s \"[:blank:]\""
|
||||||
if [ $dryrun -eq 1 ]; then
|
if [ $dryrun -eq 1 ]; then
|
||||||
printf "${MAGENTA}Would run ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
printf "${MAGENTA}Would run ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
||||||
else
|
else
|
||||||
@@ -407,7 +411,7 @@ create_vfat () {
|
|||||||
die () {
|
die () {
|
||||||
error "$@"
|
error "$@"
|
||||||
if [ $dryrun -eq 1 ]; then
|
if [ $dryrun -eq 1 ]; then
|
||||||
printf "${RED}Error${GREEN}'%s'${NO_COLOR}\n" "$@"
|
printf "${RED}Error: ${GREEN}'%s'${NO_COLOR}\n" "$@"
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -416,74 +420,35 @@ error () {
|
|||||||
printf "\n==> ERROR: %s\n" "$@"
|
printf "\n==> ERROR: %s\n" "$@"
|
||||||
} >&2
|
} >&2
|
||||||
|
|
||||||
get_config () {
|
|
||||||
local config_json=${configfile:-$config_json}
|
|
||||||
local config=${1}
|
|
||||||
|
|
||||||
local cmd
|
|
||||||
|
|
||||||
if [ $verbose -ge 1 ]; then
|
|
||||||
printf "${BLUE}get_config ...${NO_COLOR}\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if test ! -r ${config_json}; then
|
|
||||||
if [ $verbose -ge 1 ]; then
|
|
||||||
printf "${RED}Error:${MAGENTA} config file ${GREEN}'%s'${MAGENTA} can't be opend!${NO_COLOR}\n" \
|
|
||||||
"config_json"
|
|
||||||
fi
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
cmd="jq -r --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
|
||||||
| select(.ConfigName == \"${name}\") \
|
|
||||||
| .ConfigName ' \
|
|
||||||
${config_json}"
|
|
||||||
#cmd="jq --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
|
||||||
# | {Id: .ConfigId, Name: .ConfigName} ' \
|
|
||||||
# ${config_json}"
|
|
||||||
|
|
||||||
config_name=$(eval $cmd)
|
|
||||||
#config_name=$(echo $config_name | sed -e 's/\n//g')
|
|
||||||
|
|
||||||
if [ $verbose -ge 2 ]; then
|
|
||||||
printf "${MAGENTA}Config environment id: ${GREEN}'%s'${NO_COLOR}\n" \
|
|
||||||
"$config_name"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
get_config_name () {
|
get_config_name () {
|
||||||
local config_json=${configfile:-$config_json}
|
local config_json=${configfile:-$config_json}
|
||||||
local name=${1}
|
local config_file=${1}
|
||||||
|
|
||||||
local cmd
|
local cmd
|
||||||
|
|
||||||
if [ $verbose -ge 1 ]; then
|
if [ $verbose -ge 1 ]; then
|
||||||
printf "${BLUE}get_config_name ...${NO_COLOR}\n"
|
printf "${BLUE}get_config_name ...${NO_COLOR}\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test ! -r ${config_json}; then
|
if [ ! -r ${config_json} ] ; then
|
||||||
if [ $verbose -ge 1 ]; then
|
if [ $verbose -ge 1 ]; then
|
||||||
printf "${RED}Error:${MAGENTA} config file ${GREEN}'%s'${MAGENTA} can't be opend!${NO_COLOR}\n" \
|
printf "${RED}Error:${MAGENTA} config file ${GREEN}'%s'${MAGENTA} can\'t be opend!${NO_COLOR}\n" \
|
||||||
"config_json"
|
"config_json"
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cmd="jq -r --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
cmd="jq -r --monochrome-output --ascii-output ' .ConfigEnvironment[] \
|
||||||
| select(.ConfigName == \"${name}\") \
|
| select( .ConfigName == \"${config_file}\" ) \
|
||||||
| .ConfigName ' \
|
| .ConfigName ' \
|
||||||
${config_json}"
|
${config_json}"
|
||||||
config_name=$(eval $cmd)
|
|
||||||
config_name=$(echo $config_name | sed -e 's/\n//g')
|
|
||||||
|
|
||||||
if [ ${#config_name} = 0 ]; then
|
|
||||||
|
config_name=$(eval $cmd)
|
||||||
|
#config_name=$(echo $config_name | sed -e 's/\n//g')
|
||||||
|
|
||||||
if [ $verbose -ge 2 ]; then
|
if [ $verbose -ge 2 ]; then
|
||||||
printf "${MAGENTA}Config environment name: ${GREEN}'%s'${MAGENTA} not found!${NO_COLOR}\n" \
|
printf "${MAGENTA}Config environment id: ${GREEN}'%s'${NO_COLOR}\n" \
|
||||||
"$name"
|
|
||||||
fi
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if [ $verbose -ge 2 ]; then
|
|
||||||
printf "${MAGENTA}Config environment name: ${GREEN}'%s'${MAGENTA} exists.${NO_COLOR}\n" \
|
|
||||||
"$config_name"
|
"$config_name"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -636,8 +601,7 @@ install_target_packages () {
|
|||||||
eval "$cmd"
|
eval "$cmd"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
install_script=`command -v $progname`
|
cmd="cp $prog $MOUNT_POINT/usr/bin/"
|
||||||
cmd="cp $install_script $MOUNT_POINT/usr/bin/"
|
|
||||||
if [ $dryrun -eq 1 ]; then
|
if [ $dryrun -eq 1 ]; then
|
||||||
printf "${MAGENTA}Would run ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
printf "${MAGENTA}Would run ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
|
||||||
else
|
else
|
||||||
@@ -716,7 +680,7 @@ mount_target () {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
cmd=`echo $cmd | tr -s "[:blank:]"`
|
cmd="echo $cmd | tr -s \"[:blank:]\""
|
||||||
if [ $dryrun -eq 1 ]; then
|
if [ $dryrun -eq 1 ]; then
|
||||||
printf "${MAGENTA}Would mount ${GREEN}'%s'${MAGENTA} of ${GREEN}'%s'${MAGENTA} at ${GREEN}'%s'${NO_COLOR}\n" \
|
printf "${MAGENTA}Would mount ${GREEN}'%s'${MAGENTA} of ${GREEN}'%s'${MAGENTA} at ${GREEN}'%s'${NO_COLOR}\n" \
|
||||||
"$FS_SUBVOL" "$DEV_NAME" "$MOUNT_POINT"
|
"$FS_SUBVOL" "$DEV_NAME" "$MOUNT_POINT"
|
||||||
@@ -924,7 +888,7 @@ parse_params () {
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
-*)
|
-*)
|
||||||
printf "WARN: Unknown option (ignored): $1" >&2
|
printf "WARN: Unknown option \(ignored\): $1" >&2
|
||||||
die "Unknown option"
|
die "Unknown option"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
@@ -964,7 +928,7 @@ prepare_bootloader () {
|
|||||||
> /boot/loader/loader.conf
|
> /boot/loader/loader.conf
|
||||||
|
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"title Arch Linux (Mainline)" \
|
"title Arch Linux \(Mainline\)" \
|
||||||
"linux /vmlinuz-linux" \
|
"linux /vmlinuz-linux" \
|
||||||
"initrd /intel-ucode.img" \
|
"initrd /intel-ucode.img" \
|
||||||
"initrd /initramfs-linux.img" \
|
"initrd /initramfs-linux.img" \
|
||||||
@@ -992,8 +956,8 @@ prepare_locale () {
|
|||||||
prepare_mount_units () {
|
prepare_mount_units () {
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"[Unit]" \
|
"[Unit]" \
|
||||||
"Description=root-Snapshots (btrfs)" \
|
"Description=root-Snapshots \(btrfs\)" \
|
||||||
"Documentation=man:systemd.mount(5)" \
|
"Documentation=man:systemd.mount\(5\)" \
|
||||||
"DefaultDependencies=yes" \
|
"DefaultDependencies=yes" \
|
||||||
"Before=local-fs.target" \
|
"Before=local-fs.target" \
|
||||||
"" \
|
"" \
|
||||||
@@ -1010,8 +974,8 @@ prepare_mount_units () {
|
|||||||
|
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"[Unit]" \
|
"[Unit]" \
|
||||||
"Description=Caching (btrfs)" \
|
"Description=Caching \(btrfs\)" \
|
||||||
"Documentation=man:systemd.mount(5)" \
|
"Documentation=man:systemd.mount\(5\)" \
|
||||||
"DefaultDependencies=yes" \
|
"DefaultDependencies=yes" \
|
||||||
"Before=local-fs.target" \
|
"Before=local-fs.target" \
|
||||||
"" \
|
"" \
|
||||||
@@ -1028,8 +992,8 @@ prepare_mount_units () {
|
|||||||
|
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"[Unit]" \
|
"[Unit]" \
|
||||||
"Description=data (btrfs)" \
|
"Description=data \(btrfs\)" \
|
||||||
"Documentation=man:systemd.mount(5)" \
|
"Documentation=man:systemd.mount\(5\)" \
|
||||||
"DefaultDependencies=yes" \
|
"DefaultDependencies=yes" \
|
||||||
"Before=local-fs.target" \
|
"Before=local-fs.target" \
|
||||||
"" \
|
"" \
|
||||||
@@ -1046,8 +1010,8 @@ prepare_mount_units () {
|
|||||||
|
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"[Unit]" \
|
"[Unit]" \
|
||||||
"Description=Home (btrfs)" \
|
"Description=Home \(btrfs\)" \
|
||||||
"Documentation=man:systemd.mount(5)" \
|
"Documentation=man:systemd.mount\(5\)" \
|
||||||
"DefaultDependencies=yes" \
|
"DefaultDependencies=yes" \
|
||||||
"Before=local-fs.target" \
|
"Before=local-fs.target" \
|
||||||
"" \
|
"" \
|
||||||
@@ -1064,8 +1028,8 @@ prepare_mount_units () {
|
|||||||
|
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
"[Unit]" \
|
"[Unit]" \
|
||||||
"Description=Logging (btrfs)" \
|
"Description=Logging \(btrfs\)" \
|
||||||
"Documentation=man:systemd.mount(5)" \
|
"Documentation=man:systemd.mount\(5\)" \
|
||||||
"DefaultDependencies=yes" \
|
"DefaultDependencies=yes" \
|
||||||
"Before=local-fs.target" \
|
"Before=local-fs.target" \
|
||||||
"" \
|
"" \
|
||||||
@@ -1153,6 +1117,8 @@ prepare_target_filesystems () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show_config () {
|
show_config () {
|
||||||
|
local options
|
||||||
|
|
||||||
if [ $verbose -ge 1 ]; then
|
if [ $verbose -ge 1 ]; then
|
||||||
printf "${BLUE}$progname (runtime arguments) ...${NO_COLOR}\n"
|
printf "${BLUE}$progname (runtime arguments) ...${NO_COLOR}\n"
|
||||||
i=0
|
i=0
|
||||||
@@ -1173,7 +1139,7 @@ show_config () {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
options="verbose_level=$verbose"
|
options="verbose_level=$verbose"
|
||||||
if [ $dryrun -ge 1 ]; then options="${options}dryrun=true"; fi
|
if [ $dryrun -ge 1 ]; then options="${options} dryrun=true"; fi
|
||||||
if [ $color -ge 1 ]; then options="${options} color=true"; fi
|
if [ $color -ge 1 ]; then options="${options} color=true"; fi
|
||||||
|
|
||||||
printf "Options: '%s'\n\n" "${options}"
|
printf "Options: '%s'\n\n" "${options}"
|
||||||
@@ -1205,7 +1171,8 @@ usage () {
|
|||||||
###
|
###
|
||||||
# Main
|
# Main
|
||||||
###
|
###
|
||||||
# can't be ported to dash (ERR is not supported)
|
|
||||||
|
# can't be ported to dash \(ERR is not supported\)
|
||||||
#trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR
|
#trap 'traperror ${LINENO} $? "$BASH_COMMAND" $BASH_LINENO "${FUNCNAME[@]}"' ERR
|
||||||
trap trapkill TERM INT
|
trap trapkill TERM INT
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user