Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # dexgate installation script
- SCRIPT_NAME="$(basename $0)"
- TARGET_DISK="$1"
- TARGET_PART="$TARGET_DISK"1
- TARGET_LABEL="DEXGate"
- TARGET_MOUNT="/mnt/tmp-$(echo $TARGET_DISK|cut -d/ -f3)"
- SOURCE_TAR="/home/jordi/dumpalixgw/dumpentar.tgz"
- unmount_target_partition(){
- umount "$TARGET_PART"
- }
- generate_partition_table(){
- SFDISKCMD='0,,L,*\n;\n;\n;'
- echo -e "$SFDISKCMD"|sfdisk "$TARGET_DISK"
- if [ -d "$TARGET_MOUNT" ]
- then
- echo "Mount directory exist!"
- else
- mkdir "$TARGET_MOUNT"
- echo "Create $TARGET_MOUNT.."
- fi
- }
- format_target_partition(){
- mkfs.ext2 "$TARGET_PART"
- tune2fs -i 28 -c 28 -C -1 "$TARGET_PART" -L "$TARGET_LABEL"
- }
- mount_target_partition(){
- mount "$TARGET_PART" "$TARGET_MOUNT"
- }
- copy_image(){
- #cd "$SOURCE_DIR"
- #dd if="$SOURCE_TAR"|pv|tar xf - -C "$TARGET_MOUNT"
- pv "$SOURCE_TAR"|tar xzf - -C "$TARGET_MOUNT"
- }
- setup_chroot(){
- mount -o bind /dev "$TARGET_MOUNT/dev"
- }
- setup_grub(){
- # "hd5" should be dynamic like "$TARGET_DISK"
- echo "Write (hd5) $TARGET_DISK to $TARGET_MOUNT/boot/grub/device.map.."
- echo "(hd5) $TARGET_DISK">"$TARGET_MOUNT/boot/grub/device.map"
- # this part relates more to setup_chroot()
- echo "Setup grub under chroot $TARGET_MOUNT.."
- RES="$(chroot $TARGET_MOUNT /usr/sbin/grub \
- --device-map=/boot/grub/device.map <<EOF
- setup (hd5) (hd5,0)
- quit
- EOF)"
- echo "$RES"
- if [ $? -ne 0 ]
- then
- err_quit "Trouble running grub - dialog was: $RES"
- fi
- }
- cleanup(){
- echo "Delete $TARGET_MOUNT/boot/grub/device.map.."
- rm "$TARGET_MOUNT/boot/grub/device.map"
- echo "Unmount $TARGET_MOUNT/dev.."
- umount "$TARGET_MOUNT/dev"
- echo "Unmount partition.."
- umount "$TARGET_PART"
- sync
- }
- install_dexgate(){
- unmount_target_partition
- generate_partition_table
- format_target_partition
- mount_target_partition
- setup_chroot
- setup_grub
- cleanup
- }
- if [ $# -eq 1 ] && [ -b "$1" ]
- then
- install_dexgate
- else
- echo "Usage: $SCRIPT_NAME <disk>"
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment