diff --git a/seqs/raspberry.sh b/seqs/raspberry.sh index 6aef225..08a57ce 100755 --- a/seqs/raspberry.sh +++ b/seqs/raspberry.sh @@ -14,6 +14,11 @@ distName= RPI_BOOT_CONFIG="/boot/config.txt" step_config() { + # Shift away args + local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + # Set download url with specified CPU architecture + PIDOWNURL="https://downloads.raspberrypi.org/raspios_lite_${PIARCH}_latest" + if [ "$(which lsb_release)" == "" ] ; then echoerr " [W] Cannot detect OS. Assuming Ubuntu" osName="Ubuntu" @@ -27,9 +32,12 @@ step_config() { osName="Ubuntu" fi - echo " [I] Detected OS: $osName $distName" + echoseq " Detected OS: $osName $distName" + echoseq " Requested CPU Architecture: $PIARCH" } +PIARCH=armhf +PIDOWNURL= SDDEV= SDBOOT= SDBOOTPUUID= @@ -42,35 +50,76 @@ HDROOTPUUID= HDSWAP= HDSWAPPUUID= -step_1_info() { echo "Download latest Raspberry Pi OS lite image from" -echoinfo "$downUrl"; } +evalArgs() { + local argCount=0 + + for arg in "$@"; do + case "$1" in + -a|--arch) + if [ ! -z "$2" ]; then + PIARCH="$2" + ((argCount+=2)) + else + ((argCount+=1)) + fi + shift $argCount + ;; + *) + break + ;; + esac + done + return $argCount +} + +step_1_info() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + + echoinfoArgs "[OPTIONS] [SD CARD DEVICE] [HD DEVICE]" + echo "Download latest Raspberry Pi OS lite image $PIARCH" + if [ $CONTEXT_EXE -ne 0 ]; then + echoinfo "Download URL: $PIDOWNURL" + else + echoinfo " [OPTIONS]" + echoinfo " -a, --arch : armhf (default), arm64" + fi +} step_1_alias() { ALIAS="setup"; } step_1() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + if [ ! -f "$downLoc" ] ; then - exe wget "$downUrl" -O "$downLoc" + exe wget "$PIDOWNURL" -O "$downLoc" echo -ne " [I] sha256 sum of download:\n " exe sha256sum "$downLoc" fi downImgName="${downDir}/$(zipinfo -1 "$downLoc")" if [ ! -f "$downImgName" ] ; then exe unzip "$downLoc" -d "$downDir" - endReturn -o $? "Unzip raspios image failed" + endReturn -o $? "Unzip raspios image $PIARCH failed" fi } -downUrl="https://downloads.raspberrypi.org/raspios_lite_armhf_latest" downImgName="" downDay=$(date +%Y%m%d) downDir="/tmp" downLoc="${downDir}/raspios_$downDay.zip" step_2_info() { - echoinfoArgs "[SD CARD DEVICE]" + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + + echoinfoArgs "[OPTIONS] [SD CARD DEVICE]" echo "Write Raspberry Pi OS image to SD card" echoinfo "This operation will delete all data previously on the SD card!" - [ $CONTEXT_EXE -ne 0 ] && [ ! -z $2 ] && echoinfo " [SD CARD DEVICE]: $2" + [ $CONTEXT_EXE -ne 0 ] && [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" } step_2_alias() { ALIAS="writesd"; } step_2() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + if [ "$downImgName" == "" ] ; then # called again to make sure $downImgName is populated step setup @@ -83,14 +132,14 @@ step_2() { endReturn -o 1 "No root" fi - read_sd_dev "$2" + read_sd_dev "$1" # check if device was confirmed if [ $? -ne 0 ] ; then endReturn -o 1 "SD card device not found" fi # write image - exe dd bs=4M if="$downImgName" of="$SDDEV" conv=fsync + exe dd bs=8M if="$downImgName" of="$SDDEV" conv=fsync endReturn -o "$?" "Writing image to $SDDEV failed" exe sync @@ -105,15 +154,20 @@ step_2() { } step_3_info() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + echoinfoArgs "[SD CARD DEVICE]" echo "Prepare SD for first run" if [ $CONTEXT_EXE -ne 0 ]; then - shift [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" fi } step_3() { - if [ -z $2 ] && [ ! -z $SDDEV ] ; then + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + + if [ -z $1 ] && [ ! -z $SDDEV ] ; then if [ $QUIET -ne 0 ] ; then answer="n" else @@ -132,7 +186,7 @@ step_3() { esac fi - read_sd_dev "$2" + read_sd_dev "$1" endReturn -o $? "SD card device not found" if [ ! -w "$SDBOOT" ] ; then @@ -151,19 +205,24 @@ step_3() { } step_4_info() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]" echo "Prepare SD card to boot from hard disk" if [ $CONTEXT_EXE -ne 0 ]; then - shift [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" [ ! -z $2 ] && echoinfo " [HD DEVICE]: $2" fi } step_4_alias() { ALIAS="hdboot"; } step_4() { - read_sd_dev "$2" + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + + read_sd_dev "$1" endReturn -o $? "SD detection error $?" - read_hd_dev "$3" + read_hd_dev "$2" endReturn -o $? "HD detection error" echo " [I] SD: $SDDEV" echo " $SDBOOT [$SDBOOTPUUID]" @@ -217,23 +276,28 @@ step_4() { } step_5_info() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]" echo "Prepare HD for boot (TODO)" if [ $CONTEXT_EXE -ne 0 ]; then - shift [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" [ ! -z $2 ] && echoinfo " [HD DEVICE]: $2" fi } step_5() { + # Shift away args + shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $? + #TODO echoerr " [E] Not ready yet...TODO" #return 1 - read_sd_dev "$2" + read_sd_dev "$1" endReturn -o $? "SD detection error $?" - read_hd_dev "$3" + read_hd_dev "$2" endReturn -o $? "HD detection error" echo " [I] SD: $SDDEV" echo " $SDBOOT [$SDBOOTPUUID]"