Guest User

Voyage install script

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