1#!/bin/sh
2#
3# SPDX-License-Identifier: GPL-2.0-only
4#
5
6### BEGIN INIT INFO
7# Provides:          bootmisc
8# Required-Start:    $local_fs mountvirtfs
9# Required-Stop:     $local_fs
10# Default-Start:     S
11# Default-Stop:      0 6
12# Short-Description: Misc and other.
13### END INIT INFO
14
15TIMESTAMP_FILE=/etc/timestamp
16
17. /etc/default/rcS
18[ -f /etc/default/timestamp ] && . /etc/default/timestamp
19#
20# Put a nologin file in /etc to prevent people from logging in before
21# system startup is complete.
22#
23if test "$DELAYLOGIN" = yes
24then
25  echo "System bootup in progress - please wait" > /etc/nologin
26  cp /etc/nologin /etc/nologin.boot
27fi
28
29#
30# Set pseudo-terminal access permissions.
31#
32if test -c /dev/ttyp0
33then
34	chmod 666 /dev/tty[p-za-e][0-9a-f]
35	chown root:tty /dev/tty[p-za-e][0-9a-f]
36fi
37
38#
39# Apply /proc settings if defined
40#
41SYSCTL_CONF="/etc/sysctl.conf"
42if [ -f "${SYSCTL_CONF}" ]
43then
44	if [ -x "/sbin/sysctl" ]
45	then
46		# busybox sysctl does not support -q
47		VERBOSE_REDIR="1>/dev/null"
48		if [ "${VERBOSE}" != "no" ]; then
49			VERBOSE_REDIR="1>&1"
50		fi
51		eval /sbin/sysctl -p "${SYSCTL_CONF}" $VERBOSE_REDIR
52	else
53		echo "To have ${SYSCTL_CONF} applied during boot, install package <procps>."
54	fi
55fi
56
57#
58# Update /etc/motd.
59#
60if test "$EDITMOTD" != no
61then
62	uname -a > /etc/motd.tmp
63	sed 1d /etc/motd >> /etc/motd.tmp
64	mv /etc/motd.tmp /etc/motd
65fi
66
67#
68# This is as good a place as any for a sanity check
69#
70# Set the system clock from hardware clock
71# If the timestamp is more recent than the current time,
72# use the timestamp instead.
73test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh start
74if test -e "$TIMESTAMP_FILE"
75then
76	SYSTEMDATE=`date -u +%4Y%2m%2d%2H%2M%2S`
77	read TIMESTAMP < "$TIMESTAMP_FILE"
78	if [ ${TIMESTAMP} -gt $SYSTEMDATE ]; then
79		# format the timestamp as date expects it (2m2d2H2M4Y.2S)
80		TS_YR=${TIMESTAMP%??????????}
81		TS_SEC=${TIMESTAMP#????????????}
82		TS_FIRST12=${TIMESTAMP%??}
83		TS_MIDDLE8=${TS_FIRST12#????}
84		date -u ${TS_MIDDLE8}${TS_YR}.${TS_SEC}
85		test -x /etc/init.d/hwclock.sh && /etc/init.d/hwclock.sh stop
86	fi
87fi
88: exit 0
89