Skip to content

Commit

Permalink
Backup/Restore ZFS datasets, show ip, fixes (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
midzelis authored Dec 9, 2024
1 parent 2053a37 commit de566cc
Show file tree
Hide file tree
Showing 15 changed files with 583 additions and 136 deletions.
510 changes: 415 additions & 95 deletions recipes/zquick_bootstrap/fs/zquick/libexec/installer/installer.sh

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions recipes/zquick_core/fs/init
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ start_getty() {
fi
}

export TERMINFO_DIRS=/usr/share/terminfo
export TERM=xterm-256color

. /zquick/libexec/utils.sh

# shellcheck disable=SC1091
. /etc/zquickinit.conf
if [[ -f "/etc/zfsbootmenu.conf" ]]; then
# shellcheck disable=SC1091
source /etc/zfsbootmenu.conf
fi

trap '' EXIT INT TERM
#tput clear
Expand Down
5 changes: 4 additions & 1 deletion recipes/zquick_core/fs/zquick/init
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ cat <<EOF
EOF

source /etc/zfsbootmenu.conf
if [[ -f "/etc/zfsbootmenu.conf" ]]; then
source /etc/zfsbootmenu.conf
fi

echo The controlling terminal is ${control_term}
echo This terminal is $(tty)
echo
Expand Down
13 changes: 11 additions & 2 deletions recipes/zquick_core/initcpio/install/zquick_core
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ add_terminfo() {
build() {
zquick_add_fs

add_binary lscpu

zquick_add_secret /etc/zquickinit.conf "zquick init"

add_terminfo
Expand All @@ -31,6 +33,10 @@ build() {
add_binary loadkeys
add_binary lspci
add_binary lshw

# prefer real readlink over busybox
add_binary readlink

if which yq-go >/dev/null; then
add_binary yq-go /bin/yq
else
Expand Down Expand Up @@ -90,7 +96,7 @@ build() {
libpaths+=("$line")
done <"$conf"
done
libs=(security/pam_warn.so security/pam_deny.so security/pam_unix.so security/pam_env.so security/pam_nologin.so)
libs=(security/pam_warn.so security/pam_deny.so security/pam_unix.so security/pam_env.so security/pam_nologin.so libnss_wrapper.so)
for llib in "${libs[@]}"; do
for ldir in "${libpaths[@]}"; do
lib=${ldir}/${llib}
Expand All @@ -99,7 +105,10 @@ build() {
done

# UDEV stuff
use_systemd=$(sed -rn '/^use_systemd=/s/.*=(.*)/\1/p' "${zquickinit_config}/etc/zquickinit.conf")
use_systemd="no"
if [[ -f "${zquickinit_config}/etc/zquickinit.conf" ]]; then
use_systemd=$(sed -rn '/^use_systemd=/s/.*=(.*)/\1/p' "${zquickinit_config}/etc/zquickinit.conf")
fi
if [[ "${use_systemd}" = "yes" ]]; then
echo "use systemd"
else
Expand Down
2 changes: 1 addition & 1 deletion recipes/zquick_core/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ xbps-packages:
- busybox-huge
- util-linux
- pciutils
- lshw
- lshw - nss_wrapper
debian-packages:
- kbd
help: "Required common dependencies to all recipes"
9 changes: 7 additions & 2 deletions recipes/zquick_hostname/initcpio/install/zquick_hostname
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

build() {

zquick_add_fs

if [[ $RELEASE == 1 ]]; then
echo "Zquickinit" >"$BUILDROOT/etc/hostname"
return
fi

for hostname in "$zquickinit_config/etc/hostname" "/etc/hostname"; do
[[ -f "$hostname" ]] && break
done

warning "using $hostname"
if [ ! -r "$hostname" ]; then
warning "Hostname not found"
else
add_file "$hostname" /etc/hostname
fi

zquick_add_fs
}
6 changes: 3 additions & 3 deletions recipes/zquick_lvm/initcpio/install/zquick_lvm
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ build() {

# binaries from lvm2
add_binary "lvm"
if which lvmetad > /dev/null; then
add_binary "lvmetad"
if which lvmetad >/dev/null 2>&1; then
add_binary "lvmetad"
fi

# binaries from device-mapper
Expand Down Expand Up @@ -44,4 +44,4 @@ build() {

add_file "/etc/lvm/lvm.conf"

}
}
13 changes: 8 additions & 5 deletions recipes/zquick_qemu/fs/zquick/hooks/init.d/20-qemu_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

source /zquick/libexec/utils.sh

qinitlog "QEMU mounting shared directories /mnt/qemu-host, /mnt/cache"
if grep -q "hypervisor" /proc/cpuinfo; then

mkdir -p /mnt/qemu-host
mount -t 9p -o trans=virtio qemuhost /mnt/qemu-host -oversion=9p2000.L,posixacl,msize=104857600 >/dev/null 2>&1 || rmdir /mnt/qemu-host
mkdir -p /mnt/cache
mount -t 9p -o trans=virtio qemucache /mnt/cache -oversion=9p2000.L,posixacl,msize=104857600 >/dev/null 2>&1 || rmdir /mnt/cache
qinitlog "Detected KVM: QEMU mounting shared directories /mnt/qemu-host, /mnt/cache"

mkdir -p /mnt/qemu-host
mount -t 9p -o trans=virtio qemuhost /mnt/qemu-host -oversion=9p2000.L,posixacl,msize=104857600 >/dev/null 2>&1 || rmdir /mnt/qemu-host
mkdir -p /mnt/cache
mount -t 9p -o trans=virtio qemucache /mnt/cache -oversion=9p2000.L,posixacl,msize=104857600 >/dev/null 2>&1 || rmdir /mnt/cache
fi
26 changes: 23 additions & 3 deletions recipes/zquick_sshd/initcpio/install/zquick_sshd
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#!/bin/bash

wrap_user() {
U=$(id -u)
G=$(id -g)

HOME_DIR=/tmp/user
PASSWD=/var/tmp/passwd
GROUP=/var/tmp/group

if [ ! -d "$HOME_DIR" ]; then
mkdir "$HOME_DIR"
fi
if [ ! -f "$PASSWD" ]; then
echo "user::$U:$G::$HOME_DIR:" >"$PASSWD"
fi
if [ ! -f "$GROUP" ]; then
echo "user::$G:" >"$GROUP"
fi

LD_PRELOAD=libnss_wrapper.so NSS_WRAPPER_PASSWD="$PASSWD" NSS_WRAPPER_GROUP="$GROUP" "$@"
}
build() {
zquick_add_fs

Expand All @@ -19,14 +39,14 @@ build() {
zquick_add_secret /etc/ssh/sshd_config "sshd configuration" 644

if [[ ! -e "${BUILDROOT}/etc/ssh/ssh_host_rsa_key" && ! -e "${BUILDROOT}/etc/ssh/ssh_host_ecdsa_key" && ! -e "${BUILDROOT}/etc/ssh/ssh_host_ed25519_key" ]]; then
msg2 "No host keys specified, autogenerating new keys for this build. Keys will be not be saved to zquickinit configuration area."
ssh-keygen -A -f "${BUILDROOT}"
msg2 "NOTICE: No host keys specified, autogenerating new keys for this build. Keys will be not be saved to zquickinit configuration area."
wrap_user ssh-keygen -A -f "${BUILDROOT}"
fi

if [[ ! -e "${BUILDROOT}/etc/ssh/sshd_config" ]]; then
msg2 "sshd_config not found, sshd will likely not run until this file is present. (Can be injected into image later)"
elif [[ ! -e "${BUILDROOT}/root/.ssh/authorized_keys" ]]; then
msg2 "/root/.ssh/authorized_keys not found."
msg2 "NOTICE: /root/.ssh/authorized_keys not found."
fi

}
4 changes: 2 additions & 2 deletions recipes/zquick_sshd/recipe.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
xbps-packages:
- openssh
help: "Includes: `sshd` (OpenSSH)"
- openssh
help: "Includes: `sshd` (OpenSSH)"
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
# shellcheck disable=SC1091
. /zquick/libexec/utils.sh

qloginit "Tailscale - Closing SSH sessions"
qinitlog "Tailscale - Closing SSH sessions"
pkill -HUP sshd
pkill -HUP login
3 changes: 2 additions & 1 deletion recipes/zquick_tmux/fs/zquick/hooks/bash.d/00-tmux.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash

if [[ -z $TMUX ]]; then
export TERMINFO_DIRS=/usr/share/terminfo
export TERM=xterm-256color
if tmux -2 -u new-session -A -s ZFSBootMenu; then
exit 0
fi
echo "tmux exited with error, starting shell..."
exec /bin/sh
fi

9 changes: 8 additions & 1 deletion recipes/zquick_tmux/fs/zquick/libexec/tmux/status.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/bash

getip() {
interface=$(ip route | grep default | awk '{print $5}')
# Get the IP address associated with the active interface
ip_address=$(ip -4 addr show $interface | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
echo "$ip_address"
}
status+="#[fg=colour255,bg=colour17] Hostname [#[fg=colour255,bg=colour25]$(hostname)"
status+="#[fg=colour255,bg=colour17]] | ip [#[fg=colour255,bg=colour25]$(getip)"
status+="#[fg=colour255,bg=colour17]] | Tailscale [#[fg=colour0,bg=colour25]"
if which tailscale >/dev/null && [[ -r /var/lib/tailscale/tailscaled.state ]]; then
if which tailscale >/dev/null2 >&1 && [[ -r /var/lib/tailscale/tailscaled.state ]]; then
ts_status=$(tailscale status --json)
if [[ $(echo "$ts_status" | yq e '.Self.Online' -oy) == "true" ]]; then
status+=" UP "
Expand Down
6 changes: 4 additions & 2 deletions recipes/zquick_tmux/fs/zquick/libexec/tmux/t.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/bin/bash
if [[ -z $TMUX ]]; then
export TERMINFO_DIRS=/usr/share/terminfo
export TERM=xterm-256color
if tmux -2 -u new-session -A -s ZFSBootMenu; then
exit 0
fi
echo "tmux exited with error, starting shell..."
echo "tmux exited with error, starting shell... tt"
exec /bin/sh
fi
fi
Loading

0 comments on commit de566cc

Please sign in to comment.