WIP simplification of read sd/hd functions
This commit is contained in:
@@ -45,7 +45,9 @@ downDir="/tmp"
|
||||
downLoc="${downDir}/raspbian_$downDay.zip"
|
||||
|
||||
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() {
|
||||
if [ "$downImgName" == "" ] ; then
|
||||
@@ -56,48 +58,83 @@ step_2() {
|
||||
echoerr " [E] No raspian image found"
|
||||
return 1
|
||||
fi
|
||||
if [ ! -z $2 ] && [ "$2" != "" ] && [ -b "$2" ] ; then
|
||||
SDDEV="$2"
|
||||
fi
|
||||
|
||||
read_sd_dev
|
||||
# check if device is a block special file
|
||||
read_sd_dev "$2"
|
||||
# check if device was confirmed
|
||||
if [ $? -ne 0 ] ; then
|
||||
echoerr " [E] SD card device not found"
|
||||
return 1
|
||||
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
|
||||
#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."
|
||||
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() {
|
||||
#TODO
|
||||
echoerr " [E] Not ready yet...TODO"
|
||||
#return 1
|
||||
|
||||
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
|
||||
read_sd_dev
|
||||
fi
|
||||
|
||||
if [ ! -w "$SDBOOT" ] ; then
|
||||
echoerr " [E] SD card boot partion not writeable"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# enable systemd ssh service
|
||||
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 "$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() {
|
||||
#TODO
|
||||
echoerr " [E] Not ready yet...TODO"
|
||||
return 1
|
||||
read_sd_dev
|
||||
#return 1
|
||||
read_sd_dev "$2"
|
||||
echo $?
|
||||
echo "$SDBOOT"
|
||||
echo "$SDROOT"
|
||||
echo "$SDROOTPUUID"
|
||||
read_hd_dev
|
||||
read_hd_dev "$3"
|
||||
echo $?
|
||||
echo "$HDROOT"
|
||||
echo "$HDROOTPUUID"
|
||||
## ? modify PARTUUID of sdBoot/cmdline.txt
|
||||
@@ -167,23 +204,28 @@ ledOffCmd="sudo sh -c 'echo 0 > ${ledPowerBright}'"
|
||||
|
||||
|
||||
read_sd_dev() {
|
||||
local devsd=""
|
||||
if [ -z $SDDEV ] && [ ! -b "$SDDEV" ] ; then
|
||||
if [ -z $2 ]; then
|
||||
if [ ! -z "$1" ] ; then
|
||||
SDBOOT=
|
||||
SDROOT=
|
||||
SDROOTPUUID=
|
||||
SDDEV="$1"
|
||||
elif [ -z $SDDEV ] || [ ! -b "$SDDEV" ] ; then
|
||||
SDDEV=
|
||||
SDBOOT=
|
||||
SDROOT=
|
||||
SDROOTPUUID=
|
||||
echo " [I] Available devices:"
|
||||
echo
|
||||
exe lsblk -p
|
||||
echo
|
||||
exe read -p "Provide SD card device (e.g. /dev/sdb): " devsd
|
||||
else
|
||||
devsd="$2"
|
||||
exe read -p "Provide SD card device (e.g. /dev/sdb): " SDDEV
|
||||
fi
|
||||
if [ -b "$devsd" ] ; then
|
||||
SDDEV=$devsd
|
||||
else
|
||||
|
||||
if [ ! -b "$SDDEV" ] ; then
|
||||
SDDEV=
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z $SDBOOT ] ; then
|
||||
SDBOOT=$(findmnt -no TARGET "${SDDEV}p1")
|
||||
fi
|
||||
@@ -196,23 +238,25 @@ read_sd_dev() {
|
||||
}
|
||||
|
||||
read_hd_dev() {
|
||||
local devhd=""
|
||||
if [ -z $HDDEV ] && [ ! -b "$HDDEV" ] ; then
|
||||
if [ -z $2 ]; then
|
||||
if [ ! -z "$1" ] ; then
|
||||
HDROOT=
|
||||
HDROOTPUUID=
|
||||
HDDEV="$1"
|
||||
elif [ -z $HDDEV ] || [ ! -b "$HDDEV" ] ; then
|
||||
HDROOT=
|
||||
HDROOTPUUID=
|
||||
echo " [I] Available devices:"
|
||||
echo
|
||||
exe lsblk -p
|
||||
echo
|
||||
exe read -p "Provide HD device (e.g. /dev/sdf): " devhd
|
||||
else
|
||||
devhd="$2"
|
||||
exe read -p "Provide HD device (e.g. /dev/sdf): " HDDEV
|
||||
fi
|
||||
if [ -b "$devhd" ] ; then
|
||||
HDDEV=$devhd
|
||||
else
|
||||
|
||||
if [ ! -b "$HDDEV" ] ; then
|
||||
HDDEV=
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z $HDROOT ] ; then
|
||||
HDROOT=$(findmnt -no TARGET "${HDDEV}1")
|
||||
fi
|
||||
|
Reference in New Issue
Block a user