Advertisement
kei91

mount.sh

Nov 14th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.72 KB | None | 0 0
  1. #!/bin/bash
  2. # TODO: merge /var/lib/dpkg/status & available with diff-n-patch
  3.  
  4. cmd()
  5. {
  6.     "$@" || {
  7.         s=$?
  8.         if [ $((s & 38)) -ne 0 ]
  9.         then
  10.             echo $@
  11.             exit $s
  12.         fi
  13.     }
  14. }
  15.  
  16. [ -n "$1" ] || exit 1
  17. host=/opt/jail-trees/$1
  18. dest=/opt/jail/$1
  19. base2=""
  20. [ -n "$2" ] && base2=/opt/jail-trees/$2
  21.  
  22. if [ $(basename $0) = "mount.sh" ]
  23. then
  24.     op=mount
  25. else
  26.     op=umount
  27. fi
  28.  
  29.  
  30.  
  31. if [ $op = mount ]
  32. then
  33.     cmd mount -t aufs -o br:$host/root${base2:+:$base2/root}:/ none $dest
  34. fi
  35.  
  36. if [ $op = umount ]
  37. then
  38.     for d in /var/cache/apt/archives
  39.     do
  40.         cmd umount -l ${dest}${d}
  41.     done
  42. fi
  43.  
  44. # FIXME: why usr/* and then ln -s?
  45.  
  46. exclude=/opt/kde3
  47.  
  48. for d in $host/home
  49. do
  50.     # wildcard was not matched
  51.     [[ $d =~ \* ]] && continue
  52.  
  53.     d=${d#$host}
  54.  
  55.     [ "$d" = "$exclude" ] && continue
  56.  
  57.     case $op
  58.     in
  59.     mount)
  60.         [ -d ${dest}${d} ] || mkdir ${dest}${d} || exit 1
  61.         if [ -d ${host}${d} ]
  62.         then
  63.             cmd mount -t aufs -o br:${host}${d}${base2:+:$base2$d}:${d} none ${dest}${d}
  64.         else
  65.             cmd mount --bind ${src}${d} ${dest}${d}
  66.         fi
  67.         ;;
  68.     umount)
  69.         cmd umount -l ${dest}${d}
  70.         ;;
  71.     esac
  72. done
  73.  
  74. if [ $op = mount ]
  75. then
  76.     for d in /var/cache/apt/archives
  77.     do
  78.         cmd mount --bind ${d} ${dest}${d}
  79.     done
  80. fi
  81.  
  82. for d in /proc /sys /dev /tmp /media /run
  83. do
  84.     case $op
  85.     in
  86.     mount)
  87.         cmd mount --rbind $d ${dest}${d}
  88.         ;;
  89.     umount)
  90.         cmd umount -l ${dest}${d}
  91.         ;;
  92.     esac
  93. done
  94.  
  95. case $op
  96. in
  97. mount)
  98.     [ -L ${dest}/usr/lib64 ] || cmd ln -s lib ${dest}/usr/lib64
  99.     ;;
  100. umount)
  101.     cmd umount $dest
  102.     ;;
  103. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement