From dbe9a69fd65739ed35ae9afe09f78b618bf94bca Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Tue, 14 Nov 2023 08:37:50 +0100 Subject: [PATCH] edited script somewhat Signed-off-by: Jeroen Oudshoorn --- scripts/backup.sh | 1 + scripts/macos_connection_share.sh | 2 +- scripts/openbsd_connection_share.sh | 4 +++- scripts/restore.sh | 12 +++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/backup.sh b/scripts/backup.sh index 15aa3d8a..dd3f2349 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -61,4 +61,5 @@ ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || { } echo "@ backing up $UNIT_HOSTNAME to $OUTPUT ..." +# shellcheck disable=SC2029 ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo find ${FILES_TO_BACKUP} -type f -print0 | xargs -0 sudo tar cv" | gzip -9 > "$OUTPUT" diff --git a/scripts/macos_connection_share.sh b/scripts/macos_connection_share.sh index d3d8627d..25362e30 100755 --- a/scripts/macos_connection_share.sh +++ b/scripts/macos_connection_share.sh @@ -5,7 +5,7 @@ USB_IFACE='' USB_IP=${2:-10.0.0.1} for i in $(ifconfig -lu); do - if ifconfig $i | grep -q "${USB_IP}" ; then USB_IFACE=$i; fi; + if ifconfig "$i" | grep -q "${USB_IP}" ; then USB_IFACE=$i; fi; done if [ -z "$USB_IFACE" ] diff --git a/scripts/openbsd_connection_share.sh b/scripts/openbsd_connection_share.sh index fd20f44d..07e35354 100644 --- a/scripts/openbsd_connection_share.sh +++ b/scripts/openbsd_connection_share.sh @@ -3,13 +3,15 @@ USB_IFACE=$(ifconfig urndis0 | grep urndis0 | awk '{print $1}' | tr -d ':') USB_IP=${2:-10.0.0.1} +# shellcheck disable=SC2046 if test $(whoami) != root; then doas "$0" "$@" exit $? fi +# shellcheck disable=SC2039 if [ "${USB_IFACE}" == "urndis0" ]; then - ifconfig ${USB_IFACE} ${USB_IP} + ifconfig "${USB_IFACE}" "${USB_IP}" sysctl -w net.inet.ip.forwarding=1 echo "match out on egress inet from ${USB_IFACE}:network to any nat-to (egress:0)" | pfctl -f - pfctl -f /etc/pf.conf diff --git a/scripts/restore.sh b/scripts/restore.sh index d4fb424b..b805a01a 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -27,15 +27,20 @@ done # name of the ethernet gadget interface on the host UNIT_HOSTNAME=${UNIT_HOSTNAME:-10.0.0.2} # output backup tgz file +# shellcheck disable=SC2086 if [ -z $BACKUP ]; then - BACKUP=$(ls -rt ${UNIT_HOSTNAME}-backup-*.tgz 2>/dev/null | tail -n1) - if [ -z $BACKUP ]; then + # shellcheck disable=SC2012 + BACKUP=$(ls -rt "${UNIT_HOSTNAME}"-backup-*.tgz 2>/dev/null | tail -n1) + if [ -z "$BACKUP" ]; then echo "@ Can't find backup file. Please specify one with '-b'" exit 1 fi echo "@ Found backup file:" + # shellcheck disable=SC2028 echo "\t${BACKUP}" + # shellcheck disable=SC2039 echo -n "@ continue restroring this file? (y/n) " + # shellcheck disable=SC2162 read CONTINUE CONTINUE=$(echo "${CONTINUE}" | tr "[:upper:]" "[:lower:]") if [ "${CONTINUE}" != "y" ]; then @@ -51,4 +56,5 @@ ping -c 1 "${UNIT_HOSTNAME}" > /dev/null 2>&1 || { } echo "@ restoring $BACKUP to $UNIT_HOSTNAME ..." -cat ${BACKUP} | ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo tar xzv -C /" +# shellcheck disable=SC2002 +cat "${BACKUP}" | ssh "${UNIT_USERNAME}@${UNIT_HOSTNAME}" "sudo tar xzv -C /"