This commit is contained in:
2023-11-29 11:25:24 +01:00
parent b08325c2cf
commit abd11f65b9
4 changed files with 81 additions and 12 deletions
+65
View File
@@ -0,0 +1,65 @@
# startx checks if disks are mounted
def startx [] {
# I'm used to running startx right after I login, to this first mount my
# disks and then runs startx.
mount-disk
# Then I run startx
/bin/startx
}
# mount my encrypted disks
def mount-disk [] {
# If there is no $env.PRIMARY_DISK_UUID, we don't have to decrypt / mount anything
if not ("PRIMARY_DISK_UUID" in $env) {
return
}
# In my home on my encrypted partition, I have an empty file in ~/.mounted,
# this way, I can easily check if my encrypted partition is mounted or not.
if ("~/.mounted"| path exists) {
print -en "already mounted\n"
return
}
mut passphrase = ""
# On my computer, I have two disks, one NVMe with my OS, and one HDD with
# more space. I want three attempts at typing the passphrase.
for retry in [1, 2, 3] {
# Because they're encrypted with the same passphrase, I read the
# passphrase once, and then decrypt both disks.
sudo echo -n
let local_passphrase = (input -s "Enter your passphrase: ")
print -en "\n"
# Mount the NVMe encrypted partition
let mounted = do { $local_passphrase | sudo cryptsetup luksOpen ("/dev/disk/by-uuid/" + $env.PRIMARY_DISK_UUID) luks } | complete
# If mounted correctly, break this loop and mount other partitions.
if $mounted.exit_code == 0 {
print -en (ansi green_bold) "Passphrase correct\n" (ansi reset)
$passphrase = $local_passphrase
break
} else if $retry == 3 {
# If the third attempt failed, exit
error make {msg: "couldn't decrypt disk"}
} else {
print -en (ansi red_bold) "Passphrase incorrect, please try again\n" (ansi reset)
}
}
sudo mount /dev/mapper/luks /home
if ("SECONDARY_DISK_UUID" in $env) {
$passphrase | sudo cryptsetup luksOpen ("/dev/disk/by-uuid/" + $env.SECONDARY_DISK_UUID) luks2
sudo mount /dev/mapper/luks2 /mnt
}
# Some services cannot be started on boot because my encrypted drives are
# not mounted yet, so I mount them here.
systemctl start --user pueued
sudo systemctl start docker
}
+6 -2
View File
@@ -1,7 +1,9 @@
# nushell puts prompt at bottom of terminal on resize, so it's preferable to start on the bottom of the terminal
let has_tfetch = not (which tfetch | is-empty)
# tfetch takes 19 lines, 21 with prompt
let height = (stty size | split row " " | get 0 | into int) - 21
let height = (stty size | split row " " | get 0 | into int) - (if $has_tfetch { 21 } else { 0 })
# skip lines so that the prompt starts at the bottom of the terminal
for i in 0..<$height {
@@ -9,4 +11,6 @@ for i in 0..<$height {
}
# Start tfetch
tfetch
if $has_tfetch {
tfetch
}