This commit is contained in:
BlwAvg
2025-02-27 13:02:14 -07:00
parent 023fb4b68b
commit 5d96a8060f
2 changed files with 11 additions and 24 deletions

View File

@@ -14,22 +14,20 @@ start() {
if [ -e /boot/eth.nodhcp ]
then
[ -e /boot/eth.nodhcp ] &&
cat /boot/eth.nodhcp | while read inet gw
do
while read -r inet gw; do
addr=${inet%/*}
netid=${inet#*/}
[ -z $gw ] &&
gw=$( echo $addr| ( IFS='.' read a b c d; echo $((
(((((($a<<8)+$b)<<8)+$c)<<8)+$d)
& (((1<<$netid)-1)<<(32-$netid))
))
)) &&
gw=$(($gw>>24&0xff)).$(($gw>>16&0xff)).$(($gw>>8&0xff)).$((1+( $gw>>0&0xff )))
if [ -z "$gw" ]; then
IFS='.' read -r a b c d <<< "$addr"
gw=$(( (((((($a << 8) + $b) << 8) + $c) << 8) + $d) & (((1 << $netid) - 1) << (32 - $netid)) ))
gw=$(( (gw >> 24) & 0xff )).$(( (gw >> 16) & 0xff )).$(( (gw >> 8) & 0xff )).$(( 1 + (gw & 0xff) ))
fi
arping -Dqc2 -Ieth0 $addr || continue
ip a add $inet brd + dev eth0
ip r add default via $gw dev eth0
cat > /etc/resolve.conf << EOF
cat > /etc/resolv.conf << EOF
nameserver $gw
nameserver 8.8.8.8
nameserver 114.114.114.114
@@ -53,7 +51,7 @@ EOF
}
stop() {
[[ ! -e "/run/udhcpc.eth0.pid" ]] && echo "udhcpc is not running..." && exit 1
kill `cat /run/udhcpc.eth0.pid`
kill "$(cat /run/udhcpc.eth0.pid)"
rm /run/udhcpc.eth0.pid
}

View File

@@ -12,18 +12,11 @@ PIDFILE="/var/run/sshd.pid"
umask 077
startssh() {
# Generate keys if missing
# Generate SSH keys if they do not exist
[ ! -f /etc/ssh/ssh_host_rsa_key ] && /usr/bin/ssh-keygen -A
# Prevent multiple instances using PID check
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then
echo "sshd already running"
exit 0
fi
printf "Starting sshd: "
/usr/sbin/sshd
echo $! > "$PIDFILE" # Store the PID of sshd
touch /var/lock/sshd
echo "OK"
}
@@ -44,9 +37,7 @@ start() {
stop() {
printf "Stopping sshd: "
if [ -f "$PIDFILE" ]; then
kill "$(cat "$PIDFILE")" 2>/dev/null && rm -f "$PIDFILE"
fi
killall sshd 2>/dev/null
rm -f /var/lock/sshd
echo "OK"
}
@@ -67,12 +58,10 @@ case "$1" in
restart
;;
permanent_on)
[ ! -e /etc/kvm/ssh_stop ] && { echo "SSH is already enabled"; exit 0; }
rm -f /etc/kvm/ssh_stop
start
;;
permanent_off)
[ -e /etc/kvm/ssh_stop ] && { echo "SSH is already disabled"; exit 0; }
touch /etc/kvm/ssh_stop
stop
;;