init script refactoring

This commit is contained in:
Calin Crisan 2015-11-13 17:35:26 +02:00
parent 2f8a10dcf9
commit 64089ae6bb
33 changed files with 197 additions and 267 deletions

View File

@ -1,44 +0,0 @@
#!/bin/bash
start() {
echo -n "Setting hostname: "
sn=$(cat /sys/class/net/eth0/address | tr -d ':')
sn=${sn: -8}
echo $sn > /var/cache/serial_number
hostname="meye-$sn"
/bin/hostname $hostname
echo "127.0.0.1 localhost $hostname" > /etc/hosts
echo "done"
}
stop() {
echo -n
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

View File

@ -0,0 +1,5 @@
#!/bin/bash
sn=$(cat /sys/class/net/eth0/address | tr -d ':')
echo ${sn: -8}

View File

@ -1,11 +1,11 @@
# <file system> <mount pt> <type> <options> <dump> <pass>
/dev/mmcblk0p1 /boot vfat ro,defaults 0 0
/dev/mmcblk0p3 /data ext4 defaults,noatime 0 0
proc /proc proc defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs mode=0777 0 0
tmpfs /tmp tmpfs mode=1777 0 0
sysfs /sys sysfs defaults 0 0
/dev/mmcblk0p1 /boot vfat ro,defaults 0 0
/dev/mmcblk0p3 /data ext4 defaults,noatime 0 0
/data/output /home/ftp/sdcard rbind rbind 0 0
/data/media /home/ftp/storage rbind rbind 0 0

View File

@ -1,43 +0,0 @@
#!/bin/bash
start() {
echo -n "Setting hostname: "
sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2)
sn=${sn: -8}
echo $sn > /var/cache/serial_number
hostname="meye-$sn"
/bin/hostname $hostname
echo "127.0.0.1 localhost $hostname" > /etc/hosts
echo "done"
}
stop() {
echo -n
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

View File

@ -0,0 +1,94 @@
#!/bin/bash
sys_conf="/etc/os.conf"
conf="/data/etc/os.conf"
if [ -f $sys_conf ] && ! [ -f $conf ]; then
cp $sys_conf $conf
fi
if [ -f $conf ]; then
source $conf
fi
mount_all() {
echo -n "Mounting filesystems: "
/bin/mkdir -p /dev/pts
/bin/mkdir -p /dev/shm
/bin/mount --make-shared /
/bin/mount -a
echo "done"
if [ "$os_debug" == "true" ]; then
echo -n "Remounting boot partition read-write: "
mount -o remount,rw /boot
[ $? == 0 ] && echo "done" || echo "failed"
echo -n "Remounting root partition read-write: "
mount -o remount,rw /
[ $? == 0 ] && echo "done" || echo "failed"
fi
}
unmount_all() {
/bin/umount -a -r
/sbin/swapoff -a
}
set_hostname() {
echo -n "Setting hostname: "
if [ -f /data/etc/hostname ]; then
hostname=$(cat /data/etc/hostname)
else
hostname="$os_prefix-$board_sn"
fi
/bin/hostname $hostname
echo "127.0.0.1 localhost $hostname" > /etc/hosts
echo "done"
}
load_modules() {
echo -n "Loading kernel modules: "
if [ -r /etc/modules ]; then
cat /etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done
fi
if [ -r /data/etc/modules ]; then
cat /data/etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done
fi
echo "done"
}
start() {
mount_all
set_hostname
load_modules
}
stop() {
unmount_all
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit $?

View File

@ -0,0 +1,22 @@
#!/bin/bash
case "$1" in
start)
if [ -r /data/etc/userinit.sh ]; then
echo -n "Executing user init script: "
/bin/bash /data/etc/userinit.sh
echo "done"
fi
;;
stop)
true
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit $?

View File

@ -0,0 +1,4 @@
#!/bin/bash
echo "00000000"

View File

@ -0,0 +1,3 @@
#!/bin/bash

View File

@ -1,31 +1,27 @@
#!/bin/sh
BOOT_LOG=/var/log/boot.log
PID_FILE=/tmp/rc.pid
boot_log=/var/log/boot.log
pid_file=/tmp/rc.pid
echo "---- shutting down ----" >> $BOOT_LOG
source /etc/init.d/vars
source /etc/init.d/functions
# stop all init scripts in /etc/init.d
echo "---- shutting down $os_name $os_version ----" >> $boot_log
# stop all init scripts in /etc/init.d,
# executing them in numerical order.
(for i in /etc/init.d/S??*; do
[ ! -f "$i" ] && continue
[ -f /data/etc/no_$(basename $i) ] && continue
case "$i" in
*.sh) # Source shell script for speed.
(
trap - INT QUIT TSTP
set stop
. $i
)
;;
*) # No sh extension, so fork subprocess.
$i stop
;;
esac
done& echo $! > $PID_FILE) | tee -a $BOOT_LOG &
(
trap - INT QUIT TSTP
set stop
. $i
)
done& echo $! > $pid_file) | tee -a $boot_log &
pid=$(cat $PID_FILE)
pid=$(cat $pid_file)
while kill -0 $pid 2>/dev/null; do
sleep 1
done

View File

