Last active
March 18, 2025 12:18
-
-
Save NotYusta/0d669bd57bfc67a56c8f1f18941a2b9a to your computer and use it in GitHub Desktop.
RC Local
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Detect system type | |
if command -v dnf >/dev/null 2>&1; then | |
OS="rhel" | |
RC_LOCAL="/etc/rc.d/rc.local" | |
elif command -v apt >/dev/null 2>&1; then | |
OS="debian" | |
RC_LOCAL="/etc/rc.local" | |
else | |
echo "Unsupported OS" | |
exit 1 | |
fi | |
# Ensure rc.local exists | |
if [ ! -f "$RC_LOCAL" ]; then | |
echo '#!/bin/sh -e' | sudo tee "$RC_LOCAL" | |
echo "exit 0" | sudo tee -a "$RC_LOCAL" | |
fi | |
# Add firewall script if not already present | |
if ! grep -q "bash /root/firewall.sh" "$RC_LOCAL"; then | |
sudo sed -i "/^exit 0/i bash /root/firewall.sh" "$RC_LOCAL" | |
fi | |
# Set executable permission | |
chmod +x "$RC_LOCAL" | |
sleep 1s | |
# Enable rc-local service | |
systemctl enable rc-local --now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment