Compare commits
No commits in common. "master" and "1.5.3" have entirely different histories.
14
Makefile
14
Makefile
@ -3,19 +3,15 @@
|
|||||||
# Please modify config.mk and not this
|
# Please modify config.mk and not this
|
||||||
sinclude config.mk
|
sinclude config.mk
|
||||||
|
|
||||||
.PHONY: clean install uninstall all tools
|
.PHONY: clean install uninstall all
|
||||||
|
|
||||||
build: rc tools
|
build: rc
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
tools:
|
|
||||||
make -C tools
|
|
||||||
|
|
||||||
rc: rc.in
|
rc: rc.in
|
||||||
sed -r \
|
sed -r \
|
||||||
-e 's%@ETC@%$(ETC)%' \
|
-e 's%@ETC@%$(ETC)%' \
|
||||||
-e 's%@BASH_PATH@%$(BASH_PATH)%' \
|
|
||||||
rc.in > rc
|
rc.in > rc
|
||||||
|
|
||||||
chmod 750 $@
|
chmod 750 $@
|
||||||
@ -23,8 +19,6 @@ rc: rc.in
|
|||||||
clean:
|
clean:
|
||||||
rm rc
|
rm rc
|
||||||
|
|
||||||
make -C tools clean
|
|
||||||
|
|
||||||
install: build
|
install: build
|
||||||
install -dm755 $(BINDIR)
|
install -dm755 $(BINDIR)
|
||||||
install -dm755 $(ETCDIR)
|
install -dm755 $(ETCDIR)
|
||||||
@ -35,9 +29,5 @@ install: build
|
|||||||
|
|
||||||
install -m755 tools/killall5 $(BINDIR)/killall5
|
install -m755 tools/killall5 $(BINDIR)/killall5
|
||||||
|
|
||||||
make -C tools install
|
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm $(BINDIR)/rc
|
rm $(BINDIR)/rc
|
||||||
|
|
||||||
make -C tools uninstall
|
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
# spark-rc
|
spark-rc
|
||||||
|
========
|
||||||
|
|
||||||
A simple rc script to kickstart your system.
|
A simple rc script to kickstart your system.
|
||||||
|
|
||||||
## depends
|
|
||||||
|
|
||||||
* Enabled sysrq or halt from suckless.org's ubase.
|
|
||||||
* /proc support.
|
|
||||||
|
@ -4,7 +4,5 @@ USR ?= /usr/local
|
|||||||
ETC ?= /etc
|
ETC ?= /etc
|
||||||
BIN ?= $(USR)/bin
|
BIN ?= $(USR)/bin
|
||||||
|
|
||||||
BASH_PATH ?= /bin/bash
|
|
||||||
|
|
||||||
BINDIR = $(DESTDIR)$(PREFIX)$(BIN)
|
BINDIR = $(DESTDIR)$(PREFIX)$(BIN)
|
||||||
ETCDIR = $(DESTDIR)$(PREFIX)$(ETC)
|
ETCDIR = $(DESTDIR)$(PREFIX)$(ETC)
|
||||||
|
47
rc.conf
47
rc.conf
@ -1,48 +1,21 @@
|
|||||||
# A default PATH
|
# System-wide configuration
|
||||||
export PATH='/usr/local/bin:/usr/local/sbin:/usr/bin'
|
export PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
|
||||||
|
|
||||||
# Locale
|
|
||||||
export LC_ALL='en_US.UTF-8'
|
|
||||||
|
|
||||||
# Hostname
|
# Hostname
|
||||||
cfg_hostname='spark'
|
cfg_hostname='changeme'
|
||||||
|
|
||||||
# Timezone
|
# Timezone
|
||||||
# Uncomment and change this to yours
|
# Change this to yours
|
||||||
#cfg_timezone='Europe/Moscow'
|
#cfg_timezone='Europe/Moscow'
|
||||||
|
|
||||||
# Early fsck, if you don't have such a step in your initrd
|
# Services
|
||||||
cfg_early_fsck=1
|
cfg_services+=( 'fsck' 'mount' 'systemd-udevd' 'sysctl' ) # Services that need tp be started in an order
|
||||||
|
cfg_services+=( '@lo.iface' '@crond' '@dbus' '@alsa' ) # These start in parallel.
|
||||||
|
cfg_services+=( @agetty-tty{2..6} ) # Comment this if your init starts something on the ttys itself.
|
||||||
|
cfg_services+=( 'rc.local' ) # Traditionally, rc.local starts last. Technically here it doesn't. Not quite :)
|
||||||
|
|
||||||
# Services that start with @ are executed in parallel
|
# Add modules you want to be loaded at boot time here
|
||||||
cfg_services+=(
|
|
||||||
'mount' 'sysctl' 'rsyslogd'
|
|
||||||
'@lo.iface' '@scron' @agetty-tty{2..6}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Uncomment and add modules you want to be loaded at boot time here
|
|
||||||
#cfg_modules=( )
|
#cfg_modules=( )
|
||||||
|
|
||||||
# Make C-A-D perform a soft reset
|
# Make C-A-D perform a soft reset
|
||||||
ctrlaltdel soft
|
ctrlaltdel soft
|
||||||
|
|
||||||
# Virtual filesystems
|
|
||||||
cfg_mounts=(
|
|
||||||
'run:tmpfs:/run'
|
|
||||||
'tmp:tmpfs:/tmp'
|
|
||||||
|
|
||||||
'proc:proc:/proc:defaults,hidepid=2'
|
|
||||||
'sys:sysfs:/sys'
|
|
||||||
|
|
||||||
'dev:devtmpfs:/dev'
|
|
||||||
'pts:devpts:/dev/pts:noexec,nosuid,gid=5,mode=0620'
|
|
||||||
'mqueue:mqueue:/dev/mqueue:noexec,nosuid,nodev'
|
|
||||||
'shm:tmpfs:/dev/shm:defaults,mode=0777'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Some temporary directories and files
|
|
||||||
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
|
||||||
cfg_tmpfiles+=( '/run/utmp' )
|
|
||||||
|
|
||||||
# How long do we wait for all processes to die nicely?
|
|
||||||
cfg_killall5_timeout=30
|
|
||||||
|
111
rc.in
Normal file → Executable file
111
rc.in
Normal file → Executable file
@ -1,5 +1,18 @@
|
|||||||
#!@BASH_PATH@
|
#!/bin/bash
|
||||||
# vim: ft=zsh
|
|
||||||
|
# Default virtual mounts for linux systems
|
||||||
|
cfg_mounts+=( 'proc:proc:/proc:' )
|
||||||
|
cfg_mounts+=( 'run:tmpfs:/run:' )
|
||||||
|
cfg_mounts+=( 'sys:sysfs:/sys:' )
|
||||||
|
|
||||||
|
# devfs and its children
|
||||||
|
cfg_mounts+=( 'dev:devtmpfs:/dev:' )
|
||||||
|
cfg_mounts+=( 'pts:devpts:/dev/pts:noexec,nosuid,gid=5,mode=0620' )
|
||||||
|
cfg_mounts+=( 'mqueue:mqueue:/dev/mqueue:noexec,nosuid,nodev' )
|
||||||
|
cfg_mounts+=( 'shm:tmpfs:/dev/shm:defaults,mode=0777' )
|
||||||
|
|
||||||
|
# Some temporary directories
|
||||||
|
cfg_tmpdirs+=( '/run/lock' '/run/lock/lvm' '/run/lvm' '/run/user' )
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
|
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
|
||||||
@ -7,45 +20,27 @@ rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
|
|||||||
rc.motd() {
|
rc.motd() {
|
||||||
[[ -f "/etc/rc.motd" ]] && {
|
[[ -f "/etc/rc.motd" ]] && {
|
||||||
while read; do
|
while read; do
|
||||||
printf "%s\n" "$REPLY"
|
printf "$REPLY"
|
||||||
done < "/etc/rc.motd"
|
done < "/etc/rc.motd"
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.tmpfiles() {
|
rc.tmpdirs() {
|
||||||
printf '%s\n' "${cfg_tmpdirs[@]}" | while IFS=':' read dir perm own grp; do
|
mkdir -p -m0755 "${cfg_tmpdirs[@]}"
|
||||||
mkdir -pm "${perm:-755}" "$dir"
|
|
||||||
chown -c "${own:-root}:${grp:-root}" "$dir"
|
|
||||||
done
|
|
||||||
|
|
||||||
printf '%s\n' "${cfg_tmpfiles[@]}" | while IFS=':' read file perm own grp; do
|
|
||||||
> "$file"
|
|
||||||
chmod -c "${perm:-644}" "$file"
|
|
||||||
chown -c "${own:-root}:${grp:-root}" "$file"
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.mount() {
|
rc.mount_misc() {
|
||||||
for fs in "${cfg_mounts[@]}"; do
|
for m in "${cfg_mounts[@]}"; do
|
||||||
echo "$fs" | while IFS=':' read device fs_type mountpoint mount_options; do
|
IFS=':' read fs fs_type mountpoint mount_options <<< "$m"
|
||||||
if mountpoint -q "$mountpoint"; then
|
|
||||||
if [[ "$mount_options" ]]; then
|
|
||||||
mount -o "remount,$mount_options" "$mountpoint"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
if ! [[ -d "$mountpoint" ]]; then
|
|
||||||
mkdir -p "$mountpoint"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! [[ "$mount_options" ]]; then
|
[[ "$mount_options" ]] || { mount_options='defaults'; }
|
||||||
mount_options='defaults'
|
|
||||||
fi
|
|
||||||
|
|
||||||
mount "$device" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
|
mountpoint -q "$mountpoint" || {
|
||||||
fi
|
[[ -d "$mountpoint" ]] || { mkdir -p "$mountpoint"; }
|
||||||
done
|
mount "$fs" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
|
||||||
|
}
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,15 +96,15 @@ rc.services_stop() {
|
|||||||
|
|
||||||
rc.stop_everything() {
|
rc.stop_everything() {
|
||||||
echo "Politely asking all processes to shut down..."
|
echo "Politely asking all processes to shut down..."
|
||||||
killall5 -s 15 -w "$cfg_killall5_timeout"
|
killall5 -15; sleep 3
|
||||||
|
|
||||||
echo "Killing the remaning ones..."
|
echo "Killing the remaning ones..."
|
||||||
killall5 -s 9
|
killall5 -9
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.unmount_everything() {
|
rc.unmount_everything() {
|
||||||
echo "Unmounting filesystems..."
|
echo "Unmounting filesystems..."
|
||||||
umount -r -a
|
umount -a
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.remount_root() {
|
rc.remount_root() {
|
||||||
@ -118,10 +113,8 @@ rc.remount_root() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc.boot() {
|
rc.boot() {
|
||||||
(( cfg_early_fsck )) && rc.fsck
|
rc.mount_misc
|
||||||
|
rc.tmpdirs
|
||||||
rc.mount
|
|
||||||
rc.tmpfiles
|
|
||||||
rc.hostname
|
rc.hostname
|
||||||
rc.timezone
|
rc.timezone
|
||||||
rc.modules
|
rc.modules
|
||||||
@ -131,33 +124,16 @@ rc.boot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc.halt() {
|
rc.halt() {
|
||||||
if type -P halt &>/dev/null; then
|
|
||||||
function rc.halt_poweroff { halt -p; }
|
|
||||||
function rc.halt_reboot { halt -r; }
|
|
||||||
elif (( $(</proc/sys/kernel/sysrq) )); then
|
|
||||||
function rc.halt_poweroff { echo 'o' > /proc/sysrq-trigger; }
|
|
||||||
function rc.halt_reboot { echo 'b' > /proc/sysrq-trigger; }
|
|
||||||
else
|
|
||||||
printf 'Cannot halt, please install halt from suckless.org ubase or enable sysrq.\n'
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
|
poweroff|shutdown) echo 'o' > /proc/sysrq-trigger;;
|
||||||
halt) :;;
|
halt) :;;
|
||||||
poweroff|shutdown) rc.halt_poweroff;;
|
reboot|*) echo 'b' > /proc/sysrq-trigger;;
|
||||||
reboot|*) rc.halt_reboot;;
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.sync() {
|
|
||||||
echo "Syncing disks."
|
|
||||||
sync
|
|
||||||
}
|
|
||||||
|
|
||||||
rc.shutdown() {
|
rc.shutdown() {
|
||||||
rc.services_stop
|
rc.services_stop
|
||||||
rc.stop_everything
|
rc.stop_everything
|
||||||
rc.sync
|
|
||||||
rc.unmount_everything
|
rc.unmount_everything
|
||||||
rc.remount_root
|
rc.remount_root
|
||||||
|
|
||||||
@ -167,7 +143,6 @@ rc.shutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc.hostname() {
|
rc.hostname() {
|
||||||
[[ -f '/etc/hostname' ]] && { hostname "$(</etc/hostname)"; }
|
|
||||||
[[ "$cfg_hostname" ]] && { hostname "$cfg_hostname"; }
|
[[ "$cfg_hostname" ]] && { hostname "$cfg_hostname"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,32 +158,14 @@ rc.timezone() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.fsck() {
|
|
||||||
declare root_rw=0
|
|
||||||
touch /rc-write-test && root_rw=1
|
|
||||||
(( root_rw )) && mount -o remount,ro /
|
|
||||||
fsck -A -C -p
|
|
||||||
(( root_rw )) && mount -o remount,rw /
|
|
||||||
}
|
|
||||||
|
|
||||||
rc.main() {
|
rc.main() {
|
||||||
source "@ETC@/rc.conf"
|
source "@ETC@/rc.conf"
|
||||||
|
|
||||||
# Default XDG_RUNTIME_DIR for all non-system users
|
|
||||||
# rtkit:x:133:133:RealtimeKit:/proc:/sbin/nologin
|
|
||||||
# Also add one for root
|
|
||||||
cfg_tmpdirs+=( "/run/user/0:700:0:0" )
|
|
||||||
while IFS=':' read -r _ _ uid gid _; do
|
|
||||||
if (( uid >= 1000 )); then
|
|
||||||
cfg_tmpdirs+=( "/run/user/$uid:700:$uid:$gid" )
|
|
||||||
fi
|
|
||||||
done < /etc/passwd
|
|
||||||
|
|
||||||
action="${1:-boot}"
|
action="${1:-boot}"
|
||||||
|
|
||||||
case "$action" in
|
case "$action" in
|
||||||
boot)
|
boot)
|
||||||
echo "Welcome to $(uname -rs)"
|
echo "Welcome to `uname -rs`"
|
||||||
rc.boot
|
rc.boot
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
# spark-rc tools makefile
|
|
||||||
|
|
||||||
# Please modify config.mk and not this
|
|
||||||
sinclude ../config.mk
|
|
||||||
|
|
||||||
.PHONY: clean install uninstall all
|
|
||||||
|
|
||||||
build: killall5
|
|
||||||
|
|
||||||
all: build
|
|
||||||
|
|
||||||
killall5: killall5.in
|
|
||||||
sed -r \
|
|
||||||
-e 's%@BASH_PATH@%$(BASH_PATH)%' \
|
|
||||||
killall5.in > killall5
|
|
||||||
|
|
||||||
chmod 750 $@
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm killall5
|
|
||||||
|
|
||||||
install: build
|
|
||||||
install -dm755 $(BINDIR)
|
|
||||||
install -dm755 $(ETCDIR)
|
|
||||||
|
|
||||||
install -m750 killall5 $(BINDIR)/killall5
|
|
||||||
|
|
||||||
uninstall:
|
|
||||||
rm $(BINDIR)/killall5
|
|
52
tools/killall5.in → tools/killall5
Normal file → Executable file
52
tools/killall5.in → tools/killall5
Normal file → Executable file
@ -1,4 +1,4 @@
|
|||||||
#!@BASH_PATH@
|
#!/usr/bin/env bash
|
||||||
# A simple reimplementation of killall5 from sysvinit-tools
|
# A simple reimplementation of killall5 from sysvinit-tools
|
||||||
|
|
||||||
get_my_tree() {
|
get_my_tree() {
|
||||||
@ -37,60 +37,14 @@ get_procs_to_kill() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
pids_exist() {
|
|
||||||
for i in "$@"; do
|
|
||||||
if [[ -d "/proc/$i" ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_wait() {
|
|
||||||
declare counter
|
|
||||||
|
|
||||||
while pids_exist "$@"; do
|
|
||||||
if (( counter == timeout )); then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
(( counter++ ))
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
timeout=30
|
|
||||||
signal=15
|
|
||||||
|
|
||||||
while (( $# )); do
|
|
||||||
case $1 in
|
|
||||||
-w)
|
|
||||||
flag_wait=1
|
|
||||||
timeout=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
|
|
||||||
-s)
|
|
||||||
signal=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
my_tree=( $(get_my_tree) self thread-self )
|
my_tree=( $(get_my_tree) self thread-self )
|
||||||
all_procs=( $(get_all_procs) )
|
all_procs=( $(get_all_procs) )
|
||||||
procs_to_kill=( $(get_procs_to_kill) )
|
procs_to_kill=( $(get_procs_to_kill) )
|
||||||
|
|
||||||
kill -n "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
signal="${1:-"-15"}"
|
||||||
|
|
||||||
if (( flag_wait )); then
|
kill "$signal" "${procs_to_kill[@]}" 2>/dev/null
|
||||||
pid_wait "${procs_to_kill[@]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user