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