edited script somewhat

Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-11-14 08:37:50 +01:00
parent d4911108a7
commit dbe9a69fd6
4 changed files with 14 additions and 5 deletions

View File

@ -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"

View File

@ -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" ]

View File

@ -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

View File

@ -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 /"