#!/bin/bash #toolName=mytool toolDownSite="https://raspi.debian.net/tested-images" toolDownUrl= toolDownFile= toolEssentialDeps="vim bash-completion man-db locales wget" 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 <>/dev/null; echo $?) -eq 0 ] ; then echoseq " [I] Hostname $localHostname already defined" return 0 fi exe hostnamectl set-hostname "$localHostname" endReturn -o $? "Couldn't set hostname" exe sed -i "s/^\(127\.0\.0\.1[[:space:]]*\)\(localhost.*\)/\1\2\n\1$localHostname/" "$hostsLoc" } hostsLoc="/etc/hosts" 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