mirror of
https://github.com/unifi-utilities/unifios-utilities.git
synced 2024-08-30 18:32:21 +00:00
Add persist-changes script (#401)
This commit is contained in:
parent
7fcb9c77b1
commit
40421d98e5
30
persist-changes/README.md
Normal file
30
persist-changes/README.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Persist changes
|
||||||
|
|
||||||
|
Do you want to make some custom changes to your UDM which Unifi hasn't released yet?
|
||||||
|
Would you like to make some changes that on EdgeOS would be achieved with config.something.yml?
|
||||||
|
|
||||||
|
If you just make changes to the interfaces, Unifi will overwrite what you've done periodically/next time you change something.
|
||||||
|
Luckily we can hook into Unifi's state file and perform the updates immediately afterwards.
|
||||||
|
|
||||||
|
For example, [configuring two IP addresses on your WAN interface, so that you can get to your modem's configuration](https://community.ui.com/questions/Access-modem-connected-to-USG/db5986b8-26cb-4d66-a332-2ace81ac8c4f#answer/7da28d8d-25c8-4ca3-b455-c6eba836f034).
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. [Enable on-boot-script](https://github.com/unifi-utilities/unifios-utilities/blob/main/on-boot-script/README.md)
|
||||||
|
1. Copy `42-watch-for-changes.sh` to `/mnt/data/on_boot.d/`
|
||||||
|
* Check the `FILE` variable, it should point to a file that exists, it might be in `/data` or in `/mnt/data`
|
||||||
|
1. Copy `on-state-change.sh` to `/mnt/data/scripts/`
|
||||||
|
1. Edit `/mnt/data/scripts/on-state-change.sh` to your heart's content
|
||||||
|
|
||||||
|
> Make sure that your script doesn't error in the likely case that it tries to execute an update which has already been made
|
||||||
|
|
||||||
|
## Example: configuring two IP addresses on your WAN interface
|
||||||
|
|
||||||
|
`/mnt/data/scripts/on-state-change.sh`
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# give port9 this IP, allows access to router web interface
|
||||||
|
ip addr add 192.168.0.2/24 dev eth8 || true
|
||||||
|
```
|
41
persist-changes/on_boot.d/42-watch-for-changes.sh
Normal file
41
persist-changes/on_boot.d/42-watch-for-changes.sh
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
EXECUTE01='/mnt/data/scripts/on-state-change.sh'
|
||||||
|
FILE="/data/udapi-config/ubios-udapi-server/ubios-udapi-server.state"
|
||||||
|
# /usr/bin/logger -t "${PROCESSNAME}" "$*"
|
||||||
|
|
||||||
|
# run on boot aswell
|
||||||
|
$EXECUTE01
|
||||||
|
|
||||||
|
if [ "$1" = "DAEMON" ]; then
|
||||||
|
# is this necessary? Add other signals at will (TTIN TTOU INT STOP TSTP)
|
||||||
|
trap '' INT
|
||||||
|
cd /tmp
|
||||||
|
shift
|
||||||
|
### daemonized section ######
|
||||||
|
# RUNNING=`ps aux | grep $CMD | grep -v grep | wc -l`
|
||||||
|
# echo $RUNNING
|
||||||
|
# if [ "$RUNNING" -lt 1 ]; then
|
||||||
|
LAST=`ls -l "$FILE"`
|
||||||
|
# echo $LAST
|
||||||
|
while true; do
|
||||||
|
sleep 1
|
||||||
|
NEW=`ls -l "$FILE"`
|
||||||
|
# echo $NEW
|
||||||
|
if [ "$NEW" != "$LAST" ]; then
|
||||||
|
DATE=`date`
|
||||||
|
echo "${DATE}: Executing ${EXECUTE01}"
|
||||||
|
$EXECUTE01
|
||||||
|
LAST="$NEW"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# fi
|
||||||
|
#### end of daemonized section ####
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
|
||||||
|
umask 022
|
||||||
|
# You can add nice and ionice before nohup but they might not be installed
|
||||||
|
# nohup setsid $0 DAEMON $* 2>/var/log/mydaemon.err >/var/log/mydaemon.log &
|
||||||
|
nohup setsid $0 DAEMON WATCH $* 2>/var/log/watch.err >/var/log/watch.log &
|
3
persist-changes/scripts/on-state-change.sh
Normal file
3
persist-changes/scripts/on-state-change.sh
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# edit this file with your custom instructions...
|
Loading…
x
Reference in New Issue
Block a user