From 60d68bbbbc76bbfdb02aeb47065800f9e5e71328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mah=C3=A9?= Date: Wed, 10 Apr 2019 11:49:30 +0200 Subject: [PATCH] more compact test and operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - factorize file name (don't repeat yourself®), - sed does not need `-e`: > If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read. - sed does not need `g` (`^#` cannot occur multiple times on the same line), - sed expression, use a space to separate the conditional pattern `/--dport 22 /` from the rest of the expression for clarity --- ssh_on.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ssh_on.sh b/ssh_on.sh index 389503b..310e27f 100644 --- a/ssh_on.sh +++ b/ssh_on.sh @@ -36,11 +36,12 @@ mount | grep "on / .*[(,]ro[,$]" -q && RO_ROOT="true" mv /etc/init.d/_S50sshd /etc/init.d/S50sshd > /dev/null 2>&1 sync [ "$RO_ROOT" == "true" ] && mount / -o remount,ro -if [ -f /media/fat/linux/iptables.up.rules ] -then - sed -e '/--dport 22 /s/^#//g' -i /media/fat/linux/iptables.up.rules -fi + +# start listening port 22 (SSH) +IP_FILTERING="/media/fat/linux/iptables.up.rules" +[[ -f "${IP_FILTERING}" ]] && sed -i '/--dport 22 / s/^#//' "${IP_FILTERING}" sync + if [ -f /etc/network/if-pre-up.d/iptables ] then /etc/network/if-pre-up.d/iptables @@ -50,4 +51,4 @@ fi echo "SSH is on and" echo "active at startup." echo "Done!" -exit 0 \ No newline at end of file +exit 0