|
#!/bin/sh |
|
## This script assumes you have https://github.com/mezcel/arch-openbox.git in your home dir |
|
|
|
## Arch Linux Boot from Iso |
|
## Really fast install via Usb, but about 30min via slow internet |
|
|
|
## terminal beautification |
|
function decorativeColors() { |
|
## ${Black} |
|
## https://en.wikipedia.org/wiki/ANSI_escape_code |
|
## https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/ |
|
## Usage example: echo "abcd $MODE_BEGIN_UNDERLINE edf $MODE_EXIT_UNDERLINE $FG_RED hijk $STYLES_OFF |
|
|
|
## Forground Color using ANSI escape |
|
|
|
FG_BLACK=$(tput setaf 0) |
|
FG_RED=$(tput setaf 1) |
|
FG_GREEN=$(tput setaf 2) |
|
FG_YELLOW=$(tput setaf 3) |
|
FG_BLUE=$(tput setaf 4) |
|
FG_MAGENTA=$(tput setaf 5) |
|
FG_CYAN=$(tput setaf 6) |
|
FG_WHITE=$(tput setaf 7) |
|
FG_NoColor=$(tput sgr0) |
|
|
|
## Background Color using ANSI escape |
|
|
|
BG_BLACK=$(tput setab 0) |
|
BG_RED=$(tput setab 1) |
|
BG_GREEN=$(tput setab 2) |
|
BG_YELLOW=$(tput setab 3) |
|
BG_BLUE=$(tput setab 4) |
|
BG_MAGENTA=$(tput setab 5) |
|
BG_CYAN=$(tput setab 6) |
|
BG_WHITE=$(tput setab 7) |
|
BG_NoColor=$(tput sgr0) |
|
|
|
## set mode using ANSI escape |
|
|
|
MODE_BOLD=$(tput bold) |
|
MODE_DIM=$(tput dim) |
|
MODE_BEGIN_UNDERLINE=$(tput smul) |
|
MODE_EXIT_UNDERLINE=$(tput rmul) |
|
MODE_REVERSE=$(tput rev) |
|
MODE_ENTER_STANDOUT=$(tput smso) |
|
MODE_EXIT_STANDOUT=$(tput rmso) |
|
|
|
# clear styles using ANSI escape |
|
|
|
STYLES_OFF=$(tput sgr0) |
|
} |
|
|
|
function format_HDD() { |
|
# del existing partitions |
|
(echo d; echo ""; echo w;) | fdisk /dev/sda |
|
sleep 1s |
|
(echo d; echo ""; echo w;) | fdisk /dev/sda |
|
sleep 1s |
|
(echo d; echo ""; echo w;) | fdisk /dev/sda |
|
sleep 1s |
|
# make new partitions |
|
(echo o; echo n; echo p; echo 2; echo ""; echo +1G; echo w; echo "";) | fdisk /dev/sda |
|
sleep 1s |
|
(echo n; echo p; echo 1; echo ""; echo ""; echo w; echo "";) | fdisk /dev/sda |
|
sleep 1s |
|
(echo y;) | mkfs.ext4 /dev/sda1 |
|
sleep 1s |
|
mkswap /dev/sda2 |
|
sleep 1s |
|
swapon /dev/sda2 |
|
sleep 1s |
|
# Mount |
|
# mkdir /mnt |
|
mount /dev/sda1 /mnt |
|
sleep 1s |
|
} |
|
|
|
function format_SSD_HDD() { |
|
## del any existing partitions |
|
(echo d; echo 1; echo ""; echo w;) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
(echo d; echo 2; echo ""; echo w;) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
(echo d; echo 3; echo ""; echo w;) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
(echo d; echo 4; echo ""; echo w;) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
(echo d; echo ""; echo w;) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
|
|
## make new partitions |
|
## +256M UEFI Boot partition is a guess, Win10 likes 4K-25M, yet 256M-500M is recomended by the ArchWiki, Ubuntu doesent even care |
|
(echo o; echo n; echo p; echo 1; echo ""; echo +256M; echo w; echo "";) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
## I put in swap just as a curtesy |
|
(echo n; echo p; echo 3; echo ""; echo +1G; echo w; echo "";) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
(echo n; echo p; echo 2; echo ""; echo ""; echo w; echo "";) | fdisk /dev/mmcblk0 |
|
sleep 1s |
|
|
|
## Format for uefi boot system |
|
(echo y;) | mkfs.fat -F32 /dev/mmcblk0p1 |
|
sleep 1s |
|
(echo y;) | mkfs.ext4 /dev/mmcblk0p2 |
|
sleep 1s |
|
|
|
## extra swap just to have it |
|
mkswap /dev/mmcblk0p3 |
|
sleep 1s |
|
swapon /dev/mmcblk0p3 |
|
sleep 1s |
|
|
|
## Mount |
|
mount /dev/mmcblk0p2 /mnt |
|
sleep 1s |
|
} |
|
|
|
function packstrap_from_iso() { |
|
## my regional mirrorlist for pacman |
|
|
|
mirrorlist_backup="/etc/pacman.d/mirrorlist" |
|
if [ -f "$mirrorlist_backup" ] |
|
then mv "$mirrorlist_backup" "$mirrorlist_backup.backup.$(date +%H%M%S)" |
|
fi |
|
sleep 1s |
|
|
|
# cp ~/arch-openbox/mirrorlist /etc/pacman.d/mirrorlist |
|
currentDirPath=$(dirname $0) |
|
cp $currentDirPath/mirrorlist /etc/pacman.d/mirrorlist |
|
sleep 1s |
|
|
|
## Customize my Skel |
|
## copy my current home to skel |
|
# cp -r ~/* /etc/skel |
|
# cp -r ~/.* /etc/skel |
|
|
|
## Usb merge resource from usb |
|
time cp -ax / /mnt |
|
sleep 2s |
|
cp -vaT /run/archiso/bootmnt/arch/boot/x86_64/vmlinuz /mnt/boot/vmlinuz-linux |
|
sleep 2s |
|
# pacman -Sy |
|
## Install the base packages |
|
# pacstrap /mnt base base-devel |
|
## Generate an fstab |
|
genfstab -p /mnt >> /mnt/etc/fstab |
|
sleep 1s |
|
} |
|
|
|
function chroot_localization() { |
|
# Chroot into your newly installed system |
|
# remove a lot of things that were imported from usb iso |
|
( |
|
# Localization |
|
echo timedatectl set-ntp true; |
|
echo ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime; |
|
echo "echo en_US.UTF-8 UTF-8 >> /etc/locale.gen"; |
|
echo locale-gen; |
|
echo hwclock --systohc; |
|
echo "echo LANG=en_US.UTF-8 >> /etc/locale.conf"; |
|
# Restore the configuration of journald |
|
echo sed -i 's/Storage=volatile/#Storage=auto/' /etc/systemd/journald.conf; |
|
# Remove special udev rule |
|
echo rm /etc/udev/rules.d//81-dhcpcd.rules; |
|
# Disable and remove the services created by archiso |
|
echo systemctl disable pacman-init.service choose-mirror.service; |
|
echo rm /etc/systemd/system/choose-mirror.service; |
|
echo rm /etc/systemd/system/pacman-init.service; |
|
echo rm /etc/systemd/system/etc-pacman.d-gnupg.mount; |
|
echo rm -rf /etc/systemd/system/[email protected]; |
|
echo rm /etc/systemd/scripts/choose-mirror; |
|
# Remove special scripts of the Live environment |
|
echo rm /etc/systemd/system/[email protected]/autologin.conf; |
|
echo rm /root/.automated_script.sh; |
|
echo rm /root/.zlogin; |
|
echo rm /etc/mkinitcpio-archiso.conf; |
|
echo rm -r /etc/initcpio/; |
|
# Import archlinux keys |
|
echo pacman-key --init; |
|
echo pacman-key --populate archlinux; |
|
echo sleep 1s; |
|
# Initramfs |
|
echo mkinitcpio -p linux; |
|
echo sleep 4s; |
|
echo exit; |
|
) | arch-chroot /mnt /bin/bash |
|
} |
|
|
|
function chroot_biosGrub() { |
|
## GRUB Stuff |
|
## Install Grub Bootloader |
|
( |
|
## Install Grub Bootloader |
|
echo pacman -S --needed grub; |
|
echo grub-install --target=i386-pc --recheck --force /dev/sda; |
|
echo sleep 2s; |
|
echo cp /usr/share/locale/en\@quot/LC_MESSAGES/grub.mo /boot/grub/locale/en.mo; |
|
echo grub-mkconfig -o /boot/grub/grub.cfg; |
|
echo sleep 2s; |
|
echo exit; |
|
) | arch-chroot /mnt /bin/bash |
|
|
|
} |
|
|
|
function chroot_uefiGrub() { |
|
# wifi-menu |
|
# sleep 3s # Waits 3 seconds. |
|
# pacman -Sy |
|
|
|
## GRUB Stuff |
|
## im gona want to enable internet to dl grub and efibootmgr |
|
## maybe in the near future I wont need to mess with even this step |
|
( |
|
## Install Grub Bootloader |
|
echo pacman -S --noconfirm grub; |
|
echo pacman -S --noconfirm efibootmgr; |
|
echo mkdir /boot/efi; |
|
echo mount /dev/mmcblk0p1 /boot/efi; |
|
echo sleep 4s; |
|
echo grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot/efi; |
|
echo sleep 2s; |
|
echo grub-mkconfig -o /boot/grub/grub.cfg; |
|
echo sleep 2s; |
|
## tricky stuff to make sure it always boot |
|
echo mkdir /boot/efi/EFI/BOOT; |
|
echo cp /boot/efi/EFI/GRUB/grubx64.efi /boot/efi/EFI/BOOT/BOOTX64.EFI; |
|
echo "echo bcf boot add 1 fs0:\\\EFI\GRUB\\\grubx64.efi \\\"My GRUB bootloader\\\" >> /boot/efi/startup.nsh"; |
|
echo "echo exit >> /boot/efi/startup.nsh"; |
|
echo sleep 4s; |
|
echo exit; |
|
) | arch-chroot /mnt /bin/bash |
|
} |
|
|
|
function biosgrub() { |
|
timedatectl set-ntp true |
|
|
|
## Partition Destination Drive |
|
echo "$FG_YELLOW |
|
About to prepare destination drive... |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
format_HDD |
|
|
|
## Packstrap and cutomization |
|
echo "$FG_YELLOW |
|
About to prepare packstrap... |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
packstrap_from_iso |
|
|
|
echo "$FG_YELLOW |
|
About to prepare chroot customizations... |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
chroot_localization |
|
|
|
## GRUB STUFF |
|
echo "$FG_YELLOW |
|
About to prepare grub... |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
chroot_biosGrub |
|
} |
|
|
|
function uefigrub() { |
|
timedatectl set-ntp true |
|
|
|
## Partition Destination Drive |
|
echo "$FG_YELLOW |
|
About to prepare destination drive... |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
format_SSD_HDD |
|
|
|
## Packstrap and cutomization |
|
echo "$FG_YELLOW |
|
About to prepare packstrap |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
packstrap_from_iso |
|
|
|
echo "$FG_YELLOW |
|
About to prepare chroot customizations... |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
chroot_localization |
|
|
|
## GRUB STUFF |
|
echo "$FG_YELLOW |
|
About to prepare grub |
|
$FG_NoColor" |
|
sleep 3s # Waits 3 seconds. |
|
chroot_uefiGrub |
|
} |
|
|
|
function closeOut() { |
|
## Done |
|
umount -R /mnt |
|
|
|
sleep 2s # Waits 2 seconds. |
|
echo "$FG_YELLOW |
|
Just a 2 sec delay to allow unmounting to settle... |
|
" |
|
shutdown now |
|
} |
|
|
|
function main_menu() { |
|
dialogBackTitle="Install from iso" |
|
dialogTitle="Bootloader Options" |
|
selectedMenuItem=$(dialog 2>&1 >/dev/tty \ |
|
--backtitle "$dialogBackTitle" \ |
|
--title "$dialogTitle" \ |
|
--cancel-label "Back" \ |
|
--menu "Select you boot firmware type:" 10 40 2 \ |
|
"1" "Grub on BIOS Bootloader" \ |
|
"2" "Grub on UEFI Bootloader") || return |
|
|
|
if [[ $selectedMenuItem = 1 ]]; then |
|
biosgrub |
|
fi |
|
|
|
if [[ $selectedMenuItem = 2 ]]; then |
|
uefigrub |
|
fi |
|
|
|
clear |
|
|
|
} |
|
|
|
## Start the DIY installer |
|
|
|
decorativeColors |
|
main_menu |
|
## Done |
|
sleep 4s |
|
closeOut |