2021-03-11 14:04:04 +01:00
|
|
|
module start "basesystem" "Install Basesystem"
|
|
|
|
|
2021-03-16 22:25:12 +01:00
|
|
|
diskid="${cfg[diskid]//-/_}"
|
|
|
|
|
2021-03-11 14:04:04 +01:00
|
|
|
chown root:root /
|
|
|
|
chmod 755 /
|
|
|
|
|
2021-03-16 20:17:51 +01:00
|
|
|
mkdir -p /etc/xbps.d/
|
2021-03-11 14:04:04 +01:00
|
|
|
{ echo "#ignorepkg=linux-firmware-amd";
|
|
|
|
echo "#ignorepkg=linux-firmware-intel";
|
|
|
|
echo "#ignorepkg=linux-firmware-nvidia";
|
|
|
|
echo "#ignorepkg=linux-firmware-broadcom";
|
2021-03-16 20:17:51 +01:00
|
|
|
echo "#ignorepkg=wifi-firmware"; } > /etc/xbps.d/10-ignore-firmware.conf
|
2021-03-11 14:04:04 +01:00
|
|
|
|
|
|
|
{ echo "en_DK.UTF-8 UTF-8";
|
2021-03-16 20:45:57 +01:00
|
|
|
echo "${cfg[lang]}.UTF-8 UTF-8";
|
2021-03-16 20:17:51 +01:00
|
|
|
echo "en_US.UTF-8 UTF-8"; } > /etc/default/libc-locales
|
2021-03-13 10:50:50 +01:00
|
|
|
|
2021-03-16 20:17:51 +01:00
|
|
|
echo "LANG=en_US.UTF-8" > /etc/locale.conf
|
|
|
|
echo "KEYMAP=${cfg[lang_console]}" > /etc/vconsole.conf
|
|
|
|
echo "LANG=${cfg[lang]}.UTF-8" > /etc/locale-user.conf
|
2021-03-12 20:24:09 +01:00
|
|
|
|
2021-04-14 20:37:00 +02:00
|
|
|
cp -a /etc/profile.d/locale.sh /etc/profile.d/zz-locale-user.sh
|
2021-03-16 20:17:51 +01:00
|
|
|
sed -i 's/locale.conf/locale-user.conf/' /etc/profile.d/zz-locale-user.sh
|
|
|
|
sed -i '/^if/i [ "$(id -u)" -eq 0 ] && return' /etc/profile.d/zz-locale-user.sh
|
2021-03-11 14:04:04 +01:00
|
|
|
|
|
|
|
{ echo "tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0";
|
2021-04-14 14:10:53 +02:00
|
|
|
echo "/dev/mapper/voidvg.${diskid}-root / btrfs defaults,subvol=rootfs 0 0";
|
|
|
|
echo "/dev/mapper/voidvg.${diskid}-root /home btrfs defaults,subvol=homefs 0 0";
|
2021-03-13 12:25:43 +01:00
|
|
|
echo "/dev/mapper/voidvg.${diskid}-swap swap swap defaults 0 0";
|
2021-04-14 14:10:53 +02:00
|
|
|
echo "/dev/mapper/voidvg.${diskid}-root /var/lib/backup/quelle/rootfs btrfs defaults 0 0"; } > /etc/fstab
|
|
|
|
if [[ "${cfg[fde_key_store]}" == "once" ]]; then
|
2021-04-15 10:17:58 +02:00
|
|
|
{ echo "UUID=${cfg[bootuuid]} /boot btrfs defaults,subvol=bootfs 0 0";
|
2021-04-14 14:10:53 +02:00
|
|
|
echo "UUID=${cfg[bootuuid]} /var/lib/backup/quelle/bootfs btrfs defaults 0 0"; } >> /etc/fstab
|
|
|
|
fi
|
2021-03-13 12:25:43 +01:00
|
|
|
|
2021-03-16 20:17:51 +01:00
|
|
|
mkdir -p /etc/sudoers.d
|
2021-03-11 14:04:04 +01:00
|
|
|
{ echo 'Defaults timestamp_timeout=15';
|
|
|
|
echo 'Defaults !tty_tickets';
|
|
|
|
echo 'Defaults umask = 022';
|
|
|
|
echo 'Defaults passprompt="[sudo] Password: "';
|
|
|
|
echo '%wheel ALL=(ALL) ALL';
|
|
|
|
echo 'Defaults editor = /usr/bin/nvim';
|
2021-04-05 13:34:07 +02:00
|
|
|
echo 'Defaults env_keep += "EDITOR"';
|
2021-04-07 19:00:09 +02:00
|
|
|
echo 'Defaults env_keep += "SSH_CONNECTION"'; } > /etc/sudoers.d/10-common
|
2021-04-14 14:10:53 +02:00
|
|
|
|
2021-03-16 20:17:51 +01:00
|
|
|
mkdir -p /etc/udev/rules.d/
|
|
|
|
echo 'ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"' > /etc/udev/rules.d/mount-media.rules
|
|
|
|
echo 'ACTION=="add|change", KERNEL=="sd[a-z]|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline"' > /etc/udev/rules.d/60-ioschedulers.rules
|
2021-03-11 14:04:04 +01:00
|
|
|
|
2021-03-16 20:17:51 +01:00
|
|
|
mkdir -p /etc/bash/bashrc.d/
|
2021-04-14 20:37:00 +02:00
|
|
|
cat <<'EOF' > /etc/bash/bashrc.d/xbps-aliase.sh
|
|
|
|
[ "$(id -u)" -eq 0 ] && return
|
|
|
|
alias xu="sudo void-update"
|
|
|
|
alias xr="sudo xbps-remove -R"
|
|
|
|
alias xs="xbps-query -Rs"
|
|
|
|
alias backup="sudo void-backup"
|
|
|
|
echo "xu = sudo void-update zum updaten"
|
|
|
|
echo "xi = sudo xbps-install -S zum installieren"
|
|
|
|
echo "xr = sudo xbps-remove -R zum deinstallieren"
|
|
|
|
echo "xs = xbps-query -Rs zum suchen"
|
|
|
|
echo "backup = sudo void-backup um ein backup zu machen"
|
|
|
|
EOF
|
2021-03-11 14:04:04 +01:00
|
|
|
|
2021-04-14 20:37:00 +02:00
|
|
|
echo "${cfg[hostname]}" > /etc/hostname
|
|
|
|
ln -sf "/usr/share/zoneinfo/${cfg[timezone]}" /etc/localtime
|
|
|
|
sed -i "s/#HOSTNAME=\"void-live\"/HOSTNAME=${cfg[hostname]}/g" /etc/rc.conf
|
|
|
|
sed -i "s/Europe\/Madrid/${cfg[timezone]//\//\\/}/" /etc/rc.conf
|
|
|
|
sed -i "/HARDWARECLOCK/s/^#//g" /etc/rc.conf
|
|
|
|
sed -i "/FONT=/s/^#//g" /etc/rc.conf
|
2021-03-11 14:04:04 +01:00
|
|
|
|
2021-03-13 11:38:34 +01:00
|
|
|
if [[ ! ${cfg[fde_key_store]} == "none" ]]; then
|
2021-03-17 00:18:46 +01:00
|
|
|
echo "read -p \"Change PW for disk? y/n \" answer" > /etc/runit/core-services/99-changepwdisk.sh
|
2021-03-16 23:06:15 +01:00
|
|
|
echo "if [ \"\${answer}\" = \"y\" ]; then" >> /etc/runit/core-services/99-changepwdisk.sh
|
|
|
|
echo " while ! cryptsetup luksChangeKey /dev/disk/by-uuid/${cfg[partuuid]}; do" >> /etc/runit/core-services/99-changepwdisk.sh
|
|
|
|
echo " echo \"Again, please\"" >> /etc/runit/core-services/99-changepwdisk.sh
|
|
|
|
echo " done" >> /etc/runit/core-services/99-changepwdisk.sh
|
|
|
|
echo " rm -rf /etc/runit/core-services/99-changepwdisk.sh" >> /etc/runit/core-services/99-changepwdisk.sh
|
|
|
|
echo "fi" >> /etc/runit/core-services/99-changepwdisk.sh
|
2021-03-13 11:38:34 +01:00
|
|
|
|
2021-03-16 23:06:15 +01:00
|
|
|
echo "read -p \"Change PW for ${users[name1]}? y/n \" answer" > /etc/runit/core-services/99-changepwuser.sh
|
|
|
|
echo "if [ \"\${answer}\" = \"y\" ]; then" >> /etc/runit/core-services/99-changepwuser.sh
|
|
|
|
echo " while ! passwd ${users[name1]}; do" >> /etc/runit/core-services/99-changepwuser.sh
|
|
|
|
echo " echo \"Again, please\"" >> /etc/runit/core-services/99-changepwuser.sh
|
|
|
|
echo " done" >> /etc/runit/core-services/99-changepwuser.sh
|
|
|
|
echo " rm -rf /etc/runit/core-services/99-changepwuser.sh" >> /etc/runit/core-services/99-changepwuser.sh
|
|
|
|
echo "fi" >> /etc/runit/core-services/99-changepwuser.sh
|
2021-03-13 11:38:34 +01:00
|
|
|
fi
|
|
|
|
|
2021-04-14 20:23:06 +02:00
|
|
|
{ echo "transaction_syslog daemon";
|
2021-04-12 17:25:50 +02:00
|
|
|
echo "lockfile /tmp/btrbk.lock";
|
|
|
|
echo "incremental yes";
|
|
|
|
echo "btrfs_commit_delete after";
|
|
|
|
echo "timestamp_format long";
|
2021-04-14 14:10:53 +02:00
|
|
|
echo "noauto yes";
|
|
|
|
echo "backend btrfs-progs-sudo";
|
|
|
|
echo "";
|
|
|
|
echo "volume /var/lib/backup/quelle/rootfs";
|
|
|
|
echo " group snapshotrootfs";
|
2021-04-12 17:25:50 +02:00
|
|
|
echo " snapshot_dir snapshot";
|
|
|
|
echo " snapshot_preserve_min 4h";
|
|
|
|
echo " snapshot_preserve no ";
|
2021-04-14 14:10:53 +02:00
|
|
|
echo " subvolume rootfs";
|
|
|
|
echo " subvolume homefs";
|
|
|
|
echo "";
|
|
|
|
echo "volume /var/lib/backup/quelle/rootfs";
|
|
|
|
echo " group backuprootfs";
|
|
|
|
echo " snapshot_dir backup";
|
|
|
|
echo " snapshot_preserve_min 4h";
|
|
|
|
echo " snapshot_preserve no";
|
|
|
|
echo " target_preserve_min latest";
|
|
|
|
echo " target_preserve no";
|
|
|
|
echo " subvolume rootfs";
|
|
|
|
echo " target send-receive /var/lib/backup/ziel/void/rootfs";
|
|
|
|
echo " subvolume homefs";
|
|
|
|
echo " target send-receive /var/lib/backup/ziel/void/homefs";
|
2021-04-14 20:23:06 +02:00
|
|
|
echo ""; } > /etc/btrbk/btrbk.conf
|
2021-04-12 16:27:29 +02:00
|
|
|
if [[ ! ${cfg[fde_key_store]} == "once" ]]; then
|
2021-04-14 20:23:06 +02:00
|
|
|
{ echo "volume /var/lib/backup/quelle/bootfs";
|
2021-04-14 14:10:53 +02:00
|
|
|
echo " group snapshotboot";
|
|
|
|
echo " snapshot_dir snapshot";
|
|
|
|
echo " snapshot_preserve_min 4h";
|
|
|
|
echo " snapshot_preserve no";
|
|
|
|
echo " subvolume bootfs";
|
|
|
|
echo "";
|
|
|
|
echo "volume /var/lib/backup/quelle/bootfs";
|
|
|
|
echo " group backupboot";
|
|
|
|
echo " snapshot_dir backup";
|
|
|
|
echo " snapshot_preserve_min 4h";
|
|
|
|
echo " snapshot_preserve no";
|
|
|
|
echo " target_preserve_min latest";
|
|
|
|
echo " target_preserve 20d 10w 2m";
|
|
|
|
echo " subvolume bootfs";
|
|
|
|
echo " target send-receive /var/lib/backup/ziel/void/bootfs";
|
2021-04-14 20:23:06 +02:00
|
|
|
echo ""; } >> /etc/btrbk/btrbk.conf
|
2021-04-14 14:10:53 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<'EOF' > /usr/bin/joinvpn
|
|
|
|
#!/bin/bash
|
|
|
|
basewgfolder="/etc/wireguard"
|
|
|
|
|
|
|
|
if [ $UID -ne 0 ]; then
|
|
|
|
echo "Keine Rootrechte"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
umask 0077
|
|
|
|
mkdir -p "${basewgfolder}/wg0"
|
|
|
|
cd "${basewgfolder}/wg0"
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -f "${basewgfolder}/wg0/privkey" ]]; then
|
|
|
|
read -p "Address: " ADDRESS
|
|
|
|
read -p "PublicKey: " PUBKEY_SERVER
|
|
|
|
read -p "Endpoint: " ENDPOINT
|
|
|
|
read -p "Port: " PORT
|
|
|
|
{ echo "[Interface]";
|
|
|
|
echo "Address = ${ADDRESS}";
|
|
|
|
echo "PostUp = wg set %i private-key /etc/wireguard/wg0/wg0.key <(cat /etc/wireguard/wg0/privkey)";
|
|
|
|
echo "[Peer]";
|
|
|
|
echo "PublicKey = ${PUBKEY_SERVER}";
|
|
|
|
echo "Endpoint = ${ENDPOINT}:${PORT}";
|
|
|
|
echo "AllowedIPs = fd23::23:0:0/96";
|
|
|
|
echo "PresharedKey = $(cat psk)";
|
|
|
|
echo "PersistentKeepalive = 25"; } > "${basewgfolder}/wg0.conf"
|
|
|
|
else
|
|
|
|
test -f privkey || wg genkey > privkey
|
|
|
|
test -f pubkey || wg pubkey < privkey > pubkey
|
|
|
|
test -f psk || wg genpsk > psk
|
|
|
|
echo "Frage O nach den den folgenden Daten und wenn du sie hast, starte das hier nochmal"
|
|
|
|
echo "Address"
|
|
|
|
echo "PublicKey"
|
|
|
|
echo "Endpoint"
|
|
|
|
echo "Port"
|
|
|
|
echo ""
|
|
|
|
echo "Schicke ihm verschlüsselt (Jabber oder Email) folgende Daten:"
|
|
|
|
echo "PublicKey = $(cat pubkey)"
|
|
|
|
echo "PresharedKey = $(cat psk)"
|
|
|
|
echo "Hostname = ${HOSTNAME}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<'EOF' > /usr/bin/void-backup
|
|
|
|
#!/bin/bash
|
|
|
|
export LANG="en_US.UTF-8"
|
|
|
|
backupcfg="/etc/backup.cfg"
|
|
|
|
ziel="/var/lib/backup/ziel"
|
|
|
|
cfg="/etc/btrbk/btrbk.conf.system"
|
|
|
|
|
|
|
|
if [ $UID -ne 0 ]; then
|
|
|
|
echo "Keine Rootrechte."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -f "${backupcfg}" ]] && [[ ! -f /etc/btrbk/btrbk.conf ]]; then
|
|
|
|
echo "Eine USB-Festplatte einrichten?"
|
|
|
|
while read -p "[Y/n] " answer; do
|
|
|
|
test -z "${answer}" && answer="y"
|
|
|
|
case "${answer}" in
|
|
|
|
n*|N*)
|
|
|
|
echo "Entweder eine Konfigurationsdatei anlegen. (${backupcfg})"
|
|
|
|
echo "(Diese Datei wird normalerweise durch \`void-createbackupcontainer\` erstellt)"
|
|
|
|
echo "UUID=\"uuid\""
|
|
|
|
echo "Oder eine Backupfestplatte einrichten. \`void-createbackupcontainer\`"
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
y*|Y*|j*|J*)
|
|
|
|
echo "Schliesse nun eine leere oder zu leerende USB-Festplatte an und starte dieses Programm nochmal, wenn es beendet ist"
|
|
|
|
exec /usr/bin/void-createbackupcontainer
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
elif [[ -f "${backupcfg}" ]] && [[ ! -f /etc/btrbk/btrbk.conf ]]; then
|
|
|
|
source "${backupcfg}"
|
|
|
|
elif [[ -f /etc/btrbk/btrbk.conf ]]; then
|
|
|
|
cfg="/etc/btrbk/btrbk.conf"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${UUID}" ]; then
|
|
|
|
echo "Keine Backupplatte angegeben."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
fhelp() {
|
|
|
|
echo "Nutze es so:"
|
|
|
|
echo "sudo backup"
|
|
|
|
echo "sudo backup poweroff (um den Rechner nach dem Backup herunterzufahren.)"
|
|
|
|
#echo "sudo backup update (um den Rechner nach dem Backup up zu daten.)"
|
|
|
|
#echo "update und poweroff sind mixbar"
|
|
|
|
echo "sudo backup passwd (um das Passwort für die Backupfestplatte zu ändern.)"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ ! -e "/dev/disk/by-uuid/${UUID}" ]; then
|
|
|
|
echo "Bitte Backupfestplatte anschliessen."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for argval in "$@"
|
|
|
|
do
|
|
|
|
case "${argval}" in
|
|
|
|
power|poweroff|p)
|
|
|
|
poweroff=y
|
|
|
|
;;
|
|
|
|
help|-h|--help|h)
|
|
|
|
fhelp
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
update)
|
|
|
|
update=y
|
|
|
|
;;
|
|
|
|
passwd)
|
|
|
|
passwd=y
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -e /tmp/backup ]; then
|
|
|
|
echo "Es läuft schon ein Backupvorgang oder wurde nicht richtig beendet."
|
|
|
|
echo "Bei letzterem: 'sudo rm -rf /tmp/backup'"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
touch /tmp/backup
|
|
|
|
|
|
|
|
if [[ "${passwd}" == "y" ]]; then
|
|
|
|
cryptsetup luksChangeKey "/dev/disk/by-uuid/${UUID}"
|
|
|
|
rm -rf /tmp/backup
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
function finish {
|
|
|
|
sync
|
|
|
|
if [ "${poweroff}" = "y" ]; then
|
|
|
|
shutdown -h now
|
|
|
|
fi
|
|
|
|
sleep 4
|
|
|
|
umount "${ziel}"
|
|
|
|
echo " "
|
|
|
|
echo " "
|
|
|
|
if [[ "${MOUNTEDBY}" == "script" ]]; then
|
|
|
|
cryptsetup close "luks-${UUID}"
|
|
|
|
echo "Festplatte kann nun sicher entfernt werden."
|
|
|
|
elif [[ "${MOUNTEDBY}" == "gnome" ]]; then
|
|
|
|
echo "Festplatte bitte mit der grafischen Oberflaeche auswerfen (wie ein USB-Stick)"
|
|
|
|
echo ""
|
|
|
|
echo "oder:"
|
|
|
|
echo "sudo umount /dev/mapper/luks-${UUID}"
|
|
|
|
echo "sudo cryptsetup close luks-${UUID}"
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
rm -rf /tmp/backup
|
|
|
|
echo "FERTIG"
|
|
|
|
|
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
if [ ! $(mountpoint -q -x "/dev/mapper/luks-${UUID}") ]; then
|
|
|
|
if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then
|
|
|
|
echo "Konnte /dev/disk/by-uuid/${UUID} nicht öffnen."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
MOUNTEDBY="script"
|
|
|
|
else
|
|
|
|
MOUNTEDBY="gnome"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! mount "/dev/mapper/luks-${UUID}" "${ziel}"; then
|
|
|
|
echo "Konnte /dev/mapper/luks-${UUID} in ${ziel} nicht mounten."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if mountpoint -q /var/lib/backup/quelle/boot; then
|
|
|
|
mkdir -p "/var/lib/backup/ziel/void/boot"
|
|
|
|
if ! btrbk --config="${cfg}" --progress --quiet run backupboot; then
|
|
|
|
btrbk --config="${cfg}" --progress --quiet clean
|
|
|
|
echo "Wegen Fehler nicht herunterfahren."
|
|
|
|
poweroff=n
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p "/var/lib/backup/ziel/void/{rootfs,home}"
|
|
|
|
if ! btrbk --config="${cfg}" --progress --quiet run backuprootfs; then
|
|
|
|
btrbk --config="${cfg}" --progress --quiet clean
|
|
|
|
echo "Wegen Fehler nicht herunterfahren."
|
|
|
|
poweroff=n
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#if [[ "${update}" = "y" ]]; then
|
|
|
|
# if command -v voidupdate >/dev/null; then
|
|
|
|
# if ! voidupdate; then
|
|
|
|
# echo "UPDATE FAILED, nicht runterfahren"
|
|
|
|
# poweroff=n
|
|
|
|
# fi
|
|
|
|
# else
|
|
|
|
# if ! apt-get -y -q upgrade; then
|
|
|
|
# echo "UPDATE FAILED, nicht runterfahren"
|
|
|
|
# poweroff=n
|
|
|
|
# fi
|
|
|
|
# fi
|
|
|
|
#fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<'EOF' > /usr/bin/void-createbackupcontainer
|
2021-04-07 17:52:24 +02:00
|
|
|
#!/bin/bash
|
2021-04-14 14:10:53 +02:00
|
|
|
backupcfg="/etc/backup.cfg"
|
|
|
|
|
|
|
|
if [ $UID -ne 0 ]; then
|
|
|
|
echo "Keine Rootrechte."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
#test -f "${backupcfg}" && echo "${backupcfg} existiert" && exit 1
|
|
|
|
|
|
|
|
# find all disks
|
|
|
|
declare -A disk_tmp=()
|
|
|
|
declare -A disk=()
|
|
|
|
index=0
|
|
|
|
for i in $(find /dev/disk/by-id/ -type l -printf "%P\n" | grep usb | grep -v part | tac ); do
|
|
|
|
name="$(readlink -f /dev/disk/by-id/"${i}")"
|
|
|
|
if [[ "${name}" =~ *"^[0-9]+$"* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [[ "${name}" == *"dm"* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [[ "${name}" == *"/dev/sr"* ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if blkid "${name}"|grep -q UUID; then
|
|
|
|
size="$(fdisk -l "${name}" | head -n1 | awk '{print $3}')"
|
|
|
|
else
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
size=$(awk "BEGIN { printf(\"%.0f\n\", ${size}); }")
|
|
|
|
uuid=$(blkid -o value -s UUID ${name})
|
|
|
|
index=$(( index + 1 ))
|
|
|
|
disk_tmp+=( [${index}.id]="${i}" [${index}.name]="${name}" [${index}.uuid]="${uuid}" [${index}.size]="${size}" )
|
|
|
|
done
|
|
|
|
disk_tmp+=( [count]="${index}" )
|
|
|
|
|
|
|
|
if [[ "${disk_tmp[count]}" -eq 0 ]]; then
|
|
|
|
echo "No Disk attached."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# show devices
|
|
|
|
echo "Devices:"
|
|
|
|
for i in $(seq 1 "${disk_tmp[count]}"); do
|
|
|
|
echo "${disk_tmp[${i}.id]}"
|
|
|
|
echo " - uuid: ${disk_tmp[${i}.uuid]}"
|
|
|
|
echo " - name: ${disk_tmp[${i}.name]}"
|
|
|
|
echo " - size: ${disk_tmp[${i}.size]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
# choose device
|
|
|
|
found=
|
|
|
|
while read -p "Which Device? [${disk_tmp[1.uuid]}]: " output; do
|
|
|
|
test -z "${output}" && output="${disk_tmp[1.uuid]}"
|
|
|
|
for i in $(seq 1 "${disk_tmp[count]}"); do
|
|
|
|
if [[ "${disk_tmp[${i}.id]}" == "${output}" ]] || [[ "${disk_tmp[${i}.name]}" == "${output}" ]] || [[ "${disk_tmp[${i}.uuid]}" == "${output}" ]]; then
|
|
|
|
found=1
|
|
|
|
id="${disk_tmp[${i}.id]}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
[[ "${found}" ]] && break
|
|
|
|
echo "${output} not found"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "g
|
|
|
|
n
|
|
|
|
1
|
|
|
|
|
|
|
|
|
|
|
|
w
|
|
|
|
q" | fdisk "/dev/disk/by-id/${id}"
|
|
|
|
|
|
|
|
UUID=$(blkid -o value -s UUID "/dev/disk/by-id/${id}-part1")
|
|
|
|
|
|
|
|
if ! cryptsetup luksFormat UUID="${UUID}"; then
|
|
|
|
echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
if ! cryptsetup open UUID="${UUID}" "luks-${UUID}"; then
|
|
|
|
echo "Konnte /dev/disk/by-uuid/${UUID} nicht verschluesseln."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! mkfs.btrfs -f "/dev/mapper/luks-${UUID}"; then
|
|
|
|
echo "Konnte /dev/mapper/luks-${UUID} nicht formatieren"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! mount "/dev/mapper/luks-${UUID}" "/var/lib/backup/ziel"; then
|
|
|
|
echo "Konnte /dev/mapper/luks-${UUID} nicht nach /var/lib/backup/ziel mounten"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if mountpoint -q /boot; then
|
|
|
|
mkdir -p "/var/lib/backup/ziel/${HOSTNAME}/boot"
|
|
|
|
fi
|
|
|
|
mkdir -p "/var/lib/backup/ziel/${HOSTNAME}/{rootfs,home}"
|
|
|
|
|
|
|
|
umount "/var/lib/backup/ziel"
|
|
|
|
cryptsetup close "luks-${UUID}"
|
|
|
|
|
|
|
|
echo "UUID=\"${UUID}\"" > "${backupcfg}"
|
|
|
|
|
|
|
|
echo "Erstellen des Containers fertig."
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<'EOF' > /usr/bin/void-snapshot
|
|
|
|
#!/bin/sh
|
|
|
|
if [ -f /etc/btrbk/btrbk.conf ]; then
|
|
|
|
cfg="/etc/btrbk/btrbk.conf"
|
|
|
|
else
|
|
|
|
cfg="/etc/btrbk/btrbk.conf.system"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if mountpoint -q /var/lib/backup/quelle/boot; then
|
|
|
|
btrbk --config="${cfg}" --quiet run snapshotboot
|
|
|
|
fi
|
|
|
|
|
|
|
|
btrbk --config="${cfg}" --quiet run snapshotrootfs
|
|
|
|
|
|
|
|
if ! update-grub 2> /dev/null; then
|
|
|
|
echo update-grub failed
|
|
|
|
fi
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat <<'EOF' > /usr/bin/void-update
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ $UID -ne 0 ]; then
|
|
|
|
echo "Keine Rootrechte."
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-04-07 17:52:24 +02:00
|
|
|
|
|
|
|
RESTART=
|
|
|
|
echo "Synchronisiere Repositorys"
|
|
|
|
xbps-install -S > /dev/null
|
|
|
|
|
|
|
|
mapfile -t updatedpkgs < <(xbps-install -un|awk '{print $1}')
|
|
|
|
if [[ "${#updatedpkgs[@]}" -eq 0 ]]; then
|
|
|
|
echo "Keine Updates"
|
|
|
|
exit
|
2021-04-14 14:10:53 +02:00
|
|
|
else
|
|
|
|
echo "Es sind Updates da!"
|
|
|
|
while read -p "Installieren? [Y/n] " answer; do
|
|
|
|
test -z "${answer}" && answer="y"
|
|
|
|
case "${answer}" in
|
|
|
|
n*|N*|*o|*O)
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
y*|Y*|j*|J*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2021-04-07 17:52:24 +02:00
|
|
|
fi
|
|
|
|
|
2021-04-14 14:10:53 +02:00
|
|
|
echo "Lege Snapshot an"
|
|
|
|
void-snapshot
|
|
|
|
|
2021-04-07 17:52:24 +02:00
|
|
|
echo "Entferne nicht benutzte Pakete"
|
|
|
|
xbps-remove -oy > /dev/null
|
2021-04-14 14:10:53 +02:00
|
|
|
|
2021-04-07 17:52:24 +02:00
|
|
|
echo "Räume den Cache auf"
|
|
|
|
xbps-remove -Oy > /dev/null
|
|
|
|
|
2021-04-14 14:10:53 +02:00
|
|
|
echo "Installiere Updates"
|
|
|
|
if ! xbps-install -uy; then
|
|
|
|
echo "Update failed."
|
|
|
|
exit
|
|
|
|
fi
|
2021-04-07 17:52:24 +02:00
|
|
|
|
|
|
|
if [[ "$(xcheckrestart)" ]]; then
|
|
|
|
RESTART=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for i in "${updatedpkgs[@]}"; do
|
2021-04-14 14:10:53 +02:00
|
|
|
if grep -q "^linux" <<< "${i}"; then
|
2021-04-07 17:52:24 +02:00
|
|
|
vkpurge list | head -n -1 | xargs -r vkpurge rm
|
|
|
|
RESTART=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ "${RESTART}" ]]; then
|
|
|
|
echo ""; echo "Bitte den Computer neu starten."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Update fertig."
|
2021-04-14 14:10:53 +02:00
|
|
|
|
2021-04-07 17:52:24 +02:00
|
|
|
EOF
|
2021-04-14 14:10:53 +02:00
|
|
|
|
|
|
|
|
2021-04-07 17:52:24 +02:00
|
|
|
|
2021-03-12 16:28:20 +01:00
|
|
|
module end
|