arch-create-system

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-01-26 23:19:07 +01:00
parent aae2fef40e
commit c5f487ff97

View File

@@ -89,6 +89,8 @@ check_prerequisites () {
}
create_bootloader () {
local cmd
# Needs to be executed in chroot environment (target)
cmd="bootctl --path=boot install"
if [ $dryrun -eq 1 ]; then
@@ -110,6 +112,7 @@ create_btrfs () {
local PREFIX=${2:-BTRFS}
local MOUNT_POINT=$3
local cmd
if [ $dryrun -eq 1 ]; then
printf "${BLUE}Would prepare filesystem ${GREEN}'%s'${NO_COLOR}\n" \
@@ -157,6 +160,8 @@ create_disk () {
local SGDISK="/usr/bin/sgdisk"
local PARTITION=1
local cmd
# test if block-device is available
test -b $TARGET || exit 1
@@ -220,6 +225,8 @@ create_fs_structure () {
local MOUNT_POINT=$3
local SUBVOL=$4
local cmd
printf "${BLUE}Prepare filesystem structure${GREEN}'subvol=%s'${NO_COLOR}\n" \
"$SUBVOL"
cmd="mount_target $MOUNT_POINT /dev/disk/by-partlabel/$LABEL btrfs $SUBVOL"
@@ -229,7 +236,6 @@ create_fs_structure () {
eval "$cmd"
fi
if [ $LABEL="OS" ]; then
printf "${BLUE}Create target filesystem structure${NO_COLOR}\n"
@@ -287,6 +293,8 @@ create_swapfs () {
local PREFIX=$1
local MOUNT_POINT=$2
local cmd
printf "${BLUE}Create target swapfs${NO_COLOR}\n"
# create a subvolume for the swapfs file
@@ -297,7 +305,6 @@ create_swapfs () {
eval "$cmd"
fi
# Disable COW functionality for Subvolume swap
cmd="chattr +C $MOUNT_POINT/swap"
if [ $dryrun -eq 1 ]; then
@@ -335,6 +342,8 @@ create_fat () {
local PREFIX=${2:-BTRFS}
local MOUNT_POINT=$3
local cmd
if [ $dryrun -eq 1 ]; then
printf "${BLUE}Would prepare filesystem ${GREEN}'%s'${NO_COLOR}\n" "$LABEL"
else
@@ -361,6 +370,8 @@ create_vfat () {
local PREFIX=${2:-BTRFS}
local MOUNT_POINT=$3
local cmd
if [ $dryrun -eq 1 ]; then
printf "${BLUE}Would prepare filesystem ${GREEN}'%s'${NO_COLOR}\n" "$LABEL"
else
@@ -394,6 +405,8 @@ get_config_id () {
local config_json=${configfile:-$config_json}
local config_id=${1}
local cmd
if [ $verbose -ge 1 ]; then
printf "${BLUE}get_config_id ...${NO_COLOR}\n"
fi
@@ -410,23 +423,21 @@ get_config_id () {
| .ConfigId as \config_id \
| select(. == \"${ConfigId}\") \
| \$ConfigName'
${config_json}"
${config _json}"
cmd="jq --monochrome-output --ascii-output ' .ConfigEnvironment[] \
| .ConfigName ' \
${config_json}"
config_names=$(eval $cmd)
config_names=$(echo $config_names | sed -e 's/\n//g')
config_name=$(eval $cmd)
config_name=$(echo $config_names | sed -e 's/\n//g')
if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Config environment names: ${GREEN}'%s'${NO_COLOR}\n" \
"$config_names"
printf "${MAGENTA}Config environment id: ${GREEN}'%s'${NO_COLOR}\n" \
"$config_name"
fi
}
get_config_name () {
local config_json=${configfile:-$config_json}
local disk_name=${1}
local config_name=${1}
local cmd
if [ $verbose -ge 1 ]; then
printf "${BLUE}get_config_name ...${NO_COLOR}\n"
@@ -443,17 +454,18 @@ get_config_name () {
cmd="jq --monochrome-output --ascii-output ' .ConfigEnvironment[] \
| .ConfigName ' \
${config_json}"
config_names=$(eval $cmd)
config_names=$(echo $config_names | sed -e 's/\n//g')
config_name=$(eval $cmd)
config_name=$(echo $config_names | sed -e 's/\n//g')
if [ $verbose -ge 2 ]; then
printf "${MAGENTA}Config environment names: ${GREEN}'%s'${NO_COLOR}\n" \
"$config_names"
printf "${MAGENTA}Config environment name: ${GREEN}'%s'${NO_COLOR}\n" \
"$config_name"
fi
}
get_config_names () {
local config_json=${configfile:-$config_json}
local config_json=${config_file:-$config_json}
local cmd
if [ $verbose -ge 1 ]; then
printf "${BLUE}get_config_names ...${NO_COLOR}\n"
@@ -477,6 +489,8 @@ get_config_names () {
get_config_disk_names () {
local config_json=${config_file:-$config_json}
local cmd
if [ $verbose -ge 1 ]; then
printf "${BLUE}get_config_disk_names ...${NO_COLOR}\n"
fi
@@ -533,6 +547,8 @@ mount_target_filesytems () {
install_target_packages () {
local LABEL=$1
local cmd
printf "${BLUE}Install target packages ${GREEN}'%s' -> '%s'${NO_COLOR}\n" \
"$LABEL" "$MOUNT_POINT"
@@ -604,6 +620,8 @@ mount_target () {
local FS_TYPE=$3
local FS_SUBVOL=$4
local cmd
case $FS_TYPE in
"btrfs")
if [ -h $DEV_NAME ]; then
@@ -1011,7 +1029,6 @@ prepare_target_filesystems () {
create_fs_structure $disk_label_root $label_prefix $mount_point /
}
show_config () {
if [ $verbose -ge 1 ]; then
printf "${BLUE}$progname (runtime arguments) ...${NO_COLOR}\n"
@@ -1040,22 +1057,20 @@ show_config () {
}
usage () {
cat <<EOF
$progname $version
Usage: $progname [options]
Options:
-c, --config Read config parameters from given file
--color Enable colored output messages
--dry-run perform a trial run (no changes are written)
--mountpoint Specify MountPoint preparing targets OS-Disk
--label_prefix <prefix> Specify the partion label prefix
-t, --disk_dev_root <target> Specify the blockdevice for the target OS (e.g /dev/sda)
--disk_dev_machines <target> Specify the blockdevice for containers/machines (e.g /dev/sdb)
--disk_dev_data <target> Specify the blockdevice to store data (e.g /dev/sdc)
-v, --verbose Be verbose on what's going on (min: --verbose=0, max: --verbose=3)
--version show program version
EOF
printf '%s\n' \
"$progname $version" \
"Usage: $progname [options]" \
"Options:" \
" -c, --config Read config parameters from given file" \
" --color Enable colored output messages" \
" --dry-run perform a trial run (no changes are written)" \
" --mountpoint Specify MountPoint preparing targets OS-Disk" \
" --label_prefix <prefix> Specify the partion label prefix" \
" -t, --disk_dev_root <target> Specify the blockdevice for the target OS (e.g /dev/sda)" \
" --disk_dev_machines <target> Specify the blockdevice for containers/machines (e.g /dev/sdb)" \
" --disk_dev_data <target> Specify the blockdevice to store data (e.g /dev/sdc)" \
" -v, --verbose Be verbose on what's going on (min: --verbose=0, max: --verbose=3)" \
" --version show program version"
exit 0
}
@@ -1073,7 +1088,9 @@ parse_params $@
# commandline options handled with priority
parse_config_file
#show_config
show_config
printf "${MAGENTA}cmd: ${GREEN}'%s'${NO_COLOR}\n" "$cmd"
case $cmd in
get-config-name)
@@ -1088,6 +1105,7 @@ case $cmd in
fi
;;
get-config-names)
#echo $config_names
get_config_names
if [ $? -gt 0 ]; then
exit 1
@@ -1112,6 +1130,7 @@ case $cmd in
fi
;;
get-config-partition_names)
echo get_config_partition_names
;;
install-target)
@@ -1121,7 +1140,7 @@ case $cmd in
mount_target_filesystems
install_target_packages
exit 0
#exit 0
# change new root to target
cmd="arch-chroot $MOUNT_POINT arch-create-system install_target"
if [ $dryrun -eq 1 ]; then