#! /bin/sh -
#
# Single-user mode script
#
# Copyright (c) 2018, 2020 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

RC="[${0##*/}]"	# To reflect the name of the script between [].
IFS='
 	'
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
LC_ALL=C

echo ""
echo "Entering to single-user mode ..."

# Stop any quota file system (if needed)

if grep -E -q -m 1 '(usr|grp)quota' /etc/fstab
then
    echo "${RC}: Setting any quota file system to OFF"
    quotaoff -va
fi

# Be immune to the following signals
trap "" HUP INT QUIT ABRT TERM

echo "${RC}: Sending the HUP signal to all the processes"
killall5 -1 -o $$
sleep 7

echo "${RC}: Sending the TERM signal to all the processes"
killall5 -15 -o $$
sleep 9

exec telinit 1

