WIP on preparing SD card

New step to turn off power LED
This commit is contained in:
2019-12-24 15:32:10 +01:00
parent 742fc70798
commit 0575aad054

View File

@@ -15,6 +15,14 @@ WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
# #. "$CONFIG_FILE" # #. "$CONFIG_FILE"
#} #}
SDDEV=
SDBOOT=
SDROOT=
SDROOTPUUID=
HDDEV=
HDROOT=
HDROOTPUUID=
step_1_info() { echo "Download latest raspbian lite image from" step_1_info() { echo "Download latest raspbian lite image from"
echoinfo "$downUrl"; } echoinfo "$downUrl"; }
step_1_alias() { ALIAS="setup"; } step_1_alias() { ALIAS="setup"; }
@@ -40,7 +48,6 @@ 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 "$2"; else echo "[SD CARD DEVICE]"; fi }
step_2_alias() { ALIAS="writesd"; } step_2_alias() { ALIAS="writesd"; }
step_2() { step_2() {
local sdDev=""
if [ "$downImgName" == "" ] ; then if [ "$downImgName" == "" ] ; then
# called again to make sure $downImgName is populated # called again to make sure $downImgName is populated
step setup step setup
@@ -49,15 +56,14 @@ step_2() {
echoerr " [E] No raspian image found" echoerr " [E] No raspian image found"
return 1 return 1
fi fi
if [ ! -z $2 ] && [ "$2" != "" ] ; then if [ ! -z $2 ] && [ "$2" != "" ] && [ -b "$2" ] ; then
sdDev="$2" SDDEV="$2"
else
exe lsblk -p
exe read -p "Provide SD card device (e.g. /dev/sdb): " sdDev
fi fi
read_sd_dev
# check if device is a block special file # check if device is a block special file
if [ ! -b "$sdDev" ] ; then if [ $? -ne 0 ] ; then
echoerr " [E] $sdDev 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 exe dd bs=4M if="$downImgName" of="$sdDev" conv=fsync
@@ -67,10 +73,35 @@ step_2() {
exe read -p " Press enter to contiue." exe read -p " Press enter to contiue."
} }
step_3_info() { echo "Prepare SD for first run"; } step_3_info() { echo "TODO Prepare SD for first run"; }
step_3() { step_3() {
#TODO #TODO
echo exe touch "$partSdBoot"/ssh echoerr " [E] Not ready yet...TODO"
return 1
read_sd_dev
# enable systemd ssh service
exe touch "$SDBOOT"/ssh
# save SD boot and run settings for 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_alias() { ALIAS="hdboot"; }
step_4() {
#TODO
echoerr " [E] Not ready yet...TODO"
return 1
read_sd_dev
echo "$SDBOOT"
echo "$SDROOT"
echo "$SDROOTPUUID"
read_hd_dev
echo "$HDROOT"
echo "$HDROOTPUUID"
## ? modify PARTUUID of sdBoot/cmdline.txt
## root=PARTUUID=******00-01
} }
step_20_info() { echo "Disable swap file and remove it"; } step_20_info() { echo "Disable swap file and remove it"; }
@@ -111,5 +142,83 @@ resizeDevice="/dev/mmcblk0"
resizePartNo=2 resizePartNo=2
resizePart="${resizeDevice}p${resizePartNo}" resizePart="${resizeDevice}p${resizePartNo}"
step_24_info() {
echo "Turn off power LED [OPTION]"
echoinfo " [OPTION]"
echoinfo " -p : Turn off permanentely (/etc/rc.local)"
}
step_24() {
exep "${ledOffCmd}"
if [ ! -z $2 ] ; then
exep "grep \"$ledPowerBright\" $startScript >>/dev/null"
if [ $? -eq 0 ] ; then
echo " [I] Power LED brightness already used. Please check $startScript manually."
return 1
fi
exe sed -i "s/^exit 0/# Turn off power LED/" "$startScript"
exep "echo \"${ledOffCmd}\" >> $startScript"
exep "echo -e \"\nexit 0\" >> $startScript"
fi
}
startScript="/etc/rc.local"
ledPowerBright="/sys/class/leds/led1/brightness"
ledOffCmd="sudo sh -c 'echo 0 > ${ledPowerBright}'"
read_sd_dev() {
local devsd=""
if [ -z $SDDEV ] && [ ! -b "$SDDEV" ] ; then
if [ -z $2 ]; then
echo " [I] Available devices:"
echo
exe lsblk -p
echo
exe read -p "Provide SD card device (e.g. /dev/sdb): " devsd
else
devsd="$2"
fi
if [ -b "$devsd" ] ; then
SDDEV=$devsd
else
return 1
fi
fi
if [ -z $SDBOOT ] ; then
SDBOOT=$(findmnt -no TARGET "${SDDEV}p1")
fi
if [ -z $SDROOT ] ; then
SDROOT=$(findmnt -no TARGET "${SDDEV}p2")
fi
if [ -z $SDROOTPUUID ] ; then
SDROOTPUUID=$(findmnt -no PARTUUID "${SDDEV}p2")
fi
}
read_hd_dev() {
local devhd=""
if [ -z $HDDEV ] && [ ! -b "$HDDEV" ] ; then
if [ -z $2 ]; then
echo " [I] Available devices:"
echo
exe lsblk -p
echo
exe read -p "Provide HD device (e.g. /dev/sdf): " devhd
else
devhd="$2"
fi
if [ -b "$devhd" ] ; then
HDDEV=$devhd
else
return 1
fi
fi
if [ -z $HDROOT ] ; then
HDROOT=$(findmnt -no TARGET "${HDDEV}1")
fi
if [ -z $HDROOTPUUID ] ; then
HDROOTPUUID=$(findmnt -no PARTUUID "${HDDEV}1")
fi
}
VERSION_SEQREV=9 VERSION_SEQREV=9
. /usr/local/bin/sequencer.sh . /usr/local/bin/sequencer.sh