mirror of https://github.com/lukechilds/umbrel.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.0 KiB
55 lines
1.0 KiB
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../../..)"
|
|
|
|
source /etc/default/umbrel 2> /dev/null || true
|
|
if [[ -z "${UMBREL_OS:-}" ]]; then
|
|
echo "Exiting iptables setup when not on Umbrel OS"
|
|
exit
|
|
fi
|
|
|
|
delete="false"
|
|
if [[ "${@}" == *"--delete"* ]]; then
|
|
delete="true"
|
|
fi
|
|
|
|
force="false"
|
|
if [[ "${@}" == *"--force"* ]]; then
|
|
force="true"
|
|
fi
|
|
|
|
check_root () {
|
|
if [[ $UID != 0 ]]; then
|
|
echo "This script must be run as root"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
main () {
|
|
check_root
|
|
|
|
# Remove and then re-append iptables rule
|
|
rule=(PREROUTING \
|
|
--table nat \
|
|
--proto tcp \
|
|
--dport 80 \
|
|
--jump REDIRECT \
|
|
--to-port 8000)
|
|
if iptables --delete ${rule[@]} 2> /dev/null; then
|
|
echo "Removed existing iptables entry."
|
|
else
|
|
echo "No existing iptables entry found."
|
|
fi
|
|
if [[ "${delete}" == "false" ]]; then
|
|
position="--append"
|
|
if [[ "${force}" == "true" ]]; then
|
|
position="--insert"
|
|
fi
|
|
iptables "${position}" ${rule[@]}
|
|
echo "Appended new iptables entry."
|
|
fi
|
|
}
|
|
|
|
main
|
|
|