Aktualisisert von Coderberg
This commit is contained in:
parent
8caa3cf881
commit
0ccf139311
41 changed files with 649 additions and 186 deletions
|
|
@ -3,6 +3,11 @@
|
|||
%role-student ALL=(lmnsynci) NOPASSWD: /usr/local/bin/vm-sync
|
||||
%examusers ALL=(lmnsynci) NOPASSWD: /usr/local/bin/vm-sync
|
||||
|
||||
# vm-delete: Delete VM-Images
|
||||
%role-teacher ALL=(lmnsynci) NOPASSWD: /usr/local/bin/vm-delete
|
||||
%role-student ALL=(lmnsynci) NOPASSWD: /usr/local/bin/vm-delete
|
||||
%examusers ALL=(lmnsynci) NOPASSWD: /usr/local/bin/vm-delete
|
||||
|
||||
# vm-aria2: Start/Stop aria2 as systemd-service for VM-Images
|
||||
lmnsynci ALL=(root) NOPASSWD: /usr/local/bin/vm-aria2
|
||||
|
||||
|
|
@ -11,11 +16,6 @@ lmnsynci ALL=(root) NOPASSWD: /usr/local/bin/vm-aria2
|
|||
%role-student ALL=(root) NOPASSWD: /usr/local/bin/vm-link-images
|
||||
%role-teacher ALL=(root) NOPASSWD: /usr/local/bin/vm-link-images
|
||||
|
||||
# vm-virtiofsd: Start Virtiofsd as systemd-service
|
||||
%examusers ALL=(root) NOPASSWD: /usr/local/bin/vm-virtiofsd
|
||||
%role-student ALL=(root) NOPASSWD: /usr/local/bin/vm-virtiofsd
|
||||
%role-teacher ALL=(root) NOPASSWD: /usr/local/bin/vm-virtiofsd
|
||||
|
||||
# desktop-sync:
|
||||
%examusers ALL=(root) NOPASSWD: /usr/local/bin/desktop-sync
|
||||
%role-student ALL=(root) NOPASSWD: /usr/local/bin/desktop-sync
|
||||
|
|
|
|||
Binary file not shown.
45
roles/lmn_vm/files/vm-delete
Executable file
45
roles/lmn_vm/files/vm-delete
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
directory="/lmn/vm"
|
||||
|
||||
if [ ! -d "$directory" ]; then
|
||||
echo "No VM directory found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
qcow2_files=("$directory"/*.qcow2)
|
||||
|
||||
if [ "${#qcow2_files[@]}" -eq 0 ]; then
|
||||
echo "Keine QCOW2-Dateien gefunden."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Gefundene QCOW2-Dateien:"
|
||||
echo "-------------------------------------------------------------"
|
||||
printf "%-50s %10s\n" "Datei" "Größe (MB)"
|
||||
echo "-------------------------------------------------------------"
|
||||
|
||||
for file in "${qcow2_files[@]}"; do
|
||||
size=$(du -m "$file" | cut -f1) # Größe in MB
|
||||
printf "%-50s %10d\n" "$file" "$size"
|
||||
done
|
||||
|
||||
echo "-------------------------------------------------------------"
|
||||
|
||||
for file in "${qcow2_files[@]}"; do
|
||||
read -rp "Möchtest du die Datei $file löschen? (j/n) " confirmation
|
||||
if [[ "$confirmation" == "j" || "$confirmation" == "J" ]]; then
|
||||
link_count=$(stat -c %h "$file")
|
||||
rm "$file"
|
||||
echo "$file wurde gelöscht."
|
||||
if [ "$link_count" -gt 1 ]; then
|
||||
echo "Achtung: $file hat noch $((link_count - 1)) weitere Hardlinks."
|
||||
echo "Diese liegen evtl. unter:"
|
||||
echo "- /var/tmp/${UID}/vm/ (temporäre VMs, werden automatisch beim Neustart gelöscht)"
|
||||
echo "- /var/vm/${UID}/ (persistente VMs)"
|
||||
fi
|
||||
echo
|
||||
fi
|
||||
done
|
||||
|
|
@ -19,8 +19,9 @@ done
|
|||
shift "$((OPTIND -1))"
|
||||
|
||||
# link system-VM-Images to User VM Directory
|
||||
for i in *.qcow2; do
|
||||
[[ -f "${VM_DIR}/${i}" ]] || ln "${i}" "${VM_DIR}/${i}"
|
||||
for filename in "$@"; do
|
||||
filename="$(basename ${filename})"
|
||||
[[ -f "${VM_DIR}/${filename}" ]] || ln "${filename}" "${VM_DIR}/${filename}"
|
||||
done
|
||||
|
||||
# allow lmnsynci to remove old vm images
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ set -eu
|
|||
## Imporant for all virsh libvirt calls:
|
||||
export XDG_CONFIG_HOME="/var/tmp/vm/${UID}"
|
||||
|
||||
menu=(standard "CLI Standard Debian GNU/Linux NFS"
|
||||
standard-ram "CLI Standard Debian GNU/Linux RAM"
|
||||
kde-desktop "KDE Plasma Desktop Debian GNU/Linux NFS"
|
||||
gnome-desktop "Gnome Desktop Debian GNU/Linux NFS")
|
||||
menu=(standard-edu "CLI Standard Debian GNU/Linux NFS"
|
||||
standard-edu-ram "CLI Standard Debian GNU/Linux RAM"
|
||||
kde-edu "KDE Plasma Desktop Debian GNU/Linux NFS"
|
||||
gnome-edu "Gnome Desktop Debian GNU/Linux NFS")
|
||||
img=$(dialog --clear --backtitle "Virtual Machine Chooser" \
|
||||
--title "Choose the Virtual Machine to Start" \
|
||||
--menu "Start VM:" 12 70 6 "${menu[@]}" 2>&1 >/dev/tty)
|
||||
|
|
@ -22,6 +22,8 @@ mac="$(ip link | grep -A1 -m1 "macvtap-" | \
|
|||
sed -nE "s%\s+link/ether ([[:xdigit:]:]{17}) .+%\1%p")"
|
||||
tapdev="$(ip link | grep -A1 -m1 "macvtap-" | sed -nE "s%^[1-9]:\s(\S+)@.*%\1%p")"
|
||||
|
||||
livebox=$(host livebox | sed -E "s/.+ ([0-9.]+)$/\1/")
|
||||
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
mem=$(sed -En "s/^MemAvailable:\s+([0-9]+)\s+kB/\1/p" /proc/meminfo)
|
||||
cpu=$(sed -En "0,/^cpu cores/s/^cpu cores\s+:\s+([0-9]+)/\1/p" /proc/cpuinfo)
|
||||
|
|
@ -31,8 +33,8 @@ else
|
|||
arg=("$@")
|
||||
fi
|
||||
|
||||
kernel="http://livebox/d-i/n-live/${img%-ram}/live/vmlinuz"
|
||||
initrd="http://livebox/d-i/n-live/${img%-ram}/live/initrd.img"
|
||||
kernel="http://${livebox}/d-i/n-live/${img%-ram}/live/vmlinuz"
|
||||
initrd="http://${livebox}/d-i/n-live/${img%-ram}/live/initrd.img"
|
||||
kargs=(boot=live components splash locales=de_DE.UTF-8 keyboard-layouts=de
|
||||
swap=true live-config.timezone=Europe/Berlin)
|
||||
|
||||
|
|
@ -42,10 +44,10 @@ case "$img" in
|
|||
kargs+=(console=ttyS0)
|
||||
;;&
|
||||
*-ram)
|
||||
kargs+=("fetch=http://10.190.1.2/d-i/n-live/${img%-ram}/live/filesystem.squashfs")
|
||||
kargs+=("root=live:nfs4:${livebox}:/images/${img%-ram}/live/filesystem.squashfs rd.live.ram=1")
|
||||
;;
|
||||
*)
|
||||
kargs+=(netboot=nfs "nfsroot=10.190.1.2:/srv/nfs/debian-live/${img%-ram}")
|
||||
kargs+=("root=live:nfs4:${livebox}:/images/${img%-ram}/live/filesystem.squashfs")
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
|||
|
|
@ -90,17 +90,21 @@ create_clone() {
|
|||
local VM_NAME="$1"
|
||||
|
||||
if ! [[ -f "${VM_SYSDIR}/${VM_NAME}.qcow2" || -f "${VM_DIR}/${VM_NAME}.qcow2" ]]; then
|
||||
echo "qcow2 File does not exists." >&2
|
||||
exit 1
|
||||
echo "qcow2 File does not exists." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create User-VM-Dir and link system VM-Images
|
||||
[[ -d "${VM_DIR}" ]] || mkdir -p "${VM_DIR}"
|
||||
if [[ "${PERSISTENT}" -eq 1 ]]; then
|
||||
sudo /usr/local/bin/vm-link-images -p
|
||||
else
|
||||
sudo /usr/local/bin/vm-link-images
|
||||
fi
|
||||
IMAGE="${VM_NAME}.qcow2"
|
||||
while [[ -n ${IMAGE} ]]; do
|
||||
if [[ "${PERSISTENT}" -eq 1 ]]; then
|
||||
sudo /usr/local/bin/vm-link-images -p "${IMAGE}"
|
||||
else
|
||||
sudo /usr/local/bin/vm-link-images "${IMAGE}"
|
||||
fi
|
||||
IMAGE="$(qemu-img info -U "${VM_DIR}/${IMAGE}" | grep "^backing file:" | cut -d ' ' -f 3)"
|
||||
done
|
||||
|
||||
# Create backing file
|
||||
cd "${VM_DIR}"
|
||||
|
|
@ -121,8 +125,6 @@ create_clone() {
|
|||
|
||||
create_printerlist() {
|
||||
## Prepare .printerlist.csv
|
||||
mkdir -p "${VM_MEDIADIR}"
|
||||
chgrp "$(id -g)" "${VM_MEDIADIR}"
|
||||
echo "Name;IppURL" > "${VM_MEDIADIR}/.printerlist.csv"
|
||||
for p in $(lpstat -v | cut -f 3 -d" " | sed 's/:$//'); do
|
||||
echo "$p;ipp://192.168.122.1/printers/$p" >> "${VM_MEDIADIR}/.printerlist.csv"
|
||||
|
|
@ -130,18 +132,30 @@ create_printerlist() {
|
|||
}
|
||||
|
||||
create_mountlist() {
|
||||
if id | grep -q teachers; then
|
||||
NETHOME=/srv/samba/schools/default-school/teachers/$USER
|
||||
else
|
||||
NETHOME=(/srv/samba/schools/default-school/students/*/"$USER")
|
||||
fi
|
||||
NETHOME="${NETHOME#/srv/samba/schools}"
|
||||
cat << EOF > "/lmn/media/${USER}/.mounts.csv"
|
||||
NETHOMEPART="${NETHOME#/srv/samba/schools}"
|
||||
cat << EOF > "${VMINFO_DIR}/.mounts.csv"
|
||||
Drive;Remotepath
|
||||
H;\\\\10.190.1.1${NETHOME//\//\\}
|
||||
T;\\\\10.190.1.1\default-school\share
|
||||
H;\\\\server.pn.steinbeis.schule${NETHOMEPART//\//\\}
|
||||
T;\\\\server.pn.steinbeis.schule\\default-school\\share
|
||||
EOF
|
||||
echo "${USER}" > "/lmn/media/${USER}/.user"
|
||||
echo "${USER}" > "/${VMINFO_DIR}/.user"
|
||||
}
|
||||
|
||||
start_virtiofs_service() {
|
||||
local target_name=$1
|
||||
local shared_dir=$2
|
||||
local drive_letter=$3
|
||||
local socket="/run/user/${UID}/virtiofs-${VM_NAME}-${target_name,,}.sock"
|
||||
|
||||
systemd-run --user /usr/lib/qemu/virtiofsd --uid-map=":${GUEST_UID}:${UID}:1:" --gid-map=":${GUEST_GID}:$(id -g):1:" \
|
||||
--socket-path "${socket}" --shared-dir "${shared_dir}" --syslog
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Error starting virtiofsd for ${target_name}." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
LIBVIRTOPTS="${LIBVIRTOPTS} --filesystem driver.type=virtiofs,accessmode=passthrough,target.dir=${target_name},xpath1.set=./source/@socket=${socket}"
|
||||
}
|
||||
|
||||
start_virtiofsd() {
|
||||
|
|
@ -151,9 +165,17 @@ start_virtiofsd() {
|
|||
[[ "$GUEST_GID" == 0 ]] && GUEST_GID=1010
|
||||
fi
|
||||
# END temporary fix
|
||||
socket="/run/user/$(id -u $USER)/virtiofs-${VM_NAME}.sock"
|
||||
systemd-run --user /usr/local/bin/virtiofsd --uid-map=:${GUEST_UID}:${UID}:1: --gid-map=:${GUEST_GID}:$(id -g):1: \
|
||||
--socket-path "$socket" --shared-dir "/lmn/media/${USER}" --syslog
|
||||
|
||||
# start_virtiofs_service "VM-Data" "/lmn/media/${USER}" "Y"
|
||||
# start_virtiofs_service "default-school" "/srv/samba/schools/default-school" "Y"
|
||||
|
||||
# Home@PC / VM-Data
|
||||
# if the environment variable VMLEGACY is set, /lmn/media/USER is forced
|
||||
if [[ "${HOME}" != "${NETHOME}" && ! -v VMLEGACY ]]; then
|
||||
start_virtiofs_service "Home_Linux" "${HOME}" "Y"
|
||||
else
|
||||
start_virtiofs_service "VM-Data" "/lmn/media/${USER}" "Y"
|
||||
fi
|
||||
}
|
||||
|
||||
ask_really_persistent() {
|
||||
|
|
@ -184,6 +206,7 @@ EOF
|
|||
|
||||
QEMU='qemu:///session'
|
||||
|
||||
|
||||
NEWCLONE=0
|
||||
PERSISTENT=0
|
||||
LIBVIRTOSINFO="win10"
|
||||
|
|
@ -316,18 +339,40 @@ if ! virsh --connect="${QEMU}" list | grep "${VM_NAME}-clone"; then
|
|||
check_images
|
||||
fi
|
||||
if [[ "${NEWCLONE}" = 1 ]] || [[ ! -f "${VM_DIR}/${VM_NAME}-clone.qcow2" ]]; then
|
||||
create_clone "${VM_NAME}"
|
||||
create_clone "${VM_NAME}"
|
||||
fi
|
||||
# delete the old vm
|
||||
virsh --connect=qemu:///session undefine --nvram "${VM_NAME}-clone" || echo "${VM_NAME}-clone did not exist"
|
||||
#trap exit_script SIGHUP SIGINT SIGTERM
|
||||
|
||||
for dir in teachers examusers staff parents; do
|
||||
if [[ -d "/srv/samba/schools/default-school/${dir}/${USER}" ]]; then
|
||||
NETHOME="/srv/samba/schools/default-school/${dir}/${USER}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -z "${NETHOME+x}" ]]; then
|
||||
NETHOME=(/srv/samba/schools/default-school/students/*/"$USER")
|
||||
fi
|
||||
|
||||
if [[ "${HOME}" != "${NETHOME}" ]]; then
|
||||
VMINFO_DIR="${HOME}"
|
||||
else
|
||||
VMINFO_DIR="/lmn/media/${USER}"
|
||||
fi
|
||||
mkdir -p "${VM_MEDIADIR}" -m 700
|
||||
chgrp "$(id -g)" "${VM_MEDIADIR}"
|
||||
create_printerlist
|
||||
create_mountlist
|
||||
|
||||
# start virtiofsd-service
|
||||
[[ "${QEMU}" = 'qemu:///session' ]] && start_virtiofsd
|
||||
|
||||
# Create VMInfo Json file
|
||||
#( umask 077; ./vm-create-vminfo > "${VMINFO_DIR}/.vminfo.json" )
|
||||
# Start vminfo.timer
|
||||
systemctl --user restart vminfo.timer
|
||||
|
||||
uuid=$(openssl rand -hex 16)
|
||||
uuid="${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}"
|
||||
|
||||
|
|
@ -349,7 +394,6 @@ if ! virsh --connect="${QEMU}" list | grep "${VM_NAME}-clone"; then
|
|||
--memorybacking source.type=memfd,access.mode=shared \
|
||||
--disk "${VM_DIR}/${VM_NAME}-clone.qcow2",driver.discard=unmap,target.bus=scsi,cache=writeback \
|
||||
--network=bridge=virbr0,model.type=virtio \
|
||||
--filesystem driver.type=virtiofs,accessmode=passthrough,target.dir=virtiofs,xpath1.set=./source/@socket="/run/user/${UID}/virtiofs-${VM_NAME}.sock" \
|
||||
--controller type=scsi,model=virtio-scsi \
|
||||
--check path_in_use=off \
|
||||
--connect="${QEMU}" \
|
||||
|
|
|
|||
|
|
@ -1,50 +0,0 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
# if less than one arguments supplied, display usage
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo "This script takes as input the name of the VM " >&2
|
||||
echo "Usage: $0 vm_name" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VM_NAME="$1"
|
||||
|
||||
## Make sure VMs can read the base directory:
|
||||
chgrp 1010 "/lmn/media/${SUDO_USER}"
|
||||
chmod 0775 "/lmn/media/${SUDO_USER}"
|
||||
|
||||
socket="/run/user/$(id -u $SUDO_USER)/virtiofs-${VM_NAME}.sock"
|
||||
|
||||
# FIXME: This does not work. In windows, there is no virtiofs device.
|
||||
# In GNU/Linux it's only readable.
|
||||
#
|
||||
#if ! systemctl -q is-active virtiofs-${VM_NAME}.socket ; then
|
||||
# systemd-run --unit=virtiofs-${VM_NAME} \
|
||||
# --slice=system-virtiofs \
|
||||
# --collect \
|
||||
# --socket-property=ListenStream="$socket" \
|
||||
# --socket-property=Accept=no \
|
||||
# --socket-property=SocketMode=0700 \
|
||||
# --socket-property=SocketUser=${SUDO_USER} \
|
||||
# --property=Type=exec \
|
||||
# --property=StandardInput=socket \
|
||||
# /usr/local/bin/virtiofsd --log-level debug --sandbox none \
|
||||
# --syslog --fd=0 --shared-dir "/lmn/media/${SUDO_USER}"
|
||||
#else
|
||||
# systemctl restart virtiofs-${VM_NAME}.socket
|
||||
#fi
|
||||
|
||||
if [[ ! -S "$socket" ]] ; then
|
||||
systemd-run --unit=virtiofs-${VM_NAME} \
|
||||
--slice=system-virtiofs \
|
||||
--collect \
|
||||
--property=Type=exec \
|
||||
--property=SuccessExitStatus=1 \
|
||||
--property="ExecStopPost=rm $socket" \
|
||||
/usr/local/bin/virtiofsd --socket-path "$socket" \
|
||||
--shared-dir "/lmn/media/${SUDO_USER}"
|
||||
fi
|
||||
sleep 1
|
||||
chown "${SUDO_USER}" "$socket"
|
||||
119
roles/lmn_vm/files/vm-vminfo
Executable file
119
roles/lmn_vm/files/vm-vminfo
Executable file
|
|
@ -0,0 +1,119 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import argparse
|
||||
import struct
|
||||
import subprocess
|
||||
import json
|
||||
import sys
|
||||
|
||||
from os import environ,path
|
||||
from impacket.krb5.ccache import CCache
|
||||
from base64 import b64encode
|
||||
|
||||
home = ""
|
||||
nethome = ""
|
||||
vminfo = {}
|
||||
|
||||
def get_printers():
|
||||
printers = []
|
||||
try:
|
||||
result = subprocess.run(['lpstat', '-v'], capture_output=True, text=True, check=True)
|
||||
for line in result.stdout.splitlines():
|
||||
# Extrahiere den Druckernamen
|
||||
printer_name = line.split()[2].rstrip(':')
|
||||
ipp_url = f"ipp://192.168.122.1/printers/{printer_name}"
|
||||
printer = { 'Name': printer_name, 'IppURL': ipp_url }
|
||||
printers.append(printer)
|
||||
return printers
|
||||
except subprocess.CalledProcessError as e:
|
||||
sys.stderr.write(f"Fehler beim Abrufen der Drucker: {e}")
|
||||
return []
|
||||
|
||||
def get_groups(username):
|
||||
try:
|
||||
result = subprocess.run(['id', '-Gnz', username], capture_output=True, text=True, check=True)
|
||||
groups = result.stdout.strip().split('\0')
|
||||
return groups
|
||||
except subprocess.CalledProcessError as e:
|
||||
sys.stderr.write(f"Fehler beim Abrufen der Gruppen: {e}")
|
||||
return []
|
||||
|
||||
def get_krb5 ():
|
||||
krb5 = {}
|
||||
ccachefilename = environ.get('KRB5CCNAME').replace('FILE:', '')
|
||||
if ccachefilename:
|
||||
try:
|
||||
ccache = CCache.loadFile(ccachefilename)
|
||||
cred = ccache.toKRBCRED()
|
||||
cred_enc = b64encode(cred)
|
||||
krb5['cred'] = cred_enc.decode('utf-8')
|
||||
krb5['starttime'] = ccache.credentials[0]['time']['starttime']
|
||||
krb5['endtime'] = ccache.credentials[0]['time']['endtime']
|
||||
krb5['renew_till'] = ccache.credentials[0]['time']['renew_till']
|
||||
except:
|
||||
sys.stderr.write("Fehler beim Ticket laden")
|
||||
return krb5
|
||||
|
||||
def get_mounts():
|
||||
mounts = []
|
||||
mounts.append({ 'Drive': 'H', 'RemotePath': '\\\\server.pn.steinbeis.schule' + nethome.replace('/srv/samba/schools','').replace('/','\\'), 'Name': 'Home_Server' })
|
||||
mounts.append({ 'Drive': 'T', 'RemotePath': '\\\\server.pn.steinbeis.schule\\default-school\\share', 'Name': 'Tausch' })
|
||||
if "role-teacher" in vminfo['Groups']:
|
||||
mounts.append({ 'Drive': 'S', 'RemotePath': '\\\\server.pn.steinbeis.schule\\default-school\\students', 'Name': 'SuS' })
|
||||
return mounts
|
||||
|
||||
def get_user_folders():
|
||||
HOME="H:"
|
||||
if environ.get('HOME') != nethome:
|
||||
HOME="Y:"
|
||||
folders = []
|
||||
folders.append( {'Name': 'Personal', 'Path': f"{HOME}\Dokumente"} )
|
||||
folders.append( {'Name': 'My Pictures', 'Path': f"{HOME}\Bilder"} )
|
||||
folders.append( {'Name': 'My Music', 'Path': f"{HOME}\Musik"} )
|
||||
folders.append( {'Name': 'My Video', 'Path': f"{HOME}\Videos"} )
|
||||
return folders
|
||||
|
||||
def get_quickaccess():
|
||||
quickaccess = []
|
||||
quickaccess.append( 'H:\\transfer' )
|
||||
return quickaccess
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
#parser.add_argument('input_file', help="File in kirbi (KRB-CRED) or ccache format")
|
||||
#parser.add_argument('output_file', help="Output file")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
global home, nethome
|
||||
|
||||
args = parse_args()
|
||||
|
||||
home = environ.get('HOME')
|
||||
|
||||
vminfo['User'] = environ.get('USER')
|
||||
vminfo['Groups'] = get_groups(environ.get('USER'))
|
||||
|
||||
for dir in ['teachers','examusers','staff','parents']:
|
||||
potential_path = f"/srv/samba/schools/default-school/{dir}/{vminfo['User']}"
|
||||
if path.isdir(potential_path):
|
||||
nethome = potential_path
|
||||
break
|
||||
if not nethome:
|
||||
result = subprocess.run(['find', '/srv/samba/schools/default-school/students/', '-name', vminfo['User'], '-maxdepth', '2', '-type', 'd'], capture_output=True, text=True, check=False)
|
||||
nethome = result.stdout.splitlines()[0]
|
||||
|
||||
vminfo['Printers'] = get_printers()
|
||||
vminfo['krb5'] = get_krb5()
|
||||
vminfo['Mounts'] = get_mounts()
|
||||
vminfo['UserShellFolders'] = get_user_folders()
|
||||
vminfo['QuickAccess'] = get_quickaccess()
|
||||
|
||||
vminfo_json = json.dumps(vminfo, ensure_ascii=False, indent=4)
|
||||
print(vminfo_json)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
|
@ -16,10 +16,13 @@
|
|||
name:
|
||||
- aria2
|
||||
- mktorrent
|
||||
- guestfs-tools
|
||||
- libvirt-daemon-system
|
||||
- virt-manager
|
||||
- virt-viewer
|
||||
- dialog # for vm-netboot menu
|
||||
- python3-impacket
|
||||
- virtiofsd
|
||||
|
||||
# - name: allow all users to use VMs
|
||||
# lineinfile:
|
||||
|
|
@ -28,32 +31,6 @@
|
|||
# insertafter: '#auth_unix_rw = "polkit"'
|
||||
# notify: reload libvirtd
|
||||
|
||||
- name: Configure pam_mount for VM bind mounts
|
||||
ansible.builtin.blockinfile:
|
||||
dest: /etc/security/pam_mount.conf.xml
|
||||
marker: "<!-- {mark} ANSIBLE MANAGED BLOCK (bind mounts for VMs) -->"
|
||||
block: |
|
||||
<!-- bind mounts for the VMs, setting gid here does not work -->
|
||||
<volume
|
||||
path="~"
|
||||
mountpoint="/lmn/media/%(USER)/home"
|
||||
options="bind"
|
||||
><not><or><user>root</user><user>ansible</user><user>Debian-gdm</user><user>sddm</user>{% if localuser %}<user>{{ localuser }}</user>{% endif %}</or></not>
|
||||
</volume>
|
||||
<volume
|
||||
path="/srv/samba/schools/default-school/share"
|
||||
mountpoint="/lmn/media/%(USER)/share"
|
||||
options="bind"
|
||||
><not><or><user>root</user><user>ansible</user><user>Debian-gdm</user><user>sddm</user>{% if localuser %}<user>{{ localuser }}</user>{% endif %}</or></not>
|
||||
</volume>
|
||||
<volume
|
||||
path="/srv/samba/schools/default-school"
|
||||
mountpoint="/lmn/media/%(USER)/school"
|
||||
options="bind"
|
||||
><not><or><user>root</user><user>ansible</user><user>Debian-gdm</user><user>sddm</user>{% if localuser %}<user>{{ localuser }}</user>{% endif %}</or></not>
|
||||
</volume>
|
||||
insertafter: "<!-- END ANSIBLE MANAGED BLOCK .* -->"
|
||||
|
||||
- name: Use umount script for proper cleanup
|
||||
ansible.builtin.blockinfile:
|
||||
dest: /etc/security/pam_mount.conf.xml
|
||||
|
|
@ -143,14 +120,14 @@
|
|||
group: root
|
||||
mode: '0755'
|
||||
loop:
|
||||
- vm-delete
|
||||
- vm-create
|
||||
- vm-rebase
|
||||
- vm-run
|
||||
- vm-upload
|
||||
- vm-sync
|
||||
- vm-link-images
|
||||
- vm-virtiofsd
|
||||
- virtiofsd
|
||||
- vm-vminfo
|
||||
- vm-aria2
|
||||
- uploadseed
|
||||
- desktop-sync
|
||||
|
|
@ -237,3 +214,26 @@
|
|||
src: vm-netboot
|
||||
dest: /usr/local/bin/
|
||||
mode: '0755'
|
||||
|
||||
- name: Provide vminfo service
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Create .vminfo.json for VMs
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/bash -c 'umask 077; /usr/local/bin/vm-vminfo > "{% if localhome %}/home{% else %}/lmn/media{% endif %}/${USER}/.vminfo.json"'
|
||||
dest: /etc/systemd/user/vminfo.service
|
||||
mode: '0644'
|
||||
|
||||
- name: Provide vminfo timer
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
[Unit]
|
||||
Description=Timer for vm-info
|
||||
[Timer]
|
||||
OnActiveSec=0s
|
||||
OnUnitActiveSec=1h
|
||||
Persistent=true
|
||||
dest: /etc/systemd/user/vminfo.timer
|
||||
mode: '0644'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue