server-scripts/entry.sh

149 lines
3.3 KiB
Bash
Raw Normal View History

2020-01-25 16:41:16 +00:00
#!/bin/bash
2020-01-29 12:33:53 +00:00
2020-01-25 16:41:16 +00:00
function first_stage(){
2020-01-29 19:33:36 +00:00
set -e
2020-01-25 16:41:16 +00:00
echo foo first_stage
2020-01-29 20:49:39 +00:00
2020-01-31 14:23:19 +00:00
echo -n "luks password: "
read -s luks_password_in
2020-01-31 14:43:48 +00:00
export LUKS_PASSWORD=$luks_password_in
2020-01-31 14:34:57 +00:00
echo
2020-01-31 14:23:19 +00:00
echo -n "root password: "
read -s root_password_in
2020-01-31 14:43:48 +00:00
export ROOT_PASSWORD=$root_password_in
2020-01-31 14:34:57 +00:00
echo
2020-01-31 14:23:19 +00:00
echo -n "user password: "
read -s user_password_in
2020-01-31 14:43:48 +00:00
export USER_PASSWORD=$user_password_in
2020-01-31 14:34:57 +00:00
echo
2020-01-29 20:22:39 +00:00
2020-01-29 19:41:05 +00:00
lsblk -ftpo NAME,FSTYPE,LABEL,UUID,FSAVAIL,MOUNTPOINT
2020-01-29 19:29:15 +00:00
select DEVICE in $(lsblk -frpno NAME); do
echo using $DEVICE
2020-01-29 19:32:56 +00:00
break
2020-01-29 19:29:15 +00:00
done
2020-01-29 12:37:36 +00:00
2020-02-06 10:47:08 +00:00
export DEVICE
2020-01-29 20:49:39 +00:00
apt install -y debootstrap cryptsetup btrfs-progs lvm2
2020-01-29 20:51:19 +00:00
if [ -d /dev/vg0 ]; then
2020-01-31 10:57:22 +00:00
mount | grep target | awk '{print $3}'| sort -r | while read LINE; do
umount -l $LINE;
done
2020-01-31 11:00:17 +00:00
if [ -b /dev/vg0/swap ]; then
swapoff /dev/vg0/swap || true
fi
2020-01-29 20:51:19 +00:00
vgchange -an /dev/vg0
fi
2020-01-29 20:42:06 +00:00
if [ -b /dev/mapper/cryptlvm ]; then
cryptsetup luksClose cryptlvm
fi
wipefs -a ${DEVICE}
2020-01-29 20:02:02 +00:00
(
echo o
echo n
2020-01-29 20:12:06 +00:00
echo p
echo 1
2020-01-29 20:06:12 +00:00
echo
2020-01-29 20:02:02 +00:00
echo +2G
echo n
2020-01-29 20:12:06 +00:00
echo p
echo 2
2020-01-29 20:02:02 +00:00
echo
2020-01-29 20:12:06 +00:00
echo
2020-01-29 20:02:02 +00:00
echo w
) | fdisk ${DEVICE}
echo mkfs.ext4 ${DEVICE}1
2020-01-29 20:28:38 +00:00
yes | mkfs.ext4 ${DEVICE}1
2020-01-29 21:59:26 +00:00
2020-01-29 20:22:39 +00:00
(
2020-01-31 20:22:23 +00:00
echo $LUKS_PASSWORD
echo $LUKS_PASSWORD
2020-01-29 20:22:39 +00:00
)| cryptsetup luksFormat ${DEVICE}2
2020-01-31 20:22:23 +00:00
echo $LUKS_PASSWORD | cryptsetup luksOpen ${DEVICE}2 cryptlvm
2020-02-06 10:47:08 +00:00
unset LUKS_PASSWORD
2020-01-29 20:35:15 +00:00
pvcreate /dev/mapper/cryptlvm
vgcreate vg0 /dev/mapper/cryptlvm
2020-01-29 21:59:26 +00:00
2020-01-31 14:38:41 +00:00
export LVM_SIZE=$(dev_size /dev/mapper/cryptlvm)
2020-01-31 10:27:13 +00:00
2020-01-31 14:38:41 +00:00
export SWAP_SIZE=$(($(mem_size)/1024/1024))
export ROOT_SIZE=$(($LVM_SIZE/1024/1024-$SWAP_SIZE-512))
2020-01-31 10:27:13 +00:00
2020-01-31 10:51:33 +00:00
echo lvcreate /dev/vg0 --name=root --size=${ROOT_SIZE}M
lvcreate /dev/vg0 --name=root --size=${ROOT_SIZE}M
2020-01-29 21:22:36 +00:00
yes | mkfs.btrfs /dev/vg0/root
2020-01-29 21:59:26 +00:00
2020-01-31 10:51:33 +00:00
echo lvcreate /dev/vg0 --name=swap --size=${SWAP_SIZE}M
lvcreate /dev/vg0 --name=swap --size=${SWAP_SIZE}M
2020-01-29 20:52:15 +00:00
mkswap /dev/vg0/swap
swapon /dev/vg0/swap
2020-01-29 21:59:26 +00:00
2020-01-29 20:35:15 +00:00
echo mount /dev/vg0/root $TARGET
mount /dev/vg0/root $TARGET
2020-01-29 21:59:26 +00:00
2020-01-29 12:33:53 +00:00
echo debootstrap sid $TARGET
2020-01-29 12:38:18 +00:00
debootstrap sid $TARGET
2020-01-29 21:59:26 +00:00
2020-01-29 20:03:26 +00:00
mount ${DEVICE}1 $TARGET/boot
echo mount ${DEVICE}1 $TARGET/boot
2020-01-29 21:59:26 +00:00
2020-01-29 21:22:36 +00:00
genfstab -U $TARGET | tee $TARGET/etc/fstab
2020-01-29 21:44:06 +00:00
UUID=$(lsblk -lpo NAME,UUID | grep ${DEVICE}2 | awk '{print $2}')
2020-01-29 21:35:04 +00:00
echo cryptlvm UUID=${UUID} none luks > $TARGET/etc/crypttab
2020-01-25 16:41:16 +00:00
}
function second_stage(){
2020-01-29 19:33:36 +00:00
set -e
2020-02-06 10:47:08 +00:00
export DEBIAN_FRONTEND=noninteractive
2020-01-31 14:43:48 +00:00
(
echo $ROOT_PASSWORD
echo $ROOT_PASSWORD
) | passwd
2020-02-06 10:47:08 +00:00
unset ROOT_PASSWORD
2020-01-29 19:29:15 +00:00
echo -n > /etc/motd
2020-02-06 11:08:56 +00:00
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
apt update
2020-02-11 12:27:43 +00:00
apt install -y linux-image-amd64 grub2 cryptsetup btrfs-progs lvm2 firmware-iwlwifi locales tzdata keyboard-configuration console-common zsh intel-microcode
2020-02-06 11:26:57 +00:00
grub-install ${DEVICE}
2020-01-29 21:44:06 +00:00
mkdir /snap
btrfs subvolume snapshot / /snap/$(date +%Y-%m-%d_basesystem)
2020-01-31 15:32:59 +00:00
apt install -y task-mate-desktop mate-desktop-environment-extra
2020-01-31 14:52:39 +00:00
(
echo $USER_PASSWORD
echo $USER_PASSWORD
2020-01-31 18:05:11 +00:00
echo
echo
echo
echo
echo
) | adduser jedi
2020-02-06 10:47:08 +00:00
unset USER_PASSWORD
2020-01-31 18:05:11 +00:00
2020-01-31 15:32:59 +00:00
HOME=/home/jedi
2020-01-31 18:58:36 +00:00
btrfs subvolume snapshot / /snap/$(date +%Y-%m-%d_user_gui)
2020-02-06 15:23:13 +00:00
apt install -y git virt-manager telegram-desktop firefox thunderbird geany vlc pidgin inkscape meld kicad blender
2020-01-31 15:32:59 +00:00
git clone git://github.com/robbyrussell/oh-my-zsh.git $HOME/.oh-my-zsh
chmod 0755 $HOME/.oh-my-zsh
chown -R jedi:jedi $HOME
chsh --shell /bin/zsh jedi
2020-01-31 20:22:23 +00:00
echo second_stage done
2020-01-31 17:21:30 +00:00
}
2020-01-31 15:32:59 +00:00
2020-01-29 21:22:36 +00:00
2020-01-31 09:50:59 +00:00
function post_install_stage(){
sleep 0.5
mount | grep target | awk '{print $3}'| sort -r | while read LINE; do
umount -l $LINE;
done
}