refactoring changes from sequpgrade (endReturn, ...) and some modernizations

This commit is contained in:
2023-01-03 15:49:08 +01:00
parent 215135e8aa
commit 3c22d5729f
69 changed files with 553 additions and 654 deletions

View File

@@ -58,7 +58,7 @@ evalArgs() {
for _ in "$@"; do
case "${1:-}" in
-a|--arch)
if [ -n "${2:-}" ]; then
if [ -n "${2:-}" ]; then
PIARCH="$2"
((argCount+=2))
else
@@ -74,7 +74,7 @@ evalArgs() {
return $argCount
}
step_1_info() {
step_1_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
@@ -99,7 +99,7 @@ step_1() {
fi
if [ ! -f "$downImgLoc" ] ; then
exe unxz "$downLoc"
endReturn -o $? "Unzip raspios image $PIARCH failed"
endReturn "Unzip raspios image $PIARCH failed"
fi
}
downDay=$(date +%Y%m%d)
@@ -108,13 +108,13 @@ downImgName="raspios_${downDay}.img"
downImgLoc="${downDir}/${downImgName}"
downLoc="${downDir}/${downImgName}.xz"
step_2_info() {
step_2_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
echo "Write Raspberry Pi OS image to SD card"
echoinfo "This operation will delete all data previously on the SD card!"
contextExe && [ -n "${1:-}" ] && echoinfo " [SD CARD DEVICE]: $1"
contextExe && [ -n "${1:-}" ] && echoinfo " [SD CARD DEVICE]: $1"
}
step_2_options() { echo "[OPTIONS] [SD CARD DEVICE]"; }
step_2_alias() { echo "writesd"; }
@@ -151,7 +151,7 @@ step_2() {
exe read -p " Press enter to contiue."
}
step_3_info() {
step_3_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
@@ -164,7 +164,7 @@ step_3_options() { echo "[SD CARD DEVICE]"; }
step_3() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
if [ -z "${1:-}" ] && [ -n "${SDDEV:-}" ] ; then
if quiet ; then
@@ -186,7 +186,7 @@ step_3() {
fi
read_sd_dev "${1:-}"
endReturn -o $? "SD card device not found"
endReturn "SD card device not found"
if [ ! -w "$SDBOOT" ] ; then
error -e "SD card boot partion not writeable"
@@ -215,7 +215,7 @@ step_3() {
exe cp -ar "$SDROOT"/etc/fstab "$SDROOT"/etc/fstab.sd
}
step_4_info() {
step_4_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
@@ -232,13 +232,13 @@ step_4() {
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
read_sd_dev "${1:-}"
endReturn -o $? "SD detection error $?"
endReturn "SD detection error $?"
read_hd_dev "${2:-}"
endReturn -o $? "HD detection error"
echo " [I] SD: $SDDEV"
endReturn "HD detection error"
info "SD: $SDDEV"
echo " $SDBOOT [$SDBOOTPUUID]"
echo " $SDROOT [$SDROOTPUUID]"
echo " [I] HD: $HDDEV"
info "HD: $HDDEV"
echo " $HDROOT [$HDROOTPUUID]"
echo " $HDSWAP [$HDSWAPPUUID]"
echo
@@ -270,7 +270,7 @@ step_4() {
echo
# Resize second partition of SD to max. possible size
echo " [I] Resize root partion of SD: ${SDROOT} "
info "Resize root partion of SD: ${SDROOT} "
step resizesd "$SDDEV"
if [ $? -ne 0 ] ; then
warning -e "Something seems to have failed during resize"
@@ -286,7 +286,7 @@ step_4() {
fi
}
step_5_info() {
step_5_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
@@ -306,30 +306,30 @@ step_5() {
error -e "Not ready yet...TODO"
#return 1
read_sd_dev "${1:-}"
endReturn -o $? "SD detection error $?"
endReturn "SD detection error $?"
read_hd_dev "${2:-}"
endReturn -o $? "HD detection error"
echo " [I] SD: $SDDEV"
endReturn "HD detection error"
info "SD: $SDDEV"
echo " $SDBOOT [$SDBOOTPUUID]"
echo " $SDROOT [$SDROOTPUUID]"
echo " [I] HD: $HDDEV"
info "HD: $HDDEV"
echo " $HDROOT [$HDROOTPUUID]"
echo " $HDSWAP [$HDSWAPPUUID]"
echo
# TODO how to partition HD
echo " [I] $HDDEV is expected to be partitioned with root and swap"
info "$HDDEV is expected to be partitioned with root and swap"
echo " TODO create a step for partitioning script support?!"
echo
# Initial rsync of system to HD
echo " [I] Clone SD root to HD root:"
info "Clone SD root to HD root:"
echo " rsync -avxHAX --numeric-ids --info=stats2 $SDROOT/ $HDROOT/"
echo
# Modify fstab on HD for root and swap on HD
echo " [I] modify $HDROOT/etc/fstab"
info "modify $HDROOT/etc/fstab"
echo " PARTUUID=$SDBOOTPUUID /boot vfat ro,defaults 0 2"
echo " PARTUUID=$SDROOTPUUID /backup ext4 ro,defaults,noatime 0 2"
echo " PARTUUID=$HDROOTPUUID / ext4 defaults,noatime 0 1"
@@ -337,7 +337,7 @@ step_5() {
echo
# etc
echo " [I] modify $HDROOT/etc/dhcpcd.conf for static IPs"
info "modify $HDROOT/etc/dhcpcd.conf for static IPs"
}
read_sd_dev() {
@@ -356,7 +356,7 @@ read_sd_dev() {
SDROOTDEV=
SDBOOTPUUID=
SDROOTPUUID=
echo " [I] Available devices:"
info "Available devices:"
echo
exe lsblk -p
echo
@@ -371,7 +371,7 @@ read_sd_dev() {
if [[ "$SDDEV" =~ .*blk.* ]] ; then
partExt="p"
fi
fi
if [ -z $SDBOOT ] ; then
SDBOOT=$(findmnt -no TARGET "${SDDEV}${partExt}${SDBOOTPARTNO}")
@@ -403,7 +403,7 @@ read_hd_dev() {
HDROOT=
HDROOTPUUID=
HDSWAPPUUID=
echo " [I] Available devices:"
info "Available devices:"
echo
exe lsblk -p
echo
@@ -462,7 +462,7 @@ step_22() {
error -e "No SD found"
return 1
fi
echo " [I] Device to be resized: $SDROOTDEV"
info "Device to be resized: $SDROOTDEV"
exe umount -q "$SDROOT"
exe parted -s "$SDDEV" "resizepart $SDROOTPARTNO -1" quit
@@ -493,7 +493,7 @@ step_24() {
if [ ! -z "$2" ] && [ "$2" == "-p" ] ; then
exep "grep \"$ledPowerBright\" $startScript >>/dev/null"
if [ $? -eq 0 ] ; then
echo " [I] Power LED brightness already used. Please check $startScript manually for:"
info "Power LED brightness already used. Please check $startScript manually for:"
echo " $ledOffCmd"
return 1
fi
@@ -564,7 +564,7 @@ step_34() {
exe $tvserviceOffCmd
exep "grep \"$tvserviceBin\" $startScript >>/dev/null"
if [ $? -eq 0 ] ; then
echo " [I] Tvservice already used. Please check $startScript manually for:"
info "Tvservice already used. Please check $startScript manually for:"
echo " $tvserviceOffCmd"
return 1
fi
@@ -584,7 +584,7 @@ checkBootConfig() {
local re_check="^[[:blank:]]*[^#]*${1}[[:blank:]]*=[[:blank:]]*$2"
grep -rqE "$re_check" "$RPI_BOOT_CONFIG"
return $?
return $?
}
step_100_alias() { echo "notes"; }
@@ -619,7 +619,7 @@ step_100() {
* Configure vim to remember last position in a file
Uncomment the following in [/etc/vim/vimrc]
Uncomment the following in [/etc/vim/vimrc]
> \`au BufReadPost ...\`
NOTES_EOF