mirror of
https://github.com/gaschz/dotfiles.git
synced 2025-03-01 14:22:33 +01:00

Echo can interpret operand as an option and checking every variable to be echoed is troublesome while with printf, if the format specifier is present before the operand, printing as string can be enforced.
46 lines
1.5 KiB
Bash
Executable File
46 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
##
|
|
## SPDX-FileCopyrightText: 2023 - 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
##
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
##
|
|
## Benefits of this method:
|
|
## - faster than salt, no need for a dispvm.
|
|
## - preserve permissions, salt-ssh doesn't.
|
|
## Disadvantages:
|
|
## - files need be copied to dom0 preserving permissions or setting again.
|
|
##
|
|
## Commands to run:
|
|
## sudo ./qvm-copy-dotfiles QUBE
|
|
set -eu
|
|
|
|
test -n "${1:-}" || { printf '%s\n' "usage: ${0##*/} QUBE"; exit 1; }
|
|
uid="$(id -u)"
|
|
test "${uid}" = "0" || { printf '%s\n' "Program requires root."; exit 1; }
|
|
|
|
qube="${1-}"
|
|
if ! qvm-check -- "${qube}" >/dev/null 2>&1; then
|
|
printf '%s\n' "VM doesn't exist: '${qube}'"
|
|
exit 1
|
|
fi
|
|
test -f ./setup.sh ||
|
|
{ printf '%s\n' "File doesn't exist: './setup.sh'"; exit 1; }
|
|
|
|
if test "${qube}" = "dom0"; then
|
|
sh ./dotfiles/setup.sh
|
|
user_name="$(getent group qubes | awk -F "[:,]" '{print $4}')"
|
|
user_home="$(getent passwd "${user_name}" | awk -F ":" '{print $6}')"
|
|
sudo -u "${user_name}" mkdir -pv -- "${user_home}/.cache"
|
|
tmpdir="$(sudo -u "${user_name}" -- mktemp -d "${user_home}/.cache/XXXXXX")"
|
|
trap 'rm -rf -- "${tmpdir}"' EXIT INT HUP QUIT ABRT
|
|
cp -r -- ./dotfiles "${tmpdir}"
|
|
chown -R -- "${user_name}:${user_name}" "${tmpdir}"
|
|
sudo -u "${user_name}" -- "${tmpdir}/dotfiles/setup.sh"
|
|
exit
|
|
fi
|
|
|
|
qvm-run -q "${qube}" -- "rm -rf -- ~/QubesIncoming/dom0/files"
|
|
qvm-copy-to-vm "${qube}" ../files
|
|
qvm-run -q "${qube}" -- "sh ~/QubesIncoming/dom0/files/setup.sh"
|
|
qvm-run -q "${qube}" -- "rm -rf -- ~/QubesIncoming/dom0/files"
|