home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # (C) Klaus Knopper Nov 2002
- # Calls scanpartitions as root and adds entries to /etc/fstab
- # modified by maestromae for Kate OS
-
- [ ! -e /proc/partitions ] && { echo "$0: /proc not mounted, exiting" >&2; exit 1; }
-
- if [ -e /var/run/rebuildfstab.pid ]; then
- ps "$(</var/run/rebuildfstab.pid)" >/dev/null 2>&1 && exit 0
- rm -f /var/run/rebuildfstab.pid
- fi
-
- echo "$$" >/var/run/rebuildfstab.pid
-
- XSH=""
- [ -n "$DISPLAY" ] && XSH="rxvt -bg black -fg green -cr red -T $0 -e"
-
- [ "`id -u`" != "0" ] && { exec $XSH sudo $0 "$@"; }
-
-
- TMP="/var/log/setup/tmp/SeTDOS"
- charset="iso8859-1"
-
- if [ "$LANG" = "pl_PL" ]; then
- charset="iso8859-2"
- fi
-
- # Simple shell grep, searches for lines STARTING with string
- stringinfile(){
- while read line; do
- case "$line" in $1*) return 0;; esac
- done <"$2"
- return 1
- }
-
- removeentries(){
- # Remove comment line $1 and the following line from file $2
- # sed '/^# Added by KNOPPIX/{N;d;}'
- while read line; do
- case "$line" in $1) read line; continue ;; esac
- echo "$line"
- done <"$2"
- }
-
- verbose=""
- remove=""
- user=""
- group=""
- arg="$1"
- while [ -n "$arg" ]; do
- case "$arg" in
- -v*) verbose="yes" ;;
- -r*) remove="yes" ;;
- -u*) shift; user="$1" ;;
- -g*) shift; group="$1" ;;
- *) echo "Usage: $0 [-v[erbose]] [-r[emove_old]] [-u[ser] uid] [ -g[roup] gid]" ;;
- esac
- shift
- arg="$1"
- done
-
- [ -n "$verbose" ] && echo "Scanning for new harddisks/partitions..." >&2
- rm -f "$TMP"
-
- count=0
- while read device mountpoint fstype relax; do
- stringinfile "$device " "$TMP" || \
- { count="$count + 1"
- [ -d "/mnt/$mountpoint" ] || mkdir -p "/mnt/$mountpoint" 2>/dev/null
- options="users,exec"
- checks="0 0"
- case "$fstype" in
- ntfs) options="silent,allow_other,default_permissions,umask=000"; fstype="ntfs-fuse" ;;
- vfat|msdos) options="${options},iocharset=$charset,umask=000" ;;
- swap) options="defaults" ;;
- auto) checks="0 2" ;;
- esac
- case "$fstype" in
- vfat|msdos)
- [ -n "$user" ] && options="$options,uid=$user"
- [ -n "$group" ] && options="$options,gid=$group"
- ;;
- esac
- echo "$device $mountpoint $fstype $options $checks"; }
- done >>"$TMP" <<EOT
- $(scanpartitions)
- EOT
-
- cat /var/log/setup/tmp/SeTnative | \
- cut --delimiter=' ' --field=1 | cut --delimiter='/' --field=3 | while read foo ; do
- cat $TMP | sed -e "/$foo /d" > $TMP.new
- mv -f $TMP.new $TMP
- done
-
- [ -n "$verbose" ] && { [ "$count" -gt 0 ] && echo "Adding $count new partitions to /etc/fstab." >&2 || echo "No new partitions found." >&2; }
-
- rm -f /var/run/rebuildfstab.pid
-
- [ -n "$DISPLAY" ] && sleep 2
-
- exit 0
-