implemented basic structure and check()-method

This commit is contained in:
2026-01-29 16:36:19 +01:00
parent 6aa7035804
commit 143d5fd470

View File

@@ -1,4 +1,85 @@
#!/bin/bash #!/bin/bash
echo "currently not implemented" allow_mac(){
echo "Allowing $MAC"
exit 0
}
check(){
if command -v iptables &>/dev/null
then
echo "iptables is installed. Check passed. Bye."
exit 0;
else
echo "Please install iptables."
while [[ -z "$HAD_BEST_SUCCESS" ]]; do
read -p "Install now? [y/N] " QUESTION
if [[ -z "$QUESTION" ]] || [[ "$QUESTION" = "n" ]] || [[ "$QUESTION" = "N" ]]; then
echo "Alright, bye."
exit 0;
fi
if [[ "$QUESTION" = "y" ]] || [[ "$QUESTION" = "Y" ]]; then
HAD_BEST_SUCCESS="true"
echo "Trying to install iptables..."
if command -v apt &>/dev/null
then
sudo apt update
sudo apt install iptables -y
echo "Attempted to install iptables. Please execute the check again. Bye."
exit 0;
fi
if command -v dnf &>/dev/null
then
sudo dnf update
sudo dnf install iptables -y
echo "Attempted to install iptables. Please execute the check again. Bye."
exit 0;
fi
if command -v pacman &>/dev/null
then
sudo pacman -S iptables
echo "Attempted to install iptables. Please execute the check again. Bye."
exit 0;
fi
fi
done
fi
}
deny_mac(){
echo "Denying $MAC"
exit 0
}
show_help(){
echo "-- HELP --"
echo " -a AA:AA:AA:AA:AA:AA | Allow the access for the given mac-address"
echo " -d AA:AA:AA:AA:AA:AA | Deny the access for the given mac-address"
echo " -y | Answer all questions with yes"
echo " -h | Show this help text"
echo " -v | Get Version Info"
echo " -c | Check the usability of this tool"
exit 0
}
while getopts ":a:d:vhyc" opt; do
case $opt in
a) MAC="$OPTARG"; allow_mac ;;
d) MAC="$OPTARG"; deny_mac ;;
v) exit 0 ;;
c) check ;;
h) show_help ;;
y) ALWAYS_YES="1" ;;
\?) echo "Unknown option: -$OPTARG" >&2; exit 1 ;;
:) echo "Option -$OPTARG needs an argument" >&2; exit 1 ;;
esac
done
echo "Nothing to do."
exit 0 exit 0