Support to download OS 64 bit version

This commit is contained in:
2022-02-06 15:04:40 +01:00
parent 839d42c39b
commit dfa5804316

View File

@@ -14,6 +14,11 @@ distName=
RPI_BOOT_CONFIG="/boot/config.txt" RPI_BOOT_CONFIG="/boot/config.txt"
step_config() { 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 if [ "$(which lsb_release)" == "" ] ; then
echoerr " [W] Cannot detect OS. Assuming Ubuntu" echoerr " [W] Cannot detect OS. Assuming Ubuntu"
osName="Ubuntu" osName="Ubuntu"
@@ -27,9 +32,12 @@ step_config() {
osName="Ubuntu" osName="Ubuntu"
fi fi
echo " [I] Detected OS: $osName $distName" echoseq " Detected OS: $osName $distName"
echoseq " Requested CPU Architecture: $PIARCH"
} }
PIARCH=armhf
PIDOWNURL=
SDDEV= SDDEV=
SDBOOT= SDBOOT=
SDBOOTPUUID= SDBOOTPUUID=
@@ -42,35 +50,76 @@ HDROOTPUUID=
HDSWAP= HDSWAP=
HDSWAPPUUID= HDSWAPPUUID=
step_1_info() { echo "Download latest Raspberry Pi OS lite image from" evalArgs() {
echoinfo "$downUrl"; } 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_alias() { ALIAS="setup"; }
step_1() { step_1() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
if [ ! -f "$downLoc" ] ; then if [ ! -f "$downLoc" ] ; then
exe wget "$downUrl" -O "$downLoc" exe wget "$PIDOWNURL" -O "$downLoc"
echo -ne " [I] sha256 sum of download:\n " echo -ne " [I] sha256 sum of download:\n "
exe sha256sum "$downLoc" exe sha256sum "$downLoc"
fi fi
downImgName="${downDir}/$(zipinfo -1 "$downLoc")" downImgName="${downDir}/$(zipinfo -1 "$downLoc")"
if [ ! -f "$downImgName" ] ; then if [ ! -f "$downImgName" ] ; then
exe unzip "$downLoc" -d "$downDir" exe unzip "$downLoc" -d "$downDir"
endReturn -o $? "Unzip raspios image failed" endReturn -o $? "Unzip raspios image $PIARCH failed"
fi fi
} }
downUrl="https://downloads.raspberrypi.org/raspios_lite_armhf_latest"
downImgName="" downImgName=""
downDay=$(date +%Y%m%d) downDay=$(date +%Y%m%d)
downDir="/tmp" downDir="/tmp"
downLoc="${downDir}/raspios_$downDay.zip" downLoc="${downDir}/raspios_$downDay.zip"
step_2_info() { 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" echo "Write Raspberry Pi OS image to SD card"
echoinfo "This operation will delete all data previously on the 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_alias() { ALIAS="writesd"; }
step_2() { step_2() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
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
@@ -83,14 +132,14 @@ step_2() {
endReturn -o 1 "No root" endReturn -o 1 "No root"
fi fi
read_sd_dev "$2" read_sd_dev "$1"
# check if device was confirmed # check if device was confirmed
if [ $? -ne 0 ] ; then if [ $? -ne 0 ] ; then
endReturn -o 1 "SD card device not found" endReturn -o 1 "SD card device not found"
fi fi
# write image # 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" endReturn -o "$?" "Writing image to $SDDEV failed"
exe sync exe sync
@@ -105,15 +154,20 @@ step_2() {
} }
step_3_info() { step_3_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
echoinfoArgs "[SD CARD DEVICE]" echoinfoArgs "[SD CARD DEVICE]"
echo "Prepare SD for first run" echo "Prepare SD for first run"
if [ $CONTEXT_EXE -ne 0 ]; then if [ $CONTEXT_EXE -ne 0 ]; then
shift
[ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
fi fi
} }
step_3() { 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 if [ $QUIET -ne 0 ] ; then
answer="n" answer="n"
else else
@@ -132,7 +186,7 @@ step_3() {
esac esac
fi fi
read_sd_dev "$2" read_sd_dev "$1"
endReturn -o $? "SD card device not found" endReturn -o $? "SD card device not found"
if [ ! -w "$SDBOOT" ] ; then if [ ! -w "$SDBOOT" ] ; then
@@ -151,19 +205,24 @@ step_3() {
} }
step_4_info() { step_4_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]" echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]"
echo "Prepare SD card to boot from hard disk" echo "Prepare SD card to boot from hard disk"
if [ $CONTEXT_EXE -ne 0 ]; then if [ $CONTEXT_EXE -ne 0 ]; then
shift
[ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
[ ! -z $2 ] && echoinfo " [HD DEVICE]: $2" [ ! -z $2 ] && echoinfo " [HD DEVICE]: $2"
fi fi
} }
step_4_alias() { ALIAS="hdboot"; } step_4_alias() { ALIAS="hdboot"; }
step_4() { step_4() {
read_sd_dev "$2" # Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
read_sd_dev "$1"
endReturn -o $? "SD detection error $?" endReturn -o $? "SD detection error $?"
read_hd_dev "$3" read_hd_dev "$2"
endReturn -o $? "HD detection error" endReturn -o $? "HD detection error"
echo " [I] SD: $SDDEV" echo " [I] SD: $SDDEV"
echo " $SDBOOT [$SDBOOTPUUID]" echo " $SDBOOT [$SDBOOTPUUID]"
@@ -217,23 +276,28 @@ step_4() {
} }
step_5_info() { step_5_info() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]" echoinfoArgs "[SD CARD DEVICE] [HD DEVICE]"
echo "Prepare HD for boot (TODO)" echo "Prepare HD for boot (TODO)"
if [ $CONTEXT_EXE -ne 0 ]; then if [ $CONTEXT_EXE -ne 0 ]; then
shift
[ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1" [ ! -z $1 ] && echoinfo " [SD CARD DEVICE]: $1"
[ ! -z $2 ] && echoinfo " [HD DEVICE]: $2" [ ! -z $2 ] && echoinfo " [HD DEVICE]: $2"
fi fi
} }
step_5() { step_5() {
# Shift away args
shift; local lArgs=( "$@" ); evalArgs "${lArgs[@]}"; shift $?
#TODO #TODO
echoerr " [E] Not ready yet...TODO" echoerr " [E] Not ready yet...TODO"
#return 1 #return 1
read_sd_dev "$2" read_sd_dev "$1"
endReturn -o $? "SD detection error $?" endReturn -o $? "SD detection error $?"
read_hd_dev "$3" read_hd_dev "$2"
endReturn -o $? "HD detection error" endReturn -o $? "HD detection error"
echo " [I] SD: $SDDEV" echo " [I] SD: $SDDEV"
echo " $SDBOOT [$SDBOOTPUUID]" echo " $SDBOOT [$SDBOOTPUUID]"