home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 October / Enter 10 2006.iso / boot / isolinux / initrd / in / usr / lib / setup / rebuildfstab < prev    next >
Encoding:
Text File  |  2006-06-12  |  2.5 KB  |  102 lines

  1. #!/bin/sh
  2. # (C) Klaus Knopper Nov 2002
  3. # Calls scanpartitions as root and adds entries to /etc/fstab
  4. # modified by maestromae for Kate OS
  5.  
  6. [ ! -e /proc/partitions ] && { echo "$0: /proc not mounted, exiting" >&2; exit 1; }
  7.  
  8. if [ -e /var/run/rebuildfstab.pid ]; then
  9.  ps "$(</var/run/rebuildfstab.pid)" >/dev/null 2>&1 && exit 0
  10.  rm -f /var/run/rebuildfstab.pid
  11. fi
  12.  
  13. echo "$$" >/var/run/rebuildfstab.pid
  14.  
  15. XSH=""
  16. [ -n "$DISPLAY" ] && XSH="rxvt -bg black -fg green -cr red -T $0 -e"
  17.  
  18. [ "`id -u`" != "0" ] && { exec $XSH sudo $0 "$@"; }
  19.  
  20.  
  21. TMP="/var/log/setup/tmp/SeTDOS"
  22. charset="iso8859-1"
  23.  
  24. if [ "$LANG" = "pl_PL" ]; then
  25. charset="iso8859-2"
  26. fi
  27.  
  28. # Simple shell grep, searches for lines STARTING with string
  29. stringinfile(){
  30. while read line; do
  31. case "$line" in $1*) return 0;; esac
  32. done <"$2"
  33. return 1
  34. }
  35.  
  36. removeentries(){
  37. # Remove comment line $1 and the following line from file $2
  38. # sed '/^# Added by KNOPPIX/{N;d;}'
  39. while read line; do
  40. case "$line" in $1) read line; continue ;; esac
  41. echo "$line"
  42. done <"$2"
  43. }
  44.  
  45. verbose=""
  46. remove=""
  47. user=""
  48. group=""
  49. arg="$1"
  50. while [ -n "$arg" ]; do
  51.  case "$arg" in
  52.   -v*) verbose="yes" ;;
  53.   -r*) remove="yes" ;;
  54.   -u*) shift; user="$1" ;;
  55.   -g*) shift; group="$1" ;;
  56.   *) echo "Usage: $0 [-v[erbose]] [-r[emove_old]] [-u[ser] uid] [ -g[roup] gid]" ;;
  57.  esac
  58.  shift
  59.  arg="$1"
  60. done
  61.  
  62. [ -n "$verbose" ] && echo "Scanning for new harddisks/partitions..." >&2
  63. rm -f "$TMP"
  64.  
  65. count=0
  66. while read device mountpoint fstype relax; do
  67.  stringinfile "$device " "$TMP" || \
  68.  { count="$count + 1"
  69.    [ -d "/mnt/$mountpoint" ] || mkdir -p "/mnt/$mountpoint" 2>/dev/null
  70.    options="users,exec"
  71.    checks="0 0"
  72.    case "$fstype" in
  73.     ntfs) options="silent,allow_other,default_permissions,umask=000"; fstype="ntfs-fuse" ;;
  74.     vfat|msdos) options="${options},iocharset=$charset,umask=000" ;;
  75.     swap) options="defaults" ;;
  76.     auto) checks="0 2" ;;
  77.    esac
  78.    case "$fstype" in
  79.    vfat|msdos)
  80.    [ -n "$user" ] && options="$options,uid=$user"
  81.    [ -n "$group" ] && options="$options,gid=$group"
  82.    ;;
  83.    esac
  84.    echo "$device $mountpoint $fstype $options $checks"; }
  85. done >>"$TMP" <<EOT
  86. $(scanpartitions)
  87. EOT
  88.  
  89. cat /var/log/setup/tmp/SeTnative | \
  90. cut --delimiter=' ' --field=1 | cut --delimiter='/' --field=3 | while read foo ; do 
  91. cat $TMP | sed -e "/$foo /d" > $TMP.new
  92. mv -f $TMP.new $TMP 
  93. done
  94.  
  95. [ -n "$verbose" ] && { [ "$count" -gt 0 ] && echo "Adding $count new partitions to /etc/fstab." >&2 || echo "No new partitions found." >&2; }
  96.  
  97. rm -f /var/run/rebuildfstab.pid
  98.  
  99. [ -n "$DISPLAY" ] && sleep 2
  100.  
  101. exit 0
  102.