WIP simplification of read sd/hd functions

This commit is contained in:
2019-12-25 18:57:00 +01:00
parent 49749cdeeb
commit b5447f6f06

View File

@@ -45,7 +45,9 @@ downDir="/tmp"
downLoc="${downDir}/raspbian_$downDay.zip" downLoc="${downDir}/raspbian_$downDay.zip"
step_2_info() { echo -n "Write raspbian image to SD card " step_2_info() { echo -n "Write raspbian image to SD card "
if [ ! -z $2 ] ; then echo "$2"; else echo "[SD CARD DEVICE]"; fi } if [ -z $2 ] ; then echo "[SD CARD DEVICE]"; else echo "$2"; fi
echoinfo "This operation will delete all data previously on the SD card!"
}
step_2_alias() { ALIAS="writesd"; } step_2_alias() { ALIAS="writesd"; }
step_2() { step_2() {
if [ "$downImgName" == "" ] ; then if [ "$downImgName" == "" ] ; then
@@ -56,48 +58,83 @@ step_2() {
echoerr " [E] No raspian image found" echoerr " [E] No raspian image found"
return 1 return 1
fi fi
if [ ! -z $2 ] && [ "$2" != "" ] && [ -b "$2" ] ; then
SDDEV="$2"
fi
read_sd_dev read_sd_dev "$2"
# check if device is a block special file # check if device was confirmed
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
echoerr " [E] SD card device not found" echoerr " [E] SD card device not found"
return 1 return 1
fi fi
exe dd bs=4M if="$downImgName" of="$sdDev" conv=fsync
# write image
exe dd bs=4M if="$downImgName" of="$SDDEV" conv=fsync
endReturn -o "$?" "Writing image to $SDDEV failed"
exe sync exe sync
#x TODO ? automatic remount
# SD partitions will have new informations now
# Leave SD card device intact for next step
SDBOOT=""
SDROOT=""
# TODO ? automatic remount
echoerr " [W] Please remove SD now and plug it back in." echoerr " [W] Please remove SD now and plug it back in."
exe read -p " Press enter to contiue." exe read -p " Press enter to contiue."
} }
step_3_info() { echo "TODO Prepare SD for first run"; } step_3_info() { echo "TODO Prepare SD for first run [SD CARD DEVICE]"; }
step_3() { step_3() {
#TODO
echoerr " [E] Not ready yet...TODO" echoerr " [E] Not ready yet...TODO"
return 1 #return 1
read_sd_dev
if [ -z $2 ] && [ ! -z $SDDEV ] ; then
if [ $QUIET -ne 0 ] ; then
answer="n"
else
exe read -p "Is $SDDEV still the SD card (y/[n])? " answer
fi
case $answer in
[yY])
# Nothing todo
;;
*)
SDDEV=""
;;
esac
fi
read_sd_dev "$2"
if [ $? -ne 0 ] ; then
echoerr " [E] SD card device not found"
return 1
fi
if [ ! -w "$SDBOOT" ] ; then
echoerr " [E] SD card boot partion not writeable"
return 1
fi
# enable systemd ssh service # enable systemd ssh service
exe touch "$SDBOOT"/ssh exe touch "$SDBOOT"/ssh
# save SD boot and run settings for emergency start from SD # save SD boot settings for easy emergency start from SD
cp -ar "$SDBOOT"/cmdline.txt "$SDBOOT"/cmdline.txt.sd cp -ar "$SDBOOT"/cmdline.txt "$SDBOOT"/cmdline.txt.sd
cp -ar "$SDROOT"/etc/fstab "$SDROOT"/etc/fstab.sd cp -ar "$SDROOT"/etc/fstab "$SDROOT"/etc/fstab.sd
} }
step_4_info() { echo "TODO Prepare SD for HD boot"; } step_4_info() { echo "TODO Prepare SD for HD boot [SD CARD DEVICE] [HD DEVICE]"; }
step_4_alias() { ALIAS="hdboot"; } step_4_alias() { ALIAS="hdboot"; }
step_4() { step_4() {
#TODO #TODO
echoerr " [E] Not ready yet...TODO" echoerr " [E] Not ready yet...TODO"
return 1 #return 1
read_sd_dev read_sd_dev "$2"
echo $?
echo "$SDBOOT" echo "$SDBOOT"
echo "$SDROOT" echo "$SDROOT"
echo "$SDROOTPUUID" echo "$SDROOTPUUID"
read_hd_dev read_hd_dev "$3"
echo $?
echo "$HDROOT" echo "$HDROOT"
echo "$HDROOTPUUID" echo "$HDROOTPUUID"
## ? modify PARTUUID of sdBoot/cmdline.txt ## ? modify PARTUUID of sdBoot/cmdline.txt
@@ -167,23 +204,28 @@ ledOffCmd="sudo sh -c 'echo 0 > ${ledPowerBright}'"
read_sd_dev() { read_sd_dev() {
local devsd="" if [ ! -z "$1" ] ; then
if [ -z $SDDEV ] && [ ! -b "$SDDEV" ] ; then SDBOOT=
if [ -z $2 ]; then SDROOT=
echo " [I] Available devices:" SDROOTPUUID=
echo SDDEV="$1"
exe lsblk -p elif [ -z $SDDEV ] || [ ! -b "$SDDEV" ] ; then
echo SDDEV=
exe read -p "Provide SD card device (e.g. /dev/sdb): " devsd SDBOOT=
else SDROOT=
devsd="$2" SDROOTPUUID=
fi echo " [I] Available devices:"
if [ -b "$devsd" ] ; then echo
SDDEV=$devsd exe lsblk -p
else echo
return 1 exe read -p "Provide SD card device (e.g. /dev/sdb): " SDDEV
fi
fi fi
if [ ! -b "$SDDEV" ] ; then
SDDEV=
return 1
fi
if [ -z $SDBOOT ] ; then if [ -z $SDBOOT ] ; then
SDBOOT=$(findmnt -no TARGET "${SDDEV}p1") SDBOOT=$(findmnt -no TARGET "${SDDEV}p1")
fi fi
@@ -196,23 +238,25 @@ read_sd_dev() {
} }
read_hd_dev() { read_hd_dev() {
local devhd="" if [ ! -z "$1" ] ; then
if [ -z $HDDEV ] && [ ! -b "$HDDEV" ] ; then HDROOT=
if [ -z $2 ]; then HDROOTPUUID=
echo " [I] Available devices:" HDDEV="$1"
echo elif [ -z $HDDEV ] || [ ! -b "$HDDEV" ] ; then
exe lsblk -p HDROOT=
echo HDROOTPUUID=
exe read -p "Provide HD device (e.g. /dev/sdf): " devhd echo " [I] Available devices:"
else echo
devhd="$2" exe lsblk -p
fi echo
if [ -b "$devhd" ] ; then exe read -p "Provide HD device (e.g. /dev/sdf): " HDDEV
HDDEV=$devhd
else
return 1
fi
fi fi
if [ ! -b "$HDDEV" ] ; then
HDDEV=
return 1
fi
if [ -z $HDROOT ] ; then if [ -z $HDROOT ] ; then
HDROOT=$(findmnt -no TARGET "${HDDEV}1") HDROOT=$(findmnt -no TARGET "${HDDEV}1")
fi fi