@ -1,43 +1,40 @@
#!/bin/sh
BOOT_LOG=/var/log/boot.log
PID_FILE=/tmp/rc.pid
boot_log=/var/log/boot.log
pid_file=/tmp/rc.pid
if ! [ -d /var/log ]; then
# the very first boot won't have the /var/log directory
BOOT_LOG=/tmp/boot.log
TMP_LOG=yes
# at the very first boot,
# we won't have the /var/log directory
boot_log=/tmp/boot.log
tmp_log=yes
fi
echo "---- booting ----" >> $BOOT_LOG
source /etc/init.d/vars
source /etc/init.d/functions
# start all init scripts in /etc/init.d
echo "---- booting $os_name $os_version----" >> $boot_log
# start all init scripts in /etc/init.d,
# executing them in numerical order.
(for i in /etc/init.d/S??*; do
[ ! -f "$i" ] && continue
[ -f /data/etc/no_$(basename $i) ] && continue
case "$i" in
*.sh) # Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*) # No sh extension, so fork subprocess.
$i start
;;
esac
done& echo $! > $PID_FILE) | tee -a $BOOT_LOG &
(
trap - INT QUIT TSTP
set start
. $i
)
done& echo $! > $pid_file) | tee -a $boot_log &
pid=$(cat $PID_FILE)
pid=$(cat $pid_file)
while kill -0 $pid 2>/dev/null; do
sleep 1
done
if [ -n "$TMP_LOG" ]; then
if [ -n "$tmp_log" ]; then
# persist the boot log at first boot
mv $BOOT_LOG /var/log
mv $boot_log /var/log
fi

View File

@ -0,0 +1,6 @@
#!/bin/bash
source /etc/version
board=$(cat /etc/board)
board_sn=$(/etc/init.d/boardsn)

View File

@ -14,16 +14,7 @@
# process == program to run
# Startup the system
null::sysinit:/bin/mount -t proc proc /proc
null::sysinit:/bin/mkdir -p /dev/pts
null::sysinit:/bin/mkdir -p /dev/shm
null::sysinit:/bin/mount --make-shared /
null::sysinit:/bin/mount -a
null::sysinit:/sbin/remountrw
null::sysinit:/sbin/loadmodules
# now run any rc scripts
::sysinit:/etc/init.d/rcS
::sysinit:/sbin/userinit
# Put a getty on the serial port
tty1::respawn:/sbin/getty -L tty1 115200 vt100
@ -34,6 +25,4 @@ tty1::respawn:/sbin/getty -L tty1 115200 vt100
# Stuff to do before rebooting
null::shutdown:/etc/init.d/rcK
null::shutdown:/bin/umount -a -r
null::shutdown:/sbin/swapoff -a

View File

@ -0,0 +1,2 @@
os_debug="false"

View File

@ -0,0 +1,5 @@
os_name="motionEyeOS"
os_short_name="motioneyeos"
os_prefix="meye"
os_version="20151103"

View File

@ -1,12 +0,0 @@
#!/bin/sh
if [ -r /etc/modules ]; then
cat /etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done
fi
if [ -r /data/etc/modules ]; then
cat /data/etc/modules | while read line; do test -n "$line" && /sbin/modprobe $line; done
fi
exit 0

View File

@ -1,19 +0,0 @@
#!/bin/sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin
motioneye_conf=/data/etc/motioneye.conf
test -f $motioneye_conf || exit 0
if grep 'log-level debug' $motioneye_conf >/dev/null; then
echo -n "Remounting boot partition read-write: "
mount -o remount,rw /boot
[ $? == 0 ] && echo "done" || echo "failed"
echo -n "Remounting root partition read-write: "
mount -o remount,rw /
[ $? == 0 ] && echo "done" || echo "failed"
fi
exit 0

View File

@ -1,8 +0,0 @@
#!/bin/sh
if [ -r /data/etc/userinit.sh ]; then
/bin/bash /data/etc/userinit.sh
fi
exit 0

View File

@ -1,43 +0,0 @@
#!/bin/bash
start() {
echo -n "Setting hostname: "
sn=$(cat /sys/class/net/eth0/address | tr -d ':')
sn=${sn: -8}
echo $sn > /var/cache/serial_number
hostname="meye-$sn"
/bin/hostname $hostname
echo "127.0.0.1 localhost $hostname" > /etc/hosts
echo "done"
}
stop() {
echo -n
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

View File

@ -0,0 +1,5 @@
#!/bin/bash
sn=$(cat /sys/class/net/eth0/address | tr -d ':')
echo ${sn: -8}

View File

@ -1,44 +0,0 @@
#!/bin/bash
start() {
echo -n "Setting hostname: "
sn=$(cat /sys/class/net/eth0/address | tr -d ':')
sn=${sn: -8}
echo $sn > /var/cache/serial_number
hostname="meye-$sn"
/bin/hostname $hostname
echo "127.0.0.1 localhost $hostname" > /etc/hosts
echo "done"
}
stop() {
echo -n
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?

View File

@ -0,0 +1,5 @@
#!/bin/bash
sn=$(cat /sys/class/net/eth0/address | tr -d ':')
echo ${sn: -8}

View File

@ -0,0 +1,5 @@
#!/bin/bash
sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2)
echo ${sn: -8}

View File

@ -0,0 +1,5 @@
#!/bin/bash
sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2)
echo ${sn: -8}