pluh 🗣
This commit is contained in:
parent
3ad9944baa
commit
668140531b
59 changed files with 985 additions and 219 deletions
|
@ -19,50 +19,98 @@ error() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
args=$(getopt --options r:m:b:l:c: --longoptions=root:,mapping:,boot-label:,main-label:,cryptmain-label: --name "$progname" -- "$@")
|
||||
skip() {
|
||||
if (($# < 1)); then
|
||||
error 'name of value to be skipped is required'
|
||||
fi
|
||||
|
||||
if (($# > 1)); then
|
||||
error 'too many arguments'
|
||||
fi
|
||||
|
||||
local skip=$1
|
||||
|
||||
for s in "${skips[@]}"; do
|
||||
if [[ $s == "$skip" ]]; then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
args=$(
|
||||
getopt \
|
||||
--options r:b:l:c:m:B:M:v \
|
||||
--longoptions root:,boot-label:,main-label:,cryptmain-label:,mapping:,boot-options:,main-options:,verbose \
|
||||
--name "$progname" \
|
||||
-- "$@"
|
||||
)
|
||||
|
||||
eval set -- "$args"
|
||||
|
||||
root=/mnt
|
||||
mapping=main
|
||||
bootlbl=BOOT
|
||||
mainlbl=main
|
||||
cryptmainlbl=cryptmain
|
||||
mapping=main
|
||||
bootflags=
|
||||
mainflags=
|
||||
fatflags=()
|
||||
ext4flags=()
|
||||
skips=()
|
||||
while true; do
|
||||
case "$1" in
|
||||
(-r | --root)
|
||||
root=$2
|
||||
shift 2
|
||||
;;
|
||||
(-m | --mapping)
|
||||
mapping=$2
|
||||
shift 2
|
||||
;;
|
||||
(-b | --boot-label)
|
||||
bootlbl=${2^^}
|
||||
shift 2
|
||||
;;
|
||||
(-l | --main-label)
|
||||
mainlbl=$2
|
||||
shift 2
|
||||
;;
|
||||
(-c | --cryptmain-label)
|
||||
cryptmainlbl=$2
|
||||
shift 2
|
||||
;;
|
||||
(--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
case "$1" in
|
||||
-r | --root)
|
||||
root=$2
|
||||
shift 2
|
||||
;;
|
||||
-b | --boot-label)
|
||||
skips+=(bootlbl)
|
||||
bootlbl=${2^^}
|
||||
shift 2
|
||||
;;
|
||||
-l | --main-label)
|
||||
skips+=(mainlbl)
|
||||
mainlbl=$2
|
||||
shift 2
|
||||
;;
|
||||
-c | --cryptmain-label)
|
||||
skips+=(cryptmainlbl)
|
||||
cryptmainlbl=$2
|
||||
shift 2
|
||||
;;
|
||||
-m | --mapping)
|
||||
skips+=(mapping)
|
||||
mapping=$2
|
||||
shift 2
|
||||
;;
|
||||
-B | --boot-options)
|
||||
bootflags+=(--options "$2")
|
||||
shift 2
|
||||
;;
|
||||
-M | --main-options)
|
||||
mainflags+=(--options "$2")
|
||||
shift 2
|
||||
;;
|
||||
-v | --verbose)
|
||||
fatflags+=(-v)
|
||||
ext4flags+=(-v)
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if (( $# < 1 )); then
|
||||
error 'an argument specifying the block device is required'
|
||||
if (($# < 1)); then
|
||||
error 'an argument specifying the block device is required'
|
||||
fi
|
||||
|
||||
if (( $# > 1 )); then
|
||||
error 'too many arguments'
|
||||
if (($# > 1)); then
|
||||
error 'too many arguments'
|
||||
fi
|
||||
|
||||
blkdev=$1
|
||||
|
@ -75,45 +123,74 @@ EOF
|
|||
parts=()
|
||||
json=$(sfdisk --json -- "$blkdev")
|
||||
while IFS= read -r k; do
|
||||
parts+=("$(jq --argjson k "$k" --raw-output '.partitiontable.partitions[$k].node' <<<"$json")")
|
||||
parts+=("$(jq --argjson k "$k" --raw-output '.partitiontable.partitions[$k].node' <<<"$json")")
|
||||
done < <(jq '.partitiontable.partitions | keys[]' <<<"$json")
|
||||
|
||||
bootfs="${parts[0]}"
|
||||
mainblkdev="${parts[1]}"
|
||||
|
||||
mkfs.vfat -F 32 -n "$bootlbl" -- "$bootfs" >/dev/null
|
||||
if ! skip bootlbl; then
|
||||
read -rep "Which label should the boot file system have? [$bootlbl] " input
|
||||
if [[ -n $input ]]; then
|
||||
bootlbl=$input
|
||||
fi
|
||||
fi
|
||||
|
||||
mkfs.fat -F 32 -n "$bootlbl" "${fatflags[@]}" -- "$bootfs" >/dev/null
|
||||
|
||||
while true; do
|
||||
read -r -p 'Do you want your main partition to be encrypted [y/N]? ' luks
|
||||
case "$luks" in
|
||||
([Yy]*)
|
||||
while true; do
|
||||
read -r -s -p 'Enter password: ' password
|
||||
warn ''
|
||||
read -r -s -p 'Re-enter password: ' repassword
|
||||
warn ''
|
||||
if [[ $password == "$repassword" ]]; then
|
||||
read -rep 'Do you want your main partition to be encrypted? [y/N] ' input
|
||||
case "$input" in
|
||||
[Yy]*)
|
||||
while true; do
|
||||
read -rsp 'Enter password: ' password
|
||||
warn ''
|
||||
read -rsp 'Re-enter password: ' repassword
|
||||
warn ''
|
||||
if [[ $password == "$repassword" ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if ! skip cryptmainlbl; then
|
||||
read -rep "Which label should the main LUKS partition have? [$cryptmainlbl] " input
|
||||
if [[ -n $input ]]; then
|
||||
cryptmainlbl=$input
|
||||
fi
|
||||
fi
|
||||
|
||||
cryptsetup luksFormat --batch-mode --label "$cryptmainlbl" -- "$mainblkdev" <<<"$password"
|
||||
|
||||
if ! skip mapping; then
|
||||
read -rep "Which name should the main LUKS mapping have? [$mapping] " input
|
||||
if [[ -n $input ]]; then
|
||||
mapping=$input
|
||||
fi
|
||||
fi
|
||||
|
||||
cryptsetup open -- "$mainblkdev" "$mapping" <<<"$password"
|
||||
|
||||
mainfs=/dev/mapper/$mapping
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
cryptsetup luksFormat --batch-mode --label "$cryptmainlbl" "$mainblkdev" <<<"$password"
|
||||
cryptsetup open "$mainblkdev" "$mapping" <<<"$password"
|
||||
|
||||
mainfs=/dev/mapper/$mapping
|
||||
break
|
||||
;;
|
||||
('' | [Nn]*)
|
||||
mainfs=$mainblkdev
|
||||
break
|
||||
;;
|
||||
(*) warn 'Please answer with yes or no' ;;
|
||||
esac
|
||||
;;
|
||||
'' | [Nn]*)
|
||||
mainfs=$mainblkdev
|
||||
break
|
||||
;;
|
||||
*) warn 'Please answer with yes or no' ;;
|
||||
esac
|
||||
done
|
||||
|
||||
mkfs.ext4 -q -F -L "$mainlbl" -- "$mainfs"
|
||||
if ! skip mainlbl; then
|
||||
read -rep "Which label should the main file system have? [$mainlbl] " input
|
||||
if [[ -n $input ]]; then
|
||||
mainlbl=$input
|
||||
fi
|
||||
fi
|
||||
|
||||
mkfs.ext4 -qFL "$mainlbl" "${ext4flags[@]}" -- "$mainfs"
|
||||
mkdir --parents -- "$root"
|
||||
mount --options noatime -- "$mainfs" "$root"
|
||||
mount "${mainflags[@]}" -- "$mainfs" "$root"
|
||||
|
||||
mkdir -- "$root/boot"
|
||||
mount -- "$bootfs" "$root/boot"
|
||||
mount "${bootflags[@]}" -- "$bootfs" "$root/boot"
|
||||
|
|
|
@ -19,10 +19,19 @@ error() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
args=$(getopt --options f:o:t:v --longoptions=flake:,on:,to:,verbose --name "$progname" -- "$@")
|
||||
args=$(
|
||||
getopt \
|
||||
--options F:f:o:t:v \
|
||||
--longoptions flakeref:,flake:,on:,to:,verbose \
|
||||
--name "$progname" \
|
||||
-- "$@"
|
||||
)
|
||||
|
||||
eval set -- "$args"
|
||||
|
||||
if [[ -n $PUTER_FLAKEREF ]]; then
|
||||
flakeref=$PUTER_FLAKEREF
|
||||
fi
|
||||
flags=(
|
||||
--refresh
|
||||
--use-remote-sudo
|
||||
|
@ -31,25 +40,29 @@ flags=(
|
|||
verbose=false
|
||||
while true; do
|
||||
case $1 in
|
||||
(-f | --flake)
|
||||
-F | --flakeref)
|
||||
flakeref=$2
|
||||
shift 2
|
||||
;;
|
||||
-f | --flake)
|
||||
flake=$2
|
||||
shift 2
|
||||
;;
|
||||
(-o | --on)
|
||||
-o | --on)
|
||||
flags+=(--build-host "$2")
|
||||
shift 2
|
||||
;;
|
||||
(-t | --to)
|
||||
-t | --to)
|
||||
host=$2
|
||||
flags+=(--target-host "$host")
|
||||
shift 2
|
||||
;;
|
||||
(-v | --verbose)
|
||||
-v | --verbose)
|
||||
flags+=(--verbose)
|
||||
verbose=true
|
||||
shift
|
||||
;;
|
||||
(--)
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
|
@ -57,17 +70,26 @@ while true; do
|
|||
done
|
||||
|
||||
if [[ ! -v flake ]]; then
|
||||
if [[ -v host ]]; then
|
||||
hostname=$(ssh -- "$host" hostname)
|
||||
if [[ -v flakeref ]]; then
|
||||
warn "using flake reference $flakeref"
|
||||
if [[ -v host ]]; then
|
||||
hostname=$(ssh -- "$host" hostname)
|
||||
else
|
||||
hostname=$(hostname)
|
||||
fi
|
||||
if [[ -z $hostname ]]; then
|
||||
error 'hostname could not be resolved and no flake specified'
|
||||
fi
|
||||
flake=$flakeref#$hostname
|
||||
warn "resolved to $flake"
|
||||
else
|
||||
hostname=$(hostname)
|
||||
error 'no flake or flake reference specified'
|
||||
fi
|
||||
flake=git+https://forgejo@tea.wrz.one/lukas/puter.git#$hostname
|
||||
fi
|
||||
|
||||
flags+=(--flake "$flake")
|
||||
|
||||
if (( $# == 0 )); then
|
||||
if (($# == 0)); then
|
||||
error 'a subcommand is required'
|
||||
fi
|
||||
|
||||
|
@ -84,25 +106,25 @@ run() {
|
|||
sub=$1
|
||||
|
||||
case $sub in
|
||||
(s | switch)
|
||||
shift
|
||||
s | switch)
|
||||
shift
|
||||
|
||||
if (( $# > 0 )); then
|
||||
error 'too many arguments'
|
||||
fi
|
||||
if (($# > 0)); then
|
||||
error 'too many arguments'
|
||||
fi
|
||||
|
||||
run switch
|
||||
;;
|
||||
(b | boot)
|
||||
shift
|
||||
run switch
|
||||
;;
|
||||
b | boot)
|
||||
shift
|
||||
|
||||
if (( $# > 0 )); then
|
||||
error 'too many arguments'
|
||||
fi
|
||||
if (($# > 0)); then
|
||||
error 'too many arguments'
|
||||
fi
|
||||
|
||||
run boot
|
||||
;;
|
||||
(*)
|
||||
error 'invalid subcommand'
|
||||
;;
|
||||
run boot
|
||||
;;
|
||||
*)
|
||||
error 'invalid subcommand'
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue