laptop-scripts/entry.sh

211 lines
5.2 KiB
Bash
Raw Normal View History

2020-01-25 16:41:16 +00:00
#!/bin/bash
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
2021-03-12 13:25:29 +00:00
2021-03-11 22:21:29 +00:00
echo -n "hostname: "
2022-02-17 22:25:22 +00:00
read hostname_in
2021-03-11 22:21:29 +00:00
export NEW_HOSTNAME=$hostname_in
2021-03-12 13:25:29 +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
2021-03-12 13:25:29 +00:00
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
2021-03-12 13:25:29 +00:00
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
2021-03-12 13:25:29 +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
2021-03-12 13:25:29 +00:00
2020-02-06 10:47:08 +00:00
export DEVICE
2021-03-12 13:25:29 +00:00
2022-03-26 18:53:57 +00:00
apt install -y debootstrap cryptsetup btrfs-progs lvm2 rsync
2021-03-12 13:25:29 +00:00
2022-02-19 22:25:39 +00:00
if [ -d /dev/cryptvg ]; 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
2022-02-19 22:25:39 +00:00
if [ -b /dev/cryptvg/swap ]; then
swapoff /dev/cryptvg/swap || true
2020-01-31 11:00:17 +00:00
fi
2022-02-19 22:25:39 +00:00
vgchange -an /dev/cryptvg
2020-01-29 20:51:19 +00:00
fi
2021-03-12 13:25:29 +00:00
2020-01-29 20:42:06 +00:00
if [ -b /dev/mapper/cryptlvm ]; then
cryptsetup luksClose cryptlvm
fi
2021-03-12 13:25:29 +00:00
2020-01-29 20:42:06 +00:00
wipefs -a ${DEVICE}
2021-03-12 13:25:29 +00:00
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}
2022-02-15 04:43:07 +00:00
wipefs -a ${DEVICE}1
wipefs -a ${DEVICE}2
2021-03-12 13:25:29 +00:00
2020-01-29 20:02:02 +00:00
echo mkfs.ext4 ${DEVICE}1
2020-01-29 20:28:38 +00:00
yes | mkfs.ext4 ${DEVICE}1
2021-03-12 13:25:29 +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
2022-02-19 22:25:39 +00:00
vgcreate cryptvg /dev/mapper/cryptlvm
2021-03-12 13:25:29 +00:00
2020-01-31 14:38:41 +00:00
export LVM_SIZE=$(dev_size /dev/mapper/cryptlvm)
2021-03-12 13:25:29 +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))
2021-03-12 13:25:29 +00:00
2022-02-19 22:25:39 +00:00
echo lvcreate /dev/cryptvg --name=root --size=${ROOT_SIZE}M
lvcreate /dev/cryptvg --name=root --size=${ROOT_SIZE}M
yes | mkfs.btrfs /dev/cryptvg/root
2021-03-12 13:25:29 +00:00
2022-02-19 22:25:39 +00:00
echo lvcreate /dev/cryptvg --name=swap --size=${SWAP_SIZE}M
lvcreate /dev/cryptvg --name=swap --size=${SWAP_SIZE}M
mkswap /dev/cryptvg/swap
swapon /dev/cryptvg/swap
2021-03-12 13:25:29 +00:00
2022-02-18 22:02:22 +00:00
mkdir -p /tmp/mnt
2022-02-19 22:25:39 +00:00
mount /dev/cryptvg/root /tmp/mnt
2022-02-18 22:02:22 +00:00
btrfs subvolume create /tmp/mnt/@
btrfs subvolume create /tmp/mnt/@home
umount /tmp/mnt
2022-02-19 22:25:39 +00:00
echo mount -osubvol=@ /dev/cryptvg/root $TARGET
mount -osubvol=@ /dev/cryptvg/root $TARGET
2021-03-12 13:25:29 +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
2021-03-12 13:25:29 +00:00
2020-01-29 20:03:26 +00:00
mount ${DEVICE}1 $TARGET/boot
echo mount ${DEVICE}1 $TARGET/boot
2021-03-12 13:25:29 +00:00
2022-02-19 22:25:39 +00:00
echo mount -osubvol=@home /dev/cryptvg/root $TARGET/home
mount -osubvol=@home /dev/cryptvg/root $TARGET/home
2022-02-18 22:02:22 +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}')
2022-02-20 13:39:18 +00:00
echo cryptlvm UUID=${UUID} none luks,initramfs > $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
2021-03-11 22:21:29 +00:00
echo $NEW_HOSTNAME > /etc/hostname
hostname $NEW_HOSTNAME
2020-02-06 11:08:56 +00:00
sed -i 's/main/main contrib non-free/g' /etc/apt/sources.list
apt update
2022-02-20 13:39:18 +00:00
apt install -y linux-image-amd64 grub2 cryptsetup cryptsetup-initramfs cryptsetup-suspend 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}
2022-02-19 22:25:39 +00:00
update-grub
2022-02-20 13:39:18 +00:00
update-initramfs -k all -u
2020-01-29 21:44:06 +00:00
mkdir /snap
btrfs subvolume snapshot / /snap/$(date +%Y-%m-%d_basesystem)
2022-03-28 02:44:28 +00:00
apt install -y task-mate-desktop mate-desktop-environment-extra dbus-x11
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
2021-03-12 13:25:29 +00:00
2020-01-31 18:58:36 +00:00
btrfs subvolume snapshot / /snap/$(date +%Y-%m-%d_user_gui)
2022-02-17 22:25:22 +00:00
apt install -y git wget materia-gtk-theme htop nmap arandr timeshift gparted
2022-04-21 09:59:59 +00:00
apt install -y virt-manager telegram-desktop chromium firefox thunderbird geany vlc pidgin meld remmina gmpc
apt install -y gimp inkscape blender freecad kicad || true
2022-02-19 06:10:13 +00:00
btrfs subvolume snapshot / /snap/$(date +%Y-%m-%d_big_tools)
2022-03-27 10:43:13 +00:00
git clone https://github.com/robbyrussell/oh-my-zsh.git $HOME/.oh-my-zsh
2020-01-31 15:32:59 +00:00
chmod 0755 $HOME/.oh-my-zsh
chown -R jedi:jedi $HOME
2022-02-17 22:25:22 +00:00
chsh --shell /usr/bin/zsh jedi
2020-01-31 20:22:23 +00:00
2022-04-21 10:35:01 +00:00
echo second_stage done
2021-03-12 13:25:29 +00:00
export -f user_install
2022-04-21 16:06:09 +00:00
su jedi -c "bash -c user_install"
2021-03-12 13:25:29 +00:00
2020-01-31 17:21:30 +00:00
}
2020-01-31 15:32:59 +00:00
2022-03-28 00:34:29 +00:00
function user_install(){
2022-03-28 01:28:38 +00:00
set -e
2022-03-28 00:34:29 +00:00
2022-04-21 16:06:09 +00:00
export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i/home/jedi/.ssh/id_rsa"
2022-04-21 10:09:30 +00:00
2022-04-21 20:43:05 +00:00
export XDG_RUNTIME_DIR=/run/user/1000
2022-04-21 20:38:33 +00:00
2022-04-21 18:24:27 +00:00
dbus-launch dconf write /org/mate/desktop/interface/gtk-theme "'Materia-dark'" || true
dbus-launch dconf write /org/mate/marco/general/theme "'Materia-dark'" || true
dbus-launch dconf write /org/mate/desktop/interface/icon-theme "'Adwaita'" || true
dbus-launch dconf write /org/mate/desktop/peripherals/mouse/cursor-theme "'Adwaita'" || true
2022-03-28 00:34:29 +00:00
2022-04-21 16:06:09 +00:00
cd
rsync -a /root/unbox_data/secrets/SSH/ /home/jedi/.ssh/
2022-03-28 00:34:29 +00:00
git clone ssh://git@git.neulandlabor.de:2222/j3d1/laptop_tools.git Tools
2022-03-28 01:28:38 +00:00
echo $?
2022-03-28 00:34:29 +00:00
2022-04-21 18:57:00 +00:00
#wget https://data.services.jetbrains.com/products/releases?code=TBA&latest=true
#do jq stuff
2022-03-28 00:34:29 +00:00
#wget --show-progress -qO ./toolbox.tar.gz https://download.jetbrains.com/toolbox/jetbrains-toolbox-1.20.7940.tar.gz
#TOOLBOX_TEMP_DIR=$(mktemp -d)
#tar -C "$TOOLBOX_TEMP_DIR" -xf toolbox.tar.gz
#rm ./toolbox.tar.gz
#"$TOOLBOX_TEMP_DIR"/*/jetbrains-toolbox
#rm -r "$TOOLBOX_TEMP_DIR"
echo
}
2020-01-29 21:22:36 +00:00
2020-01-31 09:50:59 +00:00
function post_install_stage(){
sleep 0.5
2021-03-12 13:25:29 +00:00
mount | grep target | awk '{print $3}'| sort -r | while read LINE; do
umount -l $LINE;
done
2020-01-31 09:50:59 +00:00
}