I use the script bellow to configure my routers every time I do an upgrade of the firmware. I don’t like having a lot of residual files taking up space, and when going from one version to another it is not recommended to save settings when doing an upgrade.
The script is for the S1300, and you will need to read it and go through changing some of the values for your router, but its a good starting point. You can copy individual lines of the script and run them to see what is going on and you can expand the script with other configs you would like. Each config block starts with printl and a comment, so that gives you information what is going on in each block.
The script uses echo
and cat
heredoc for adding lines to config files, and uses sed
to modify lines in config files.
The script formatting is important, don’t change it, especially the EOF lines, they should not have any whitespace before them.
The wireless and network configs contain unique names for the network and wireless only for your router, so you will need to change those as well. Those are the only things that are not “universal” across the routers. All other configs are the same. As config files are stored in /etc/config/
, you can open those files and see what your current config is, then copy it to the corresponding place in the script.
After you have made your modifications, run the script by just copying it and pasting it into your SSH window. After the router reboots, the new config will be active. If something goes wrong while you experiment, you can always follow the debrick guide.
# Gl-iNet Configurator v1.0 - © Johnex 2021
# =========================================
cat<<'SEOF' | ash
#!/bin/sh
#=====================#
#=|-----------------|=#
#=| |=#
#=| FUNCTIONS |=#
#=| |=#
#=|-----------------|=#
#=====================#
printh()
{
line='~~~~~~~~~~~~~~~~~~~~~~~~~'
echo -e "\n \033[0;96m$1\033[0m\n ${line::${#1}}\n"
}
printl()
{
echo -e "\n \033[0;96m$1\033[0m"
}
#================#
#=|------------|=#
#=| |=#
#=| MAIN |=#
#=| |=#
#=|------------|=#
#================#
echo -e "\n \033[0;97mGl-iNet Configurator v1.0 - © Johnex 2021\n =========================================033[0m"
printh 'Install apps'
opkg update
opkg install htop nano openssh-sftp-server sudo
printl 'Configuring Sudo'
sed -i 's/# %sudo.ALL=(ALL) ALL/%sudo ALL=(ALL) ALL/g' /etc/sudoers
sed -i 's/# Defaults targetpw/Defaults targetpw/g' /etc/sudoers
sed -i 's/# ALL ALL=(ALL) ALL/ALL ALL=(ALL) ALL/g' /etc/sudoers
printh 'Creating Users'
echo 'USERNAME:p:16666:0:99999:7:::' >> /etc/shadow
echo 'USERNAME:x:1000:1000:USERNAME:/home/USERNAME:/bin/ash' >> /etc/passwd
echo -e "PASSWORD\nPASSWORD\n" | passwd USERNAME
printl 'Created Groups'
echo 'sudo:x:27:USERNAME' >> /etc/group
echo 'USERNAME:x:1000:' >> /etc/group
printl 'Created Home Directories'
mkdir -p /home/USERNAME
chown USERNAME /home/USERNAME
printl 'Disabled Root SSH'
sed -i "s/option RootPasswordAuth 'on'/option RootPasswordAuth 'off'/g" /etc/config/dropbear
printl 'Configured Network'
sed -i "s/'192.168.8.1'/'10.5.0.1'/g" /etc/config/network
printl 'Static IPs Set'
cat<<'EOF' >> /etc/config/dhcp
config host 'aa22aa22aa22'
option mac 'AA:22:AA:22:AA:22'
option ip '10.5.0.2'
option name 'DEVICE1'
config host 'bb33bb33bb33'
option mac 'BB:33:BB:33:BB:33'
option ip '10.5.0.2'
option name 'DEVICE2'
EOF
printl 'Configured Virtual Server'
cat<<'EOF' >> /etc/config/firewall
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp'
option src_dport '22'
option dest_ip '10.5.0.1'
option dest_port '22'
option name 'SSH'
option reflection '1'
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp'
option src_dport '8080'
option dest_ip '10.5.0.1'
option dest_port '8080'
option name 'WebServer'
option reflection '1'
EOF
printl 'Configured Wireguard'
cat<<'EOF' > /etc/config/wireguard_server
config servers
option local_ip '10.0.0.1'
option private_key 'ouhdafhoug80tr7asdbj74ggahdfbjhhquafbt8abg='
option public_key 'ojibjahbfkmnhnjuuasdvFnkyojhasvhdbhnkhihadg='
option local_port 'SERVER_PORT'
option enable '0'
config peers 'wg_peer_5296'
option name 'CLIENT1'
option client_key 'hurhhbsdfkHBSbkhgroufb4ruhd834hsdfugg4wtsdbj='
option private_key 'nkleasjforegabnasyigfwohrynhklja794w86jlnbj='
option client_ip '10.0.0.2/32'
config peers 'wg_peer_8352'
option name 'CLIENT2'
option client_key 'knhbvawuvthiptbhyuv68q8304t6nipjbasyifygafuh='
option private_key '7912gy43bhkwefviytfauopjybjoauvdutfqpiynhpi='
option client_ip '10.0.0.3/32'
EOF
printl 'Configured Wireless'
sed -i "s/'DE'/'US'/g" /etc/config/wireless
sed -i "s/'18'/'25'/g" /etc/config/wireless
sed -i "s/'19'/'25'/g" /etc/config/wireless
sed -i "s/'GL-S1300-418'/'AP_NAME'/g" /etc/config/wireless
sed -i "s/'GL-S1300-418-5G'/'AP_NAME'/g" /etc/config/wireless
sed -i "s/'GL-S1300-418-Guest'/'AP_NAME-Guest'/g" /etc/config/wireless
sed -i "s/'GL-S1300-418-Guest-5G'/'AP_NAME-Guest'/g" /etc/config/wireless
sed -i "s/'goodlife'/'AP_PASSWORD'/g" /etc/config/wireless
printl 'Configured Hostname'
sed -i "s/'console.gl-inet.com'/'NETWORKNAME'/g" /etc/config/dhcp
printl 'Replaced S1300 Name'
sed -i "s/'GL-S1300'/'NETWORKNAME'/g" /etc/config/system
sed -i "s/'GL-S1300-418'/'NETWORKNAME'/g" /etc/config/network
sed -i "s/'GL-S1300'/'NETWORKNAME'/g" /etc/config/samba
sed -i "s/'GL-S1300-418'/'NETWORKNAME'/g" /etc/config/samba
printl 'Replaced Banner'
cat<<'EOF' > /etc/banner
_____ __ __ __ _ __
| __|| | _ |__|| \| |.-----.| |__
| | || |__ |_|| || || -__|| __|
|_____||_____| |__||_|\__||_____||_____|
www.gl-inet.com
------------------------------------------
GL-S1300 v3.1 | OpenWrt 15.05.1
------------------------------------------
EOF
echo -e '\n \033[0;92mDone, Rebooting\033[0m\n'
reboot
SEOF