Advertisement
Guest User

Untitled

a guest
Oct 5th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #!/bin/bash
  2. # Insert a module to the /union on the fly.
  3. #
  4. # Author: Tomas M. <http://www.linux-live.org>
  5. # Completely rewritten for Porteus by fanthom.
  6.  
  7. BASE=`basename $1`
  8. MOD=/mnt/live/memory/images/$BASE
  9.  
  10. # Arch specific variables:
  11. if [ `uname -m|grep "x86_64"` ]; then
  12. lib=lib64
  13. else
  14. lib=lib
  15. fi
  16.  
  17. if [ "`echo $BASE | grep .xzm`" = "" ]; then
  18. echo "$BASE: Module must end with .xzm"
  19. exit 1
  20. fi
  21.  
  22. if [ "`grep '^aufs / ' /proc/mounts`" = "" ]; then
  23. echo "Not in the live mode, can't continue. Try xzm2dir $1 /"
  24. exit 2
  25. fi
  26.  
  27. if [ ! -f $1 -a ! -d $1 ]; then
  28. echo "$BASE: This is not a valid module"
  29. exit 3
  30. fi
  31.  
  32. if cat /proc/mounts | cut -d" " -f2 | grep -q $MOD; then
  33. echo "$BASE: Module is already activated. Deactivate? Answer y/n"
  34. read ans
  35. if [ "$ans" = y ]; then
  36. /opt/porteus-scripts/xorg/aufs-remove $BASE
  37. exit
  38. else
  39. exit
  40. fi
  41. fi
  42.  
  43. # Make sure that we have some free loop device:
  44. x=`losetup -a | tail -n1 | cut -d: -f1 | sed s^/dev/loop^^`; let y=x+1
  45. if [ ! -b /dev/loop$y ]; then
  46. echo "Adding 10 new loop devices"
  47. for i in {1..10}; do mknod /dev/loop$y b 7 $y; let y=y+1; done
  48. fi
  49.  
  50. # 'Stale NFS' workaround:
  51. cd /etc
  52.  
  53. # Insert module to union:
  54. mkdir -p $MOD
  55. [ -d $1 ] && mount -no bind $1 $MOD || mount -no loop,ro $1 $MOD 2>/dev/null
  56. if [ $? -ne 0 ]; then echo "$BASE: Cannot read module data. Corrupted download?"; rmdir $MOD 2>/dev/null; exit 4; fi
  57. mount -no remount,add:1:$MOD=rr aufs /
  58. if [ $? -ne 0 ]; then echo "$BASE: Can't insert module to union"; umount $MOD; rmdir $MOD; exit 5; fi
  59.  
  60. # Find all rc scripts from the module:
  61. find $MOD/etc/rc.d $MOD/etc/init.d $MOD/etc/rc.d/init.d -type f -executable -maxdepth 1 2>/dev/null | egrep -v 'rc.[0-9]|rc.K|rc.S|rc.M' | sed s^$MOD^^ | sort -u >> /mnt/live/tmp/caches/services
  62.  
  63. # Check for certain files to update system caches if necessary:
  64. touch /mnt/live/tmp/caches/ldconfig
  65.  
  66. for x in `find $MOD/usr/share/icons -name icon-theme.cache 2>/dev/null | sed s^$MOD^^`; do
  67. echo `dirname $x` >> /mnt/live/tmp/caches/icons
  68. done
  69.  
  70. [ -e $MOD/usr/share/mime ] && touch /mnt/live/tmp/caches/mime
  71. [ -e $MOD/usr/share/fonts ] && touch /mnt/live/tmp/caches/fonts
  72. [ -e $MOD/usr/share/glib-2.0/schemas ] && touch /mnt/live/tmp/caches/schemas
  73. [ -e $MOD/usr/$lib/gio/modules ] && touch /mnt/live/tmp/caches/gio
  74. [ -e $MOD/usr/$lib/gtk-2.0/*/immodules ] && touch /mnt/live/tmp/caches/immodules
  75. [ -e $MOD/usr/$lib/gtk-3.0/*/immodules ] && touch /mnt/live/tmp/caches/immodules
  76. [ -e $MOD/etc/ssl/certs ] && touch /mnt/live/tmp/caches/certs
  77. [ -e $MOD/usr/share/applications ] && find $MOD/usr/share/applications -name "*.desktop" 2>/dev/null >> /mnt/live/tmp/caches/desktop-install
  78.  
  79. # Multilib support for x86_64 arch:
  80. if [ $lib = lib64 ]; then
  81. [ -e $MOD/usr/lib/gtk-2.0/*/immodules ] && touch /mnt/live/tmp/caches/immodules
  82. [ -e $MOD/usr/lib/gtk-3.0/*/immodules ] && touch /mnt/live/tmp/caches/immodules
  83. [ -e $MOD/usr/lib/gdk-pixbuf-*/*/loaders ] && touch /mnt/live/tmp/caches/pixbuf
  84. [ -e $MOD/usr/lib/pango/*/modules ] && touch /mnt/live/tmp/caches/pango
  85. fi
  86.  
  87. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement