15 Commits

Author SHA1 Message Date
fbt
58054382e2 null the type output
Signed-off-by: fbt <fbt@fleshless.org>
2016-03-26 18:13:47 +03:00
fbt
04ff160a7d better sysrq test
Signed-off-by: fbt <fbt@fleshless.org>
2016-03-26 17:52:27 +03:00
fbt
409f6f8cd2 Merge branch 'master' of builder:git/spark-rc 2016-03-25 12:31:32 +03:00
fbt
ff28e04a20 use halt if available 2016-03-25 12:31:12 +03:00
fbt
e2b068e45d vim modeline 2015-11-04 21:06:19 +03:00
fbt
0afbcc55f2 rc.mount rewrite 2015-10-27 18:43:56 +03:00
fbt
1d5e825201 a huge oops 2015-10-26 19:16:18 +03:00
fbt
15592c0daa this should be a decent default 2015-10-14 10:03:58 +03:00
fbt
e379e8efff set the locale in rc.conf 2015-10-13 11:23:10 +03:00
fbt
9363ea33f5 agettys 2015-09-07 23:01:14 +03:00
fbt
92b8205255 on a second thought, the default IFS sucks 2015-09-01 13:05:37 +03:00
fbt
5dad6a777e default IFS, add tmp 2015-09-01 13:02:18 +03:00
fbt
63eda033cc not a hashtable 2015-08-31 02:03:26 +03:00
fbt
2b32655365 Indexed arrays were only needed to override defaults. 2015-08-31 01:56:54 +03:00
fbt
ec2ff428f8 change defaluts, move mountpoints to rc.conf 2015-08-31 01:45:16 +03:00
3 changed files with 76 additions and 49 deletions

View File

@@ -1,4 +1,7 @@
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.

41
rc.conf
View File

@@ -1,21 +1,42 @@
# System-wide configuration # A default PATH
export PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' export PATH='/usr/local/bin:/usr/local/sbin:/usr/bin'
# Locale
export LC_ALL='en_US.UTF-8'
# Hostname # Hostname
cfg_hostname='changeme' cfg_hostname='spark'
# Timezone # Timezone
# Change this to yours # Uncomment and change this to yours
#cfg_timezone='Europe/Moscow' #cfg_timezone='Europe/Moscow'
# Services # Services that start with @ are executed in parallel
cfg_services+=( 'fsck' 'mount' 'sysctl' 'rsyslogd' ) # Services that need tp be started in an order cfg_services+=(
cfg_services+=( '@lo.iface' '@scron' '@sshd' ) # These start in parallel. 'fsck' 'mount' 'sysctl' 'rsyslogd'
cfg_services+=( @agetty-tty{2..6} ) # Comment this if your init starts something on the ttys itself. '@lo.iface' '@scron' @agetty-tty{2..6}
cfg_services+=( 'rc.local' ) # Traditionally, rc.local starts last. Technically here it doesn't. Not quite :) )
# Add modules you want to be loaded at boot time here # 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' )

77
rc.in
View File

@@ -1,30 +1,5 @@
#!@BASH_PATH@ #!@BASH_PATH@
declare -A cfg_mounts # 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' )
# And temporary files
cfg_tmpfiles+=( '/run/utmp' )
# Default XDG_RUNTIME_DIR for all non-system users
# rtkit:x:133:133:RealtimeKit:/proc:/sbin/nologin
while IFS=':' read -r _ _ uid gid _; do
if (( uid >= 1000 )); then
cfg_tmpdirs+=( "/run/user/$uid:700:$uid:$gid" )
fi
done < /etc/passwd
# Functions # Functions
rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; } rc.rescue() { exec "${cfg_rc_rescue_shell:-"$SHELL"}"; }
@@ -52,15 +27,24 @@ rc.tmpfiles() {
done done
} }
rc.mount_misc() { rc.mount() {
for fs in "${!cfg_mounts[@]}"; do for fs in "${cfg_mounts[@]}"; do
echo "${cfg_mounts[$fs]}" | while IFS=':' read fs_type mountpoint mount_options; do echo "$fs" | while IFS=':' read device fs_type mountpoint mount_options; do
[[ "$mount_options" ]] || { mount_options='defaults'; } 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
mountpoint -q "$mountpoint" || { if ! [[ "$mount_options" ]]; then
[[ -d "$mountpoint" ]] || { mkdir -p "$mountpoint"; } mount_options='defaults'
mount "$fs" -n -t "$fs_type" -o "$mount_options" "$mountpoint" fi
}
mount "$device" -n -t "$fs_type" -o "$mount_options" "$mountpoint"
fi
done done
done done
} }
@@ -134,7 +118,7 @@ rc.remount_root() {
} }
rc.boot() { rc.boot() {
rc.mount_misc rc.mount
rc.tmpfiles rc.tmpfiles
rc.hostname rc.hostname
rc.timezone rc.timezone
@@ -145,10 +129,21 @@ 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) :;;
reboot|*) echo 'b' > /proc/sysrq-trigger;; poweroff|shutdown) rc.halt_poweroff;;
reboot|*) rc.halt_reboot;;
esac esac
} }
@@ -188,6 +183,14 @@ rc.timezone() {
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
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