Last active
June 9, 2017 23:47
-
-
Save j000/42a75d1402f723038a559047930773bc to your computer and use it in GitHub Desktop.
DigitalOcean experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
########## | |
# usage: | |
# curl -O -L 'https://gist.github.com/j000/42a75d1402f723038a559047930773bc/raw/freebsd-to-gentoo.sh' && sudo sh freebsd-to-gentoo.sh | |
########## | |
if [ $(id -u) -ne 0 ]; then | |
echo "This script must be run as root" 1>&2 | |
exit 1 | |
fi | |
# confirmation helper | |
yesno() { | |
question=${1:-Do you want to continue} | |
while : | |
do | |
read -p "$question (yes/no): " answer | |
case "${answer}" in | |
[yY]|[yY][eE][sS]) return 0 ;; | |
[nN]|[nN][oO]) return 1 ;; | |
esac | |
done | |
} | |
pkg install -y grub2 wget e2fsprogs nano sha | |
swapoff -a | |
echo 'Preparing drive' | |
# TODO: verify we are not feleting wrong stuff | |
#=> 40 62914480 vtbd0 GPT (30G) | |
# 40 512 1 freebsd-boot (256K) | |
# 552 4194304 2 freebsd-swap (2.0G) | |
# 4194856 58719664 3 freebsd-ufs (28G) | |
# delete boot | |
gpart delete -i 1 /dev/vtbd0 | |
# delete swap | |
gpart delete -i 2 /dev/vtbd0 | |
# add bios-boot | |
gpart add -t \!21686148-6449-6E6F-744E-656564454649 -i 1 -s 2M /dev/vtbd0 | |
# add /boot | |
gpart add -t linux-data -i 2 -s 1G /dev/vtbd0 | |
# add data partition for data | |
# TODO do we need it? | |
gpart add -t linux-data -i 4 /dev/vtbd0 | |
gpart show /dev/vtbd0 | |
yesno 'Does this look ok?' || exit | |
mkfs.ext3 -L Linux /dev/vtbd0p2 | |
mount -t ext2fs /dev/vtbd0p2 /boot | |
cd /boot | |
echo 'Installing grub' | |
#grub-install --target=x86_64-efi --efi-directory=/boot/grub/x86_64-efi/ --boot-directory=/boot /dev/vtbd0 | |
grub-install /dev/vtbd0 | |
echo 'Downloading latest install image' | |
wget 'http://distfiles.gentoo.org/releases/amd64/autobuilds/latest-install-amd64-minimal.txt' | |
latest=$(grep -v -e '^#' latest-install-amd64-minimal.txt | cut -d' ' -f 1) | |
wget 'http://distfiles.gentoo.org/releases/amd64/autobuilds/'$latest -O install-amd64-minimal.iso | |
wget 'http://distfiles.gentoo.org/releases/amd64/autobuilds/'$latest'.DIGESTS' -O digests | |
echo 'Verifing digests' | |
a=0 | |
grep -qi sha512 digests && grep -q $(sha512 -r install-amd64-minimal.iso) digests && a=1 | |
[ $a -eq 0 ] && grep -qi sha256 digests && grep -q $(sha256 -r install-amd64-minimal.iso) digests && a=1 | |
[ $a -eq 0 ] && grep -qi sha1 digests && grep -q $(sha1 -r install-amd64-minimal.iso) digests && a=1 | |
[ $a -eq 0 ] && echo 'Digest verification failed' && exit 1 | |
rm latest-install-amd64-minimal.txt | |
rm digests | |
echo 'Unpacking' | |
dd if=install-amd64-minimal.iso of=/dev/vtbd0p4 bs=8M | |
#tar xf install-amd64-minimal.iso | |
echo 'Configuring grub' | |
cat >> /usr/local/etc/grub.d/40_custom << EOF | |
set timeout=90 | |
menuentry "Gentoo Minimal Install iso" --class iso { | |
set isofile=/install-amd64-minimal.iso | |
# dokeymap | |
set cmdline="dolvm doscsi scandelay=2 doload=virtio-pci,ata_piix looptype=squashfs loop=/image.squashfs cdroot" | |
loopback loop \${isofile} | |
linux (loop)/isolinux/gentoo \$cmdline root=/dev/ram0 isoboot=\${isofile} init=/linuxrc initrd=gentoo.igz | |
initrd (loop)/isolinux/gentoo.igz | |
} | |
menuentry "memtest86" { | |
set isofile=/install-amd64-minimal.iso | |
loopback loop \${isofile} | |
linux memtest86 | |
} | |
menuentry "FreeBSD" { | |
set root="(hd0,gpt3)" | |
kfreebsd /boot/loader | |
} | |
EOF | |
#echo "DEBIAN: (hd0) /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive0" | |
#echo "EXAMPLE: grub-install --device-map=/boot/grub/device.map /dev/vda" | |
#echo "Our /boot/grub/device.map:" | |
#cat /boot/grub/device.map | |
echo "(hd0) /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive0" > /boot/grub/device.map | |
echo "Making grub config" | |
grub-mkconfig -o /boot/grub/grub.cfg | |
yesno 'Ready for reboot?' || exit | |
reboot |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment