All pastes #477217 Raw Edit

kiwi-ltsp

public text v1 · immutable
·published 2007-05-08 14:56 UTC
rendered paste body

#! /bin/sh
#
# Author:	Matt Zimmerman <mdz@ubuntu.com>
#
### BEGIN INIT INFO
# Provides:         00-suse-bind-mounts 
# Required-Start:    
# Required-Stop:     
# Default-Start:     B 
# Default-Stop:      0 6
# Short-Description: Script for LTSP client initialization
# Description:
### END INIT INFO
set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Mount all required tempfs"
NAME=00-suse-bind-mounts
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -f /usr/lib/ltsp/ltsp_functions || exit 0
# Gracefully exit if ltsp_chroot file is not present
#test -f /etc/ltsp_chroot || exit 0

. /lib/lsb/init-functions
. /usr/lib/ltsp/ltsp_functions
. /usr/lib/ltsp/ltsp_config
test -f /etc/default/ltsp-client-setup && . /etc/default/ltsp-client-setup

bind_mounts () {
  # set defaults
  test -z "$tmpfs_dir" && tmpfs_dir=/var/lib/ltsp-client-setup
  test -z "$rw_dirs" && rw_dirs="/var/cache/man /var/lib/xkb /var/lock /var/run /var/log /var/spool /var/tmp /tmp /var/lib/dbus /etc/reader.conf.d /var/adm /var/lib/dhcpcd /var/lib/misc /media"
  test -z "$copy_dirs" && copy_dirs=""
  test -z "$temp_copy_dirs" && temp_copy_dirs="/var/cache"
  test -z "$bindfiles" && bindfiles="/etc/hosts /etc/X11/xorg.conf /etc/fstab /etc/reader.conf /etc/defkeymap.name /etc/adjtime"
  mount -t tmpfs -o mode=0755 tmpfs $tmpfs_dir
  # preserve directory structure
  for d in $rw_dirs ; do
    if [ -d "$d" ]; then
      cd $tmpfs_dir
      tar --no-recursion -cpf - $(find $d -type d 2> /dev/null) 2> /dev/null | tar xpf -
      mount --bind $tmpfs_dir/$d $d
    else
      echo "WARNING: $d does not exist"
    fi
  done  
  # copy contents into tmpfs
  for d in $copy_dirs $temp_copy_dirs; do
    if [ -d "$d" ]; then
      cd $tmpfs_dir
      tar -cpf - $d 2> /dev/null | tar xpf -
      mount --bind $tmpfs_dir/$d $d
    else
      echo "WARNING: $d does not exist"
    fi
  done
  # mount one file on top of another
  for f in $bindfiles ; do
    if [ -e "$f" ]; then
      mkdir -p "$(dirname $tmpfs_dir/$f)"
      cp $f $tmpfs_dir/$f
      mount --bind $tmpfs_dir/$f $f
    else
      echo "WARNING: $f does not exist"
    fi
  done
}

bind_unmounts() {
  for dir in $temp_copy_dirs; do
    umount $dir
    rm -rf $tmpfs_dir/${dir#/}
  done
}

case "$1" in
  start)
          bind_mounts
          bind_unmounts
	;;
  stop)
#	echo -n "Stopping $DESC: $NAME"
#	d_stop
#	echo "."
	bind_unmounts
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: $NAME"
	d_stop
	sleep 1
	d_start
	echo "."
	;;
  *)
	# echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0