#!/bin/bash #toolName=mytool readonly toolDownSite="https://raspi.debian.net/tested-images" toolDownUrl= toolDownFile= readonly toolEssentialDeps="vim bash-completion man-db locales wget" SDDEV= SDBOOT= SDBOOTPUUID= SDROOT= SDROOTDEV= SDROOTPUUID= sq_aptOpt= seq_config() { interactive || sq_aptOpt="-y" return 0 } step_1_info() { echo "Download latest xz-compressed image" echoinfo "$toolDownSite" } step_1_options() { echo "[IMAGE FILE URL] [SD CARD DEVICE]"; } step_1_alias() { echo "install"; } step_1() { shift SDDEV="$2" if [ -z "$1" ] && interactive ; then read -p "Provide image download url from $toolDownSite: " toolDownUrl elif [ -n "${1:-}" ] ; then toolDownUrl="$1" else error -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 "Error downloading $downShaFile" fi if [ ! -f "$toolDownFile" ] ; then exe wget -O "$toolDownFile" "$toolDownUrl" endReturn "Error downloading $downDownFile" fi info "Checking SHA256 checksum" exe cd $(dirname "$toolDownFile") exe sha256sum -c "$downShaFile" >>/dev/null endReturn "SHA256 checksum error" } step_2_info() { echo "Write image to device"; } step_2_options() { echo "[DEVICE]"; } step_2() { shift if [ -z "$SDDEV" ] ; then SDDEV="$1" fi read_sd_dev "$SDDEV" # check if device was confirmed endReturn "SD card device not found" info "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() { color green cat <>/dev/null; echo $?) -eq 0 ] ; then info "Hostname $localHostname already defined" return 0 fi exe hostnamectl set-hostname "$localHostname" endReturn "Couldn't set hostname" exe sed -i "s/^\(127\.0\.0\.1[[:space:]]*\)\(localhost.*\)/\1\2\n\1$localHostname/" "$hostsLoc" } hostsLoc="/etc/hosts" step_16_info() { echo "Install cifs mounting requirements"; } step_16_alias() { echo "cifs"; } step_16() { exe apt install cifs-utils ${sq_aptOpt} } step_17_info() { echo "Cifs notes"; } step_17() { color green cat <