Guest User

dexgate-installation-script

a guest
Dec 5th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.96 KB | None | 0 0
  1.  
  2. #!/bin/bash
  3.  
  4. # dexgate installation script
  5.  
  6. SCRIPT_NAME="$(basename $0)"
  7. TARGET_DISK="$1"
  8. TARGET_PART="$TARGET_DISK"1
  9. TARGET_LABEL="DEXGate"
  10. TARGET_MOUNT="/mnt/tmp-$(echo $TARGET_DISK|cut -d/ -f3)"
  11. SOURCE_TAR="/home/jordi/dumpalixgw/dumpentar.tgz"
  12.  
  13. unmount_target_partition(){
  14.  
  15. umount "$TARGET_PART"
  16. }
  17.  
  18. generate_partition_table(){
  19.  
  20. SFDISKCMD='0,,L,*\n;\n;\n;'
  21.  
  22. echo -e "$SFDISKCMD"|sfdisk "$TARGET_DISK"
  23.  
  24. if [ -d "$TARGET_MOUNT" ]
  25. then
  26.   echo "Mount directory exist!"
  27. else
  28.   mkdir "$TARGET_MOUNT"
  29.   echo "Create $TARGET_MOUNT.."
  30. fi
  31. }
  32.  
  33. format_target_partition(){
  34.  
  35. mkfs.ext2 "$TARGET_PART"
  36. tune2fs -i 28 -c 28 -C -1 "$TARGET_PART" -L "$TARGET_LABEL"
  37. }
  38.  
  39. mount_target_partition(){
  40.  
  41. mount "$TARGET_PART" "$TARGET_MOUNT"
  42. }
  43.  
  44. copy_image(){
  45.  
  46. #cd "$SOURCE_DIR"
  47. #dd if="$SOURCE_TAR"|pv|tar xf - -C "$TARGET_MOUNT"
  48. pv "$SOURCE_TAR"|tar xzf - -C "$TARGET_MOUNT"
  49. }
  50.  
  51. setup_chroot(){
  52.  
  53. mount -o bind /dev "$TARGET_MOUNT/dev"
  54. }
  55.  
  56. setup_grub(){
  57.  
  58. # "hd5" should be dynamic like "$TARGET_DISK"
  59. echo "Write (hd5) $TARGET_DISK to $TARGET_MOUNT/boot/grub/device.map.."
  60. echo "(hd5) $TARGET_DISK">"$TARGET_MOUNT/boot/grub/device.map"
  61.  
  62. # this part relates more to setup_chroot()
  63. echo "Setup grub under chroot $TARGET_MOUNT.."
  64.  
  65. RES="$(chroot $TARGET_MOUNT /usr/sbin/grub \
  66.    --device-map=/boot/grub/device.map  <<EOF
  67. setup (hd5) (hd5,0)
  68. quit
  69. EOF)"
  70.  
  71. echo "$RES"
  72.  
  73. if [ $? -ne 0 ]
  74. then
  75.   err_quit "Trouble running grub - dialog was: $RES"
  76. fi
  77. }
  78.  
  79. cleanup(){
  80.  
  81. echo "Delete $TARGET_MOUNT/boot/grub/device.map.."
  82. rm "$TARGET_MOUNT/boot/grub/device.map"
  83.  
  84. echo "Unmount $TARGET_MOUNT/dev.."
  85. umount "$TARGET_MOUNT/dev"
  86.  
  87. echo "Unmount partition.."
  88. umount "$TARGET_PART"
  89. sync
  90. }
  91.  
  92. install_dexgate(){
  93.  
  94. unmount_target_partition
  95. generate_partition_table
  96. format_target_partition
  97. mount_target_partition
  98. setup_chroot
  99. setup_grub
  100. cleanup
  101. }
  102.  
  103. if [ $# -eq 1 ] && [ -b "$1" ]
  104. then
  105.   install_dexgate
  106. else
  107.   echo "Usage: $SCRIPT_NAME <disk>"
  108.   exit
  109. fi
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment