diff --git a/debian/qubes-core-agent.install b/debian/qubes-core-agent.install index 3f5f558..bbbc6a4 100644 --- a/debian/qubes-core-agent.install +++ b/debian/qubes-core-agent.install @@ -37,6 +37,8 @@ etc/qubes-rpc/qubes.VMExec etc/qubes-rpc/qubes.VMExecGUI etc/qubes-rpc/qubes.WaitForSession etc/qubes-rpc/qubes.GetDate +etc/qubes-rpc/qubes.TemplateSearch +etc/qubes-rpc/qubes.TemplateDownload etc/qubes-suspend-module-blacklist etc/qubes/autostart/* etc/qubes/applications/* @@ -150,6 +152,7 @@ usr/lib/qubes/upgrades-status-notify usr/lib/qubes/vm-file-editor usr/lib/qubes/xdg-icon usr/lib/qubes/tinyproxy-wrapper +usr/lib/qubes/qvm-template-repo-query usr/lib/systemd/user/pulseaudio.service.d/30_qubes.conf usr/lib/systemd/user/pulseaudio.socket.d/30_qubes.conf usr/share/glib-2.0/schemas/* diff --git a/qubes-rpc/Makefile b/qubes-rpc/Makefile index 67648a8..a5262bc 100644 --- a/qubes-rpc/Makefile +++ b/qubes-rpc/Makefile @@ -44,7 +44,7 @@ install: install -t $(DESTDIR)$(QUBESLIBDIR) \ prepare-suspend resize-rootfs \ qfile-agent qopen-in-vm qrun-in-vm qubes-sync-clock \ - tar2qfile vm-file-editor xdg-icon + tar2qfile vm-file-editor xdg-icon qvm-template-repo-query # Install qfile-unpacker as SUID, because it will fail to receive # files from other vm. install -t $(DESTDIR)$(QUBESLIBDIR) -m 4755 qfile-unpacker @@ -71,7 +71,9 @@ install: qubes.PostInstall \ qubes.GetDate \ qubes.ShowInTerminal \ - qubes.ConnectTCP + qubes.ConnectTCP \ + qubes.TemplateSearch \ + qubes.TemplateDownload ln -s qubes.VMExec $(DESTDIR)$(QUBESRPCCMDDIR)/qubes.VMExecGUI for config in *.config; do \ install -D -m 0644 "$$config" "$(DESTDIR)$(QUBESRPCCONFDIR)/$${config%.config}"; \ diff --git a/qubes-rpc/qubes.TemplateDownload b/qubes-rpc/qubes.TemplateDownload new file mode 100755 index 0000000..7f0097b --- /dev/null +++ b/qubes-rpc/qubes.TemplateDownload @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +exec /usr/lib/qubes/qvm-template-repo-query download diff --git a/qubes-rpc/qubes.TemplateSearch b/qubes-rpc/qubes.TemplateSearch new file mode 100755 index 0000000..fe79b29 --- /dev/null +++ b/qubes-rpc/qubes.TemplateSearch @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +exec /usr/lib/qubes/qvm-template-repo-query query diff --git a/qubes-rpc/qvm-template-repo-query b/qubes-rpc/qvm-template-repo-query new file mode 100755 index 0000000..9391649 --- /dev/null +++ b/qubes-rpc/qvm-template-repo-query @@ -0,0 +1,49 @@ +#!/usr/bin/bash + +OPTS=() +SPEC= +while IFS= read -r line; do + if [ "$line" = "---" ]; then + break + fi + case "$line" in + --enablerepo=*|\ + --disablerepo=*|\ + --repoid=*|\ + --releasever=*|\ + --refresh) + OPTS+=("$line") + ;; + *) + SPEC="$line" + ;; + esac +done + +repodir=$(mktemp -d) +cat > "$repodir/template.repo" + +OPTS+=("--setopt=reposdir=${repodir}") +OPTS+=("--quiet") + +# This creates the hashfile if it doesn't exist, and keep the ctime and mtime +# unchanged otherwise. +# We then copy the {c,m}time to the repo config. +# This allows DNF caching to work properly. +hashfile="/tmp/qvm-template-$(b2sum "$repodir/template.repo" | cut -f1 -d' ')" +touch -a "$hashfile" +touch -r "$hashfile" "$repodir/template.repo" + +RET=0 + +if [ "$1" = "query" ]; then + dnf repoquery "${OPTS[@]}" --qf='%{name}|%{epoch}|%{version}|%{release}|%{reponame}|%{downloadsize}|%{buildtime}|%{license}|%{url}|%{summary}|%{description}|' "$SPEC" + RET="$?" +elif [ "$1" = "download" ]; then + url="$(dnf download "${OPTS[@]}" --url "$SPEC" | shuf -n 1)" + curl --silent -L "$url" -o - + RET="$?" +fi + +rm -r "$repodir" +exit "$RET" diff --git a/rpm_spec/core-agent.spec.in b/rpm_spec/core-agent.spec.in index 68f587b..6b0b90c 100644 --- a/rpm_spec/core-agent.spec.in +++ b/rpm_spec/core-agent.spec.in @@ -612,6 +612,8 @@ rm -f %{name}-%{version} %config(noreplace) /etc/qubes-rpc/qubes.StartApp %config(noreplace) /etc/qubes-rpc/qubes.PostInstall %config(noreplace) /etc/qubes-rpc/qubes.GetDate +%config(noreplace) /etc/qubes-rpc/qubes.TemplateSearch +%config(noreplace) /etc/qubes-rpc/qubes.TemplateDownload %config(noreplace) /etc/qubes/rpc-config/qubes.OpenInVM %config(noreplace) /etc/qubes/rpc-config/qubes.OpenURL %config(noreplace) /etc/qubes/rpc-config/qubes.SelectFile @@ -686,6 +688,7 @@ rm -f %{name}-%{version} /usr/lib/qubes/qubes-sync-clock /usr/lib/qubes/resize-rootfs /usr/lib/qubes/tinyproxy-wrapper +/usr/lib/qubes/qvm-template-repo-query /usr/lib/dracut/dracut.conf.d/30-qubes.conf %dir /usr/lib/qubes/init /usr/lib/qubes/init/bind-dirs.sh