February 22, 200818 yr Is it possible to add hooks for user scripts in startup shutdown phase so that we do not have to modify the go script for every new release. Here's my suggestion root@unraid:/boot/config# more go #!/bin/bash # Start the Management Utility /usr/local/sbin/emhttp & fromdos < /boot/config/rc.local/rc.local_startup | sh root@unraid:/boot/config# root@unraid:/boot/config# more /etc/rc.d/rc.local_shutdown /boot/config/rc.local/rc.local_shutdown Just so you understand how this is being used, I'll post my startup/shutdowns. Possibly it may help someone or provide ideas. Directory Structure. (I'm considering moving the config's etc and rc.local directories to the root rather then under config. I'm open for suggestions.) root@unraid:/boot/config# find /boot -type d /boot /boot/config /boot/config/shares /boot/config/rc.local /boot/config/etc /boot/config/etc/rc.d /boot/config/etc/ssh /boot/packages /boot/packages/bak /boot/home root@unraid:/boot# ls -l /boot/packages/ total 3000 drwxr-xr-x 2 root root 8192 Feb 21 20:56 bak/ -rwxr-xr-x 1 root root 777783 Feb 20 15:25 openssh-4.6p1-i486-1.tgz* -rwxr-xr-x 1 root root 845145 Oct 20 11:07 openssl-solibs-0.9.8g-i486-1.tgz* -rwxr-xr-x 1 root root 821364 Feb 20 15:25 proftpd-1.3.1-i486-1.tgz* -rwxr-xr-x 1 root root 599349 Feb 20 15:25 wget-1.10.2-i486-2.tgz* root@unraid:/boot# ls -l /boot/config/rc.local/ total 96 -rwxr-xr-x 1 root root 148 Feb 20 23:29 S00-syslog.sh* -rwxr-xr-x 1 root root 263 Feb 21 22:29 S01-blockdev* -rwxr-xr-x 1 root root 432 Feb 21 02:20 S02-sync-etc* -rwxr-xr-x 1 root root 151 Feb 21 01:19 S10-installpkg* -rwxr-xr-x 1 root root 464 Feb 21 22:05 S20-init.identd* -rwxr-xr-x 1 root root 587 Feb 21 22:06 S20-init.proftpd* -rwxr-xr-x 1 root root 229 Feb 21 20:52 S20-init.rsyncd* -rwxr-xr-x 1 root root 343 Feb 21 21:48 S20-init.sshd* -rwxr-xr-x 1 root root 554 Feb 21 22:42 S75-useradds* -rwxr-xr-x 1 root root 811 Feb 20 23:49 S80-update_hosts* -rwxr-xr-x 1 root root 543 Feb 21 03:43 rc.local_shutdown* -rwxr-xr-x 1 root root 917 Feb 21 22:40 rc.local_startup* root@unraid:/boot# ls -l /boot/home total 16 -rwxr-xr-x 1 root root 2887 Feb 21 00:50 rcotrone.tar.gz* -rwxr-xr-x 1 root root 2891 Feb 21 22:44 root.tar.gz* Here are the scripts. Hopefully they are use for someone or someone can improve upon them. root@unraid:/boot# more /boot/config/rc.local/* :::::::::::::: /boot/config/rc.local/S00-syslog.sh :::::::::::::: #!/bin/bash #customized syslog.conf to allow sending messages off host to a log host. cp /boot/config/etc/syslog.conf /etc/syslog.conf read PID < /var/run/syslogd.pid kill -1 ${PID} dmesg | logger -tdmesg -plocal7.info -i :::::::::::::: /boot/config/rc.local/S01-blockdev :::::::::::::: #!/bin/bash if [ ${DEBUG:=0} -gt 1 ] then set -x -v fi LOOP=10 while [[ $LOOP -gt 1 && ! -b /dev/md1 ]] do (( LOOP=LOOP-1 )) echo "Waiting for /dev/md1 to come online ($LOOP)" sleep 1 done sleep 1 for disk in /dev/md* do blockdev --setra 2048 $disk done :::::::::::::: /boot/config/rc.local/S02-sync-etc :::::::::::::: #!/bin/bash if [ ${DEBUG:=0} -gt 0 ] then set -x -v fi ROOT=etc cd /boot/config/${ROOT} || exit 99 # rsync -rv . /${ROOT}/ # exit find . -type d ! -name '.' -print | while read DIR do if [ ! -d /${ROOT}/${DIR} ]; then mkdir /${ROOT}/${DIR}; fi done find . -type f -print | while read FILE do # CASE for binary files case "$FILE" in *ssh_host_key* ) cp ${FILE} /${ROOT}/${FILE};; * ) fromdos < ${FILE} > /${ROOT}/${FILE};; esac touch --reference=${FILE} /${ROOT}/${FILE} done :::::::::::::: /boot/config/rc.local/S10-installpkg :::::::::::::: #!/bin/bash for package in /boot/packages/*.tgz do echo "Installing $package" installpkg $package 2>&1 | logger -tinstallpkg -plocal7.info -i done :::::::::::::: /boot/config/rc.local/S20-init.identd :::::::::::::: #!/bin/bash # Find auth and identd, if exists, write a comment line and hup inetd. awk ' { if ( /^auth/ && /in.identd/ ) { printf("# %s\n",$0); next; } print $0; } ' < /etc/inetd.conf > /etc/inetd.conf.tmp if diff /etc/inetd.conf /etc/inetd.conf.tmp | grep '^>' >/dev/null then cat /etc/inetd.conf.tmp > /etc/inetd.conf read PID < /var/run/inetd.pid kill -1 ${PID} fi rm -f /etc/inetd.conf.tmp :::::::::::::: /boot/config/rc.local/S20-init.proftpd :::::::::::::: #!/bin/bash PACKAGE=openssl-solibs-0.9.8g-i486-1 if [ ! -f /var/log/packages/$PACKAGE ] then installpkg /boot/packages/$PACKAGE.tgz fi PACKAGE=proftpd-1.3.1-i486-1 if [ ! -f /var/log/packages/$PACKAGE ] then installpkg /boot/packages/$PACKAGE.tgz fi if grep '^ftp' /etc/inetd.conf >/dev/null then # echo "ftp already defined in /etc/inetd.conf" exit fi if ! grep -v '^#' /etc/inetd.conf | grep proftpd >/dev/null; then cat <<-EOF >> /etc/inetd.conf ftp stream tcp nowait root /usr/sbin/tcpd proftpd EOF fi read PID < /var/run/inetd.pid kill -1 ${PID} :::::::::::::: /boot/config/rc.local/S20-init.rsyncd :::::::::::::: #!/bin/bash if ! grep ^rsync /etc/inetd.conf > /dev/null ; then cat <<-EOF >> /etc/inetd.conf rsync stream tcp nowait root /usr/sbin/tcpd /usr/bin/rsync --daemon EOF read PID < /var/run/inetd.pid kill -1 ${PID} fi :::::::::::::: /boot/config/rc.local/S20-init.sshd :::::::::::::: PACKAGE=openssl-solibs-0.9.8g-i486-1 if [ ! -f /var/log/packages/$PACKAGE ] then installpkg /boot/packages/$PACKAGE.tgz fi PACKAGE=openssh-4.6p1-i486-1 if [ ! -f /var/log/packages/$PACKAGE ] then installpkg /boot/packages/$PACKAGE.tgz fi cp --preserve=timestamps /boot/config/etc/ssh/ssh*key* /etc/ssh chmod 600 /etc/ssh/ssh*key* /etc/rc.d/rc.sshd start :::::::::::::: /boot/config/rc.local/S75-useradds :::::::::::::: #!/bin/bash useradd -d /home/guest -s /bin/bash -G root -m -c "Guest User" guest # mkdir /home/guest chown guest:users /home/guest chmod go-r /home/guest # These are personal preferences so I can simply do # cd ~user or cd ~local or use it in scripts useradd -d /mnt/user -s /bin/false -G root -c "User" user useradd -d /usr/local -s /bin/false -G root -c "Local" local # Restore any special user profile setups for tarfile in /boot/home/*.tar.gz do tarbase=${tarfile##*/} user=${tarbase%.tar.gz} eval cd ~$user && tar -xzf $tarfile done :::::::::::::: /boot/config/rc.local/S80-update_hosts :::::::::::::: #!/bin/bash # Fixes /etc/hosts with proper hostname information HOSTNAME=`hostname` if grep $HOSTNAME /etc/hosts >/dev/null then echo "hostname: '$HOSTNAME' already in hosts. skipping" exit fi # Remove this crappy entry. grep -v 'darkstar.example.net' < /etc/hosts > /tmp/hosts # Get current ifconfig information and use it to get address ifconfig | awk -vhostname="$HOSTNAME" ' { # inet addr:192.168.1.178 Bcast:192.168.1.255 Mask:255.255.255.0 # $1 $2 $3 $4 if ( /inet addr:/ && /Bcast:/ && /Mask:/ ) { addr=$2 gsub("addr:","",addr); printf("%s\t%s\n",addr,hostname); } } ' >> /tmp/hosts if ! grep $HOSTNAME /tmp/hosts > /dev/null then printf "127.0.0.1\t%s\n" $HOSTNAME >> /tmp/hosts fi cat /tmp/hosts > /etc/hosts rm -f /tmp/hosts :::::::::::::: /boot/config/rc.local/rc.local_shutdown :::::::::::::: #!/bin/bash # Save User home files in root filesystem if [ "${DEBUG:=0}" -gt 0 ] then set -x -v fi while read USER DIRS do NF=`eval find ~$USER -newer /boot/home/$USER.tar.gz | wc -l` if [ $NF -gt 0 ] then echo "Saving ~$USER home files" eval cd ~$USER && tar -vczf /boot/home/$USER.tar.gz $DIRS fi done <<-EOF root .ssh .profile .bash_profile sh bin rcotrone .ssh .profile .bash_profile sh bin EOF find /etc/ssh -type f -newer /boot/config/etc/ssh/saved -exec cp -v {} /boot/config/etc/ssh \; touch /boot/config/etc/ssh/saved :::::::::::::: /boot/config/rc.local/rc.local_startup :::::::::::::: #!/bin/bash logger -trc.local_startup -plocal7.info -is "Initiating Local Custom Startup." for script in /boot/config/rc.local/* do scriptbase=${script##*/} # Strip pathname if [ $scriptbase = "rc.local_startup" ] ;then continue; fi if [ $scriptbase = "rc.local_shutdown" ] ;then continue; fi ( echo "Processing $script" fromdos < $script | sh ) 2>&1 | logger -t$scriptbase -plocal7.info -is # Old way not used. # fromdos < $script > /tmp/$scriptbase # chmod u+x /tmp/$scriptbase # /tmp/$scriptbase # rm /tmp/$scriptbase done # Setup shutdown script RCFILE=rc.local_shutdown if ! grep /boot/config/rc.local/$RCFILE /etc/rc.d/$RCFILE > /dev/null 2>&1 then echo /boot/config/rc.local/$RCFILE >> /etc/rc.d/$RCFILE fi if [ ! -x /etc/rc.d/$RCFILE ] then chmod u+x /etc/rc.d/$RCFILE fi logger -trc.local_startup -plocal7.info -is "Local Custom Startup Complete."
Archived
This topic is now archived and is closed to further replies.