Sequence to setup and install a debian image for a raspberry pi 3b+ or 4
This commit is contained in:
194
seqs/debianrpi.sh
Executable file
194
seqs/debianrpi.sh
Executable file
@@ -0,0 +1,194 @@
|
||||
#!/bin/bash
|
||||
|
||||
#toolName=mytool
|
||||
toolDownSite="https://raspi.debian.net/tested-images"
|
||||
toolDownUrl=
|
||||
toolDownFile=
|
||||
|
||||
SDDEV=
|
||||
SDBOOT=
|
||||
SDBOOTPUUID=
|
||||
SDROOT=
|
||||
SDROOTDEV=
|
||||
SDROOTPUUID=
|
||||
|
||||
# Get script working directory
|
||||
# (when called from a different directory)
|
||||
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
|
||||
CONFIG=0
|
||||
SCRIPT_NAME=$(basename -- $0)
|
||||
SCRIPT_NAME=${SCRIPT_NAME%%.*}
|
||||
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
|
||||
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
|
||||
|
||||
#step_config() {
|
||||
# echo "Called once before executing steps."
|
||||
## e.g. to source a config file manually:
|
||||
#. "$CONFIG_FILE"
|
||||
## or to use sequencer api with global config file:
|
||||
#initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
|
||||
## or to use sequencer api with profile config file support:
|
||||
#initSeqConfig -p "$SCRIPT_NAME" "$CONFIG_FILE_TEMPLATE"
|
||||
#if [ $? -eq 0 ] ; then
|
||||
# CONFIG=1
|
||||
#fi
|
||||
#}
|
||||
|
||||
step_1_info() {
|
||||
echo "Download latest xz-compressed image [IMAGE FILE URL] [SD CARD DEVICE]"
|
||||
echoinfo "$toolDownSite"
|
||||
}
|
||||
step_1_alias() { ALIAS="install"; }
|
||||
step_1() {
|
||||
shift
|
||||
SDDEV="$2"
|
||||
if [ -z "$1" ] && [ $QUIET -eq 0 ] ; then
|
||||
read -p "Provide image download url from $toolDownSite: " toolDownUrl
|
||||
elif [ ! -z "$1" ] ; then
|
||||
toolDownUrl="$1"
|
||||
else
|
||||
echoerr " [E] No image file provided for download"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
toolDownFile="/tmp/${toolDownUrl//*\//}"
|
||||
local downSha256="${toolDownUrl%.img.xz}.xz.sha256"
|
||||
local downShaFile="${toolDownFile%.img.xz}.xz.sha256"
|
||||
|
||||
echo Url: ${toolDownUrl}
|
||||
echo Sha256: $downSha256
|
||||
echo "Files: $toolDownFile"
|
||||
echo " $downShaFile"
|
||||
|
||||
if [ ! -f "$downShaFile" ] ; then
|
||||
exe wget -O "$downShaFile" "$downSha256"
|
||||
endReturn -o $? "Error downloading $downShaFile"
|
||||
fi
|
||||
|
||||
if [ ! -f "$toolDownFile" ] ; then
|
||||
exe wget -O "$toolDownFile" "$toolDownUrl"
|
||||
endReturn -o $? "Error downloading $downDownFile"
|
||||
fi
|
||||
|
||||
echoseq " [I] Checking SHA256 checksum"
|
||||
exe cd $(dirname "$toolDownFile")
|
||||
exe sha256sum -c "$downShaFile" >>/dev/null
|
||||
endReturn -o $? "SHA256 checksum error"
|
||||
}
|
||||
|
||||
step_2_info() { echo "Write image to device [DEVICE]"; }
|
||||
step_2() {
|
||||
shift
|
||||
if [ -z "$SDDEV" ] ; then
|
||||
SDDEV="$1"
|
||||
fi
|
||||
read_sd_dev "$SDDEV"
|
||||
# check if device was confirmed
|
||||
if [ $? -ne 0 ] ; then
|
||||
endReturn -o 1 "SD card device not found"
|
||||
fi
|
||||
|
||||
echoseq " [I] Writing $(basename "$toolDownFile")"
|
||||
exep "xzcat \"$toolDownFile\" | dd of=$SDDEV bs=64k oflag=dsync status=progress"
|
||||
exe sync
|
||||
}
|
||||
|
||||
step_3_info() { echo "Prepare SD card for first run"; }
|
||||
step_3() {
|
||||
outColor green
|
||||
cat <<PREPARE_EOF
|
||||
[I] Setup static IP
|
||||
[etc/network/interfaces.d/eth0]
|
||||
|
||||
#iface eth0 inet dhcp
|
||||
|
||||
iface eth0 inet static
|
||||
address 192.168.23.38/24
|
||||
gateway 192.168.23.1
|
||||
dns-nameserver 192.168.23.20
|
||||
dns-search lan
|
||||
|
||||
iface eth0 inet6 static
|
||||
address fd23::38/72
|
||||
gateway fd23::cece:1eff:fea5:433d/64
|
||||
dns-nameserver fd23::20/72
|
||||
dns-search lan
|
||||
|
||||
[I] Setup dns nameserver
|
||||
[etc/resolv.conf]
|
||||
|
||||
nameserver 192.168.23.20
|
||||
nameserver fd23::20
|
||||
|
||||
[I] Setup root ssh access
|
||||
[etc/ssh/sshd_config]
|
||||
PermitRootLogin yes
|
||||
|
||||
[root/.ssh/authorized_keys]
|
||||
# Root login only possible with an ssh key
|
||||
|
||||
PREPARE_EOF
|
||||
}
|
||||
|
||||
step_10_info() { echo "Essential debian setup"; }
|
||||
step_10_alias() { ALIAS="setup"; }
|
||||
step_10() {
|
||||
if [[ "$(uname)" =~ .*Rasp.* ]] ; then
|
||||
echo Raspi
|
||||
fi
|
||||
}
|
||||
|
||||
read_sd_dev() {
|
||||
local partExt=""
|
||||
if [ ! -z "$1" ] ; then
|
||||
SDBOOT=
|
||||
SDROOT=
|
||||
SDROOTDEV=
|
||||
SDROOTPUUID=
|
||||
SDBOOTPUUID=
|
||||
SDDEV="$1"
|
||||
elif [ -z $SDDEV ] || [ ! -b "$SDDEV" ] ; then
|
||||
SDDEV=
|
||||
SDBOOT=
|
||||
SDROOT=
|
||||
SDROOTDEV=
|
||||
SDBOOTPUUID=
|
||||
SDROOTPUUID=
|
||||
echo " [I] Available devices:"
|
||||
echo
|
||||
exe lsblk -p
|
||||
echo
|
||||
exe read -p "Provide SD card device (e.g. /dev/sdb): " SDDEV
|
||||
fi
|
||||
|
||||
if [ ! -b "$SDDEV" ] ; then
|
||||
echoerr " [I] $SDDEV not a block device"
|
||||
SDDEV=
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ "$SDDEV" =~ .*blk.* ]] ; then
|
||||
partExt="p"
|
||||
fi
|
||||
|
||||
if [ -z $SDBOOT ] ; then
|
||||
SDBOOT=$(findmnt -no TARGET "${SDDEV}${partExt}${SDBOOTPARTNO}")
|
||||
fi
|
||||
if [ -z $SDBOOTPUUID ] ; then
|
||||
IFS=\" read -r _ vPARTUUID _ < <(blkid "${SDDEV}${partExt}${SDBOOTPARTNO}" -s PARTUUID)
|
||||
SDBOOTPUUID=$vPARTUUID
|
||||
fi
|
||||
SDROOTDEV=${SDDEV}${partExt}${SDROOTPARTNO}
|
||||
if [ -z $SDROOT ] ; then
|
||||
SDROOT=$(findmnt -no TARGET "${SDROOTDEV}")
|
||||
fi
|
||||
if [ -z $SDROOTPUUID ] ; then
|
||||
SDROOTPUUID=$(findmnt -no PARTUUID "${SDROOTDEV}")
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
SDBOOTPARTNO=1
|
||||
SDROOTPARTNO=2
|
||||
VERSION_SEQREV=12
|
||||
. /usr/local/bin/sequencer.sh
|
Reference in New Issue
Block a user