Files
shell_scripts/openwrt_asus.sh
2024-08-05 23:26:58 +02:00

48 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
usage="USAGE: TL902AC_tftp_recovery.sh <[start | stop]> <complete_path_to_recovery file>"
# OS/System specific variables
tftp_dir=/private/tftpboot/
ethport=en1
# Device specific variables
# TP-Link TL-WR902AC v1
# https://openwrt.org/toh/tp-link/tl-wr902ac_v1
ip_addr=192.168.1.1
subnet=255.255.255.0
tl_wr902ac_filename=openwrt-23.05.2-bcm53xx-generic-asus_rt-ac88u-squashfs.trx
tftp_file_path=$tftp_dir$tl_wr902ac_filename
# If we are starting the tftp Server
if [ $1 = start ]
then
echo Starting recovery mode...
# Check that 2nd argument (recovery image) has been specified (does not validate file)
if [ -z $2 ]
then
echo $usage
else
echo "Copying file $2 to $tftp_file_path."
sudo cp $2 $tftp_file_path
echo "Setting ethernet $ethport to $ip_addr $subnet."
# Set the ethernet interface to the expected tftp server address
sudo ipconfig set $ethport manual $ip_addr $subnet
echo "Starting tftp server."
# Enable the tftp service
sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist
fi
# If we are stopping the tftp Server
elif [ $1 = stop ]
then
echo Stopping... resuming normal mode
# Disable the tftp service
sudo launchctl unload -F /System/Library/LaunchDaemons/tftp.plist
echo "Deleting file $tftp_file_path"
sudo rm $tftp_file_path
echo "Setting ethernet $ethport to DHCP"
# Set the ethernet interface to back to DHCP for normal operation
sudo ipconfig set $ethport dhcp
else
echo $usage
fi