Hope you can help...
I have a script that will be used to create firewalld rules depending on the chosen function. What I would like to know is it it possible to call a function from the commandline
E.G ./script.sh web
#!/usr/bin/env bash
set -e
### Set IP ###
## Set Ports ###
CHAT=3000
HTTP=80
HTTPS=443
DNS=53
SSH=22
SMTP=25
MONGO=27017
NFS=111
GMAIL=587
### check for Root user ###
if [ "$(whoami)" == "root" ] ; then
echo "you are root"
else
echo "you are not root, This script must be run as root"
exit 1
fi
### Error Checking ###
error_check() {
if [ $? -eq 0 ]; then
echo "$(tput setaf 2) [ OK ] $(tput sgr0)"
sleep 2
else
echo "$(tput setaf 1) [ FAILED ] $(tput sgr0)"
exit 1
fi
}
### No command line arguments ###
if [[ $# -eq 0 ]] ; then
echo -e "\nUsage: $0 web nfs mail \n"
exit 0
fi
### Check which firewall is running ###
firewalld=`systemctl list-unit-files | grep firewalld | awk {'print $2'}`
iptables=`systemctl list-unit-files | grep iptables | awk {'print $2'}`
if [[ ${firewalld} == "enabled" ]]; then
echo "FirewallD is enabled.."
else
echo "Checking if iptables is enabled.."
if [[ ${iptables} == "enabled" ]]; then
echo "iptables is enabled.....Disabling"
systemctl stop iptables
systemctl disable iptables
echo "Starting FirewallD"
systemctl enable firewalld
systemctl start firewalld
echo "FirewallD is now enabled"
fi
fi
web() {
firewall-cmd --zone=public --add-port=${HTTP} --permanent
firewall-cmd --zone=public --add-port=${HTTPS} --permanent
sudo firewall-cmd --reload
}
This is not the finished article but a long shot, but any help getting over this hurdle would be great.
Thanks :D