guix-strap
This commit is contained in:
parent
b704c73107
commit
80df8ba1b3
5 changed files with 188 additions and 0 deletions
62
guix-strap/guix-crypt
Executable file
62
guix-strap/guix-crypt
Executable file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source ./guix-log
|
||||
source ./guix-env
|
||||
|
||||
CRYPT_PARTITION=""
|
||||
EFI_PARTITION=""
|
||||
PASSWORD=""
|
||||
PASSWORD_CONFIRM=""
|
||||
|
||||
EVENT "Setting up disk encryption with luks"
|
||||
|
||||
if [[ $DISK == sd* ]]; then
|
||||
CRYPT_PARTITION="$DISK""2"
|
||||
EFI_PARTITION="$DISK""1"
|
||||
elif [[ $DISK == nvme** ]]; then
|
||||
CRYPT_PARTITION="$DISK""p2"
|
||||
EFI_PARTITION="$DISK""p1"
|
||||
else
|
||||
ERROR "Unsupported drive type, must be sata or nvme!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
get_password() {
|
||||
read -s -p "LUKS password: " PASSWORD
|
||||
read -s -p "Confirm password: " PASSWORD_CONFIRM
|
||||
if [ "$PASSWORD" == "$CONFIRM_PASSWORD" ]; then
|
||||
exit 0
|
||||
else
|
||||
ERROR "Passwords do not match"
|
||||
get_password
|
||||
fi
|
||||
}
|
||||
|
||||
get_password
|
||||
|
||||
EVENT "Setting up luks"
|
||||
|
||||
cryptsetup luksFormat --type luks1 "$CRYPT_PARTITION" <<EOF
|
||||
YES
|
||||
$PASSWORD
|
||||
$CONFIRM_PASSWORD
|
||||
EOF
|
||||
|
||||
EVENT "Opening cryptroot"
|
||||
|
||||
cryptsetup open "$CRYPT_PARTITION" cryptroot <<EOF
|
||||
$PASSWORD
|
||||
EOF
|
||||
|
||||
EVENT "Mounting cryptroot"
|
||||
|
||||
mount /dev/mapper/cryptroot /mnt
|
||||
|
||||
EVENT "Setting up EFI vfat"
|
||||
|
||||
mkfs.vfat "-F32" "$EFI_PARTITION"
|
||||
|
||||
EVENT "Successfully setup efi vfat and luks"
|
||||
|
||||
echo "CRYPT_PARTITION=\"$CRYPT_PARTITION\"" > ./guix-env
|
||||
echo "EFI_PARTITION=\"$EFI_PARTITION\"" > ./guix-env
|
3
guix-strap/guix-env
Executable file
3
guix-strap/guix-env
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# added by scripts during runtime!!!
|
10
guix-strap/guix-log
Executable file
10
guix-strap/guix-log
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
ERROR() {
|
||||
>&2 printf "\x1b[91mError: \x1b[0m\x1b[98m$1\n"
|
||||
}
|
||||
|
||||
EVENT() {
|
||||
printf "\x1b[95m>>> \x1b[0m\x1b[98m$1\n"
|
||||
}
|
||||
|
79
guix-strap/guix-partition
Executable file
79
guix-strap/guix-partition
Executable file
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o emacs;
|
||||
|
||||
CONFIRM=""
|
||||
DISK=""
|
||||
|
||||
source ./guix-log
|
||||
source ./guix-env
|
||||
|
||||
EVENT "Partitioning disks"
|
||||
|
||||
confirm() {
|
||||
if [ "$CONFIRM" == "y" ]; then
|
||||
exit 0
|
||||
fi
|
||||
read -p "Are you sure: ($1)? [y/N] " CONFIRM
|
||||
if [ "$CONFIRM" == "y" ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
check_disk() {
|
||||
lsblk $1 &> /dev/null || exit 1
|
||||
FS=$(df $1 | tail -n 1 | awk '{print $1}')
|
||||
if [ "$FS" == "none" ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
get_disk() {
|
||||
CONFIRM=""
|
||||
read -ep "Enter disk (e.g. /dev/sda): " DISK
|
||||
if [ ! -b "$DISK" ]; then
|
||||
ERROR "$DISK: file does not exist"
|
||||
get_disk
|
||||
return
|
||||
fi
|
||||
(check_disk "$DISK");
|
||||
if [ "$?" -ne 0 ]; then
|
||||
ERROR "$DISK: not a valid disk"
|
||||
get_disk
|
||||
return
|
||||
fi
|
||||
(confirm "$DISK");
|
||||
if [ "$?" -ne 0 ]; then
|
||||
get_disk
|
||||
fi
|
||||
}
|
||||
|
||||
get_disk
|
||||
|
||||
EVENT "Partitioning disks with fdisk..."
|
||||
|
||||
fdisk "$DISK" <<EOF
|
||||
g
|
||||
n
|
||||
|
||||
|
||||
+1GiB
|
||||
t
|
||||
EFI System
|
||||
n
|
||||
|
||||
|
||||
|
||||
t
|
||||
2
|
||||
Linux Filesystem
|
||||
w
|
||||
EOF
|
||||
|
||||
echo "DISK=\"$DISK\"" >> ./guix-env
|
||||
|
||||
EVENT "Disks have been successfully partitioned on $DISK"
|
34
guix-strap/guix-setup
Executable file
34
guix-strap/guix-setup
Executable file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
welcome() {
|
||||
cat<<"EOF"
|
||||
░░░ ░░░
|
||||
░░▒▒░░░░░░░░░ ░░░░░░░░░▒▒░░
|
||||
░░▒▒▒▒▒░░░░░░░ ░░░░░░░▒▒▒▒▒░
|
||||
░▒▒▒░░▒▒▒▒▒ ░░░░░░░▒▒░
|
||||
░▒▒▒▒░ ░░░░░░
|
||||
▒▒▒▒▒ ░░░░░░
|
||||
▒▒▒▒▒ ░░░░░
|
||||
░▒▒▒▒▒ ░░░░░
|
||||
▒▒▒▒▒ ░░░░░
|
||||
▒▒▒▒▒ ░░░░░
|
||||
░▒▒▒▒▒░░░░░
|
||||
▒▒▒▒▒▒░░░
|
||||
▒▒▒▒▒▒░
|
||||
____ _ _ _____ __ ____ _
|
||||
/ ___| | | |_ _\ \/ / / ___|| |_ _ __ __ _ _ __
|
||||
| | _| | | || | \ / \___ \| __| '__/ _` | '_ \
|
||||
| |_| | |_| || | / \ ___) | |_| | | (_| | |_) |
|
||||
\____|\___/|___/_/\_\ |____/ \__|_| \__,_| .__/
|
||||
|_|
|
||||
This script installs GNU Guix on your system
|
||||
|
||||
https://www.gnu.org/software/guix/
|
||||
EOF
|
||||
echo -n "Press return to continue..."
|
||||
read -r ANSWER
|
||||
}
|
||||
|
||||
welcome
|
||||
./guix-partition
|
||||
./guix-setup
|
Loading…
Reference in a new issue