# Makefile to install qemu-web-desktop. # just type: make install # # required: # apache2 libapache2-mod-perl2 novnc websockify qemu-kvm bridge-utils qemu # iptables dnsmasq libcgi-pm-perl liblist-moreutils-perl libsys-cpu-perl # libsys-cpuload-perl libsys-meminfo-perl libnet-dns-perl # libproc-background-perl libproc-processtable-perl libemail-valid-perl # libnet-smtps-perl libmail-imapclient-perl libnet-ldap-perl # libemail-valid-perl libjson-perl libwww-perl libguestfs-tools libapache2-mpm-itk # libtext-qrcode-perl # on ARM64, an EFI boot is required (e.g. qemu-efi-aarch64) # # NOTES: # you may have to tune the path to /etc/apache2/conf-available/serve-cgi-bin.conf # or other locations. The current makefile works best on Debian-class systems. # # make install # install qemu-web-desktop # make config # configure qemu-web-desktop # make deps # install dependencies (before make install) # make test # test # make deb # build debian package # make help # build the documentation files (requires help2man pandoc librsvg2-bin texlive-latex-base texlive-latex-recommended) # alt man generation: pandoc -s -o qwdctl.1 --to man -f markdown-smart qwdctl.md ARCH= VERSION=$(shell awk -F= '/config{version}[[:space:]]*=/ {print $$2}' cgi-bin/qemu-web-desktop.pl | sed -e 's/;.*//' -e 's/"//g' -e 's/[[:space:]]*//g' | tail -1 ) # auto detect system type ifneq ("$(wildcard /etc/debian_version)","") ARCH = Debian $(info Detected Debian-type system) else ifneq ("$(wildcard /etc/redhat-release)","") ARCH = RedHat $(info Detected RedHat-type system) else ifneq ("$(wildcard /etc/arch-release)","") ARCH = Arch $(info Detected Arch-type system) else ifneq ("$(wildcard /etc/bashrc_Apple_Terminal)","") ARCH = Darwin $(info Detected Darwin-type system - Apple) endif # auto detect type of CPU (for installation) uname_m := $(shell uname -m) QEMU.i386 := qemu-system-x86 QEMU.x86_64 := qemu-system-x86 QEMU.aarch64 := qemu-system-arm QEMU.arm64 := qemu-system-arm QEMU ?= $(QEMU.$(uname_m)) ifeq ($(ARCH),Debian) DIR_CGI_BIN = /usr/lib/cgi-bin DIR_APACHE_CONF_QWD = /etc/apache2/conf-available APACHE_CONF = DIR_WWW = /var/www/html else ifeq ($(ARCH),RedHat) DIR_CGI_BIN = /var/www/cgi-bin DIR_APACHE_CONF_QWD = /etc/httpd/conf.d/ APACHE_CONF = /etc/httpd/conf/httpd.conf DIR_WWW = /var/www/html else ifeq ($(ARCH),Arch) DIR_CGI_BIN = /srv/http/cgi-bin DIR_APACHE_CONF_QWD = /etc/httpd/conf/extra/ APACHE_CONF = /etc/httpd/conf/httpd.conf DIR_WWW = /srv/http else ifeq ($(ARCH),Darwin) DESTDIR ?= $(shell brew --prefix) PERLDIR = $(shell brew --prefix perl) DIR_APACHE_CONF_QWD = /etc/httpd/extra/ APACHE_CONF = /etc/httpd/httpd.conf DIR_CGI_BIN = /Library/WebServer/CGI-Executables/ DIR_WWW = /Library/WebServer/Documents/ else $(error Undefined target. Set system type with: make install ARCH=Debian|RedHat|Arch|Darwin) endif all: help help: ifneq ($(ARCH),Darwin) @help2man -o doc/qwdctl.1 --no-discard-stderr -n 'control qemu-web-desktop' bin/qwdctl || true @pandoc -s -f man -t markdown < doc/qwdctl.1 > doc/qwdctl.md || true @sed '/^\[!\[DOI\]/d' README.md | pandoc --to pdf -o doc/README.pdf || true @pandoc --to pdf -o doc/CONFIGURE.pdf doc/CONFIGURE.md || true @pandoc --to pdf -o doc/GPU.pdf doc/GPU.md || true @pandoc --to pdf -o doc/INSTALL.pdf doc/INSTALL.md || true @pandoc --to pdf -o doc/qwdctl.pdf doc/qwdctl.md || true @pandoc --to pdf -o doc/USAGE.pdf doc/USAGE.md || true @pandoc --to pdf -o doc/VIRTUAL_MACHINES.pdf doc/VIRTUAL_MACHINES.md || true endif @echo "Usage: install qemu-web-desktop" @echo "make deps" @echo " install dependencies" @echo "make install" @echo " install qemu-web-desktop" @echo "make uninstall" @echo " uninstall qemu-web-desktop" @echo "make deb" @echo " create debian package" # ------------------------------------------------------------------------------ # dependencies deps: @echo "Installing $(ARCH)-class dependencies" ifeq ($(ARCH),Debian) sudo apt install apache2 libapache2-mod-perl2 novnc websockify $(QEMU) qemu-utils bridge-utils iptables dnsmasq libcgi-pm-perl liblist-moreutils-perl libsys-cpu-perl libsys-cpuload-perl libsys-meminfo-perl libnet-dns-perl libproc-background-perl libproc-processtable-perl libemail-valid-perl libnet-smtps-perl libmail-imapclient-perl libnet-ldap-perl libemail-valid-perl libjson-perl libwww-perl libguestfs-tools libapache2-mpm-itk libtext-qrcode-perl libnet-ssh2-perl wget nano if [ "$(uname_m)" = "aarch64" -o "$(uname_m)" = "arm64" ]; then sudo apt install qemu-efi-aarch64; fi else ifeq ($(ARCH),Arch) @echo "NOTE: You need 'yay' to be installed, and the AUR to be available." yay -Sy python-numpy python-setuptools mod_itk apache qemu-desktop bridge-utils qemu-img dnsmasq guestfs-tools perl-cgi perl-list-moreutils perl-sys-cpu perl-sys-meminfo perl-net-dns perl-proc-processtable perl-mail-imapclient perl-ldap perl-json perl-libwww mod_perl novnc websockify perl-proc-background perl-email-valid perl-net-smtps perl-text-qrcode perl-net-ssh2 wget nano else ifeq ($(ARCH),RedHat) @echo "NOTE: This system-type is not fully supported" sudo dnf install mod_perl novnc python3-websockify guestfs-tools perl-CGI perl-List-MoreUtils perl-Sys-CPU perl-Sys-MemInfo perl-Net-DNS perl-Proc-ProcessTable perl-Email-Valid perl-Net-SMTPS perl-Mail-IMAPClient perl-LDAP perl-JSON perl-libwww-perl perl-Text-QRCode perl-Net-SSH2 perl-Net-Ping perl-CPAN wget nano sudo cpan Proc::Background else ifeq ($(ARCH),Darwin) ifeq ($(shell id -u),0) $(error "Install dependencies as normal user, not root.") endif @echo "NOTE: This system-type is not properly supported" brew install apache2 qemu perl python3 python-setuptools grep wget gnu-sed nano cpanminus # install PERL CPAN modules # WARNING: Net::SMTPS fails installation on Mac cpanm --notest CGI Cwd File::Temp File::Path File::Basename File::Copy List::MoreUtils List::Util IO::Socket::INET IO::Socket::IP JSON Proc::Background Proc::ProcessTable Proc::Killfam System::CPU Sys::MemInfo Email::Valid Mail::IMAPClient LWP::UserAgent Net::Ping Net::LDAP Net::SSH2 URI # install websockify $(cd /tmp; wget https://github.com/novnc/websockify/archive/refs/tags/v0.13.0.tar.gz; tar xzf v0.13.0.tar.gz; cd websockify-0.13.0; python3 setup.py build; python3 setup.py build; ) # install novnc if [ ! -d "$(DESTDIR)/usr/share/novnc" ]; then bash -c "cd /tmp; wget https://github.com/novnc/noVNC/archive/refs/tags/v1.6.0.tar.gz; tar xzf v1.6.0.tar.gz; cp -r noVNC-1.6.0 $(DESTDIR)/usr/share/novnc"; fi endif @echo "[OK] Dependencies installed for $(ARCH)" @echo "You may now proceed with: make install" # ------------------------------------------------------------------------------ # install install: copy config copy: @echo "Copying QWD files for $(ARCH)-type system" ifeq ($(ARCH),Darwin) # copy: Darwin/Apple macos # create directories (install command is broken - we use mkdir/cp) ifeq ($(shell id -u),0) $(error "Install as normal user (brew), not root.") endif mkdir -p $(DESTDIR)$(prefix)/etc/qemu-web-desktop mkdir -p $(DESTDIR)$(prefix)/etc/qemu-web-desktop/config.d mkdir -p $(DESTDIR)$(prefix)/bin mkdir -p $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop mkdir -p $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop/images mkdir -p $(DESTDIR)$(prefix)/usr/share/doc/qemu-web-desktop mkdir -p $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines mkdir -p $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/snapshots mkdir -p $(DESTDIR)$(prefix)/var/www/cgi-bin/ # common install cp etc/machines.conf $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ cp etc/config.pl $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ cp html/desktop/index.html $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop cp html/desktop/style.css $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop cp html/desktop/images/* $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop/images cp doc/*.pdf $(DESTDIR)$(prefix)/usr/share/doc/qemu-web-desktop cp bin/qwdctl $(DESTDIR)$(prefix)/bin/ -cp html/desktop/machines/* $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines # system specific locations # mkdir -p $(DESTDIR)$(prefix)$(DIR_APACHE_CONF_QWD) # cp etc/apache.conf $(DESTDIR)$(prefix)$(DIR_APACHE_CONF_QWD)/qemu-web-desktop.conf sudo cp cgi-bin/qemu-web-desktop.pl $(prefix)$(DIR_CGI_BIN) sudo sed -i '' 's|^#!/usr/bin/env perl|#!$(PERLDIR)/bin/perl|' $(prefix)$(DIR_CGI_BIN)qemu-web-desktop.pl sudo chmod 755 $(prefix)$(DIR_CGI_BIN)qemu-web-desktop.pl chmod a+x $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ chmod -R a+r $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ chmod a+x $(DESTDIR)$(prefix)/etc/qemu-web-desktop/config.d chmod a+xrw $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/snapshots chmod a+xrw $(DESTDIR)$(prefix)/var/log/ touch $(DESTDIR)$(prefix)/var/log/qemu-web-desktop.log chmod a+rw $(DESTDIR)$(prefix)/var/log/qemu-web-desktop.log # now sudo part to link to the native Apache from macos -sudo ln -s $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop $(prefix)$(DIR_WWW)/qemu-web-desktop -sudo ln -s $(prefix)$(DIR_CGI_BIN)qemu-web-desktop.pl $(DESTDIR)$(prefix)/var/www/cgi-bin/ else # not Darwin/Apple macos # create directories install -D -d $(DESTDIR)$(prefix)/etc/qemu-web-desktop install -D -d $(DESTDIR)$(prefix)/usr/bin install -D -d $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop install -D -d $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop/images install -D -d $(DESTDIR)$(prefix)/usr/share/doc/qemu-web-desktop install -D -d $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines install -D -d $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/snapshots # common install install -D etc/machines.conf -m 644 $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ install -D etc/config.pl -m 644 $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ install -D html/desktop/index.html -m 644 $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop install -D html/desktop/style.css -m 644 $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop install -D html/desktop/images/* -m 644 $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop/images install -D doc/qwdctl.1 -m 644 $(DESTDIR)$(prefix)/usr/share/man/man1/qwdctl.1 install -D doc/README.pdf -m 644 $(DESTDIR)$(prefix)/usr/share/doc/qemu-web-desktop install -D bin/qwdctl $(DESTDIR)$(prefix)/usr/bin/ -install -D html/desktop/machines/* -m 644 $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines # system specific locations ifndef DEB_BUILD_ARCH install -D -d $(DESTDIR)$(prefix)$(DIR_WWW) endif install -D -d $(DESTDIR)$(prefix)$(DIR_APACHE_CONF_QWD) install etc/apache.conf -m 644 $(DESTDIR)$(prefix)$(DIR_APACHE_CONF_QWD)/qemu-web-desktop.conf install -D -d $(DESTDIR)$(prefix)$(DIR_CGI_BIN) install -D cgi-bin/qemu-web-desktop.pl $(DESTDIR)$(prefix)$(DIR_CGI_BIN)/qemu-web-desktop.pl chmod 755 $(DESTDIR)$(prefix)$(DIR_CGI_BIN)/qemu-web-desktop.pl # system specific actions ifneq ($(ARCH),Debian) sed -i 's|Alias /qemu-web-desktop|#Alias /qemu-web-desktop|' $(DESTDIR)$(prefix)$(DIR_APACHE_CONF_QWD)/qemu-web-desktop.conf sed -i 's/config{service_port_multiple} = 0/config{service_port_multiple} = 1/' $(DESTDIR)$(prefix)/etc/qemu-web-desktop//config.pl sed -i 's/machines_insert=no/machines_insert=yes/' $(DESTDIR)$(prefix)/usr/bin/qwdctl endif find $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html -type f -exec chmod a+r {} + find $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html -type d -exec chmod a+rx {} + chmod u+xrw $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/snapshots endif # not Darwin/Apple chmod a+wxr $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop chmod a+xrw $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines @echo "[OK] QWD Installation complete for $(ARCH)." @echo "You may now proceed with: make config" # ------------------------------------------------------------------------------ # post-install/auto configure config: ifndef DEB_BUILD_ARCH @echo "Post QWD installation steps (auto-configure) for $(ARCH)" # skip when buidling Debian ifneq ($(ARCH),Darwin) -ln -sf $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop $(DESTDIR)$(prefix)$(DIR_WWW)/ -ln -sf $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines $(DESTDIR)$(prefix)$(DIR_WWW)/desktop/ endif # log file touch $(DESTDIR)$(prefix)/var/log/qemu-web-desktop.log chmod 640 $(DESTDIR)$(prefix)/var/log/qemu-web-desktop.log ifeq ($(ARCH),Debian) -adduser --system --home $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop --force-badname _qemu-web-desktop -chown -R _qemu-web-desktop $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop -chown _qemu-web-desktop $(DESTDIR)$(prefix)/var/log/qemu-web-desktop.log systemctl enable apache2 a2enconf qemu-web-desktop a2enmod cgi proxy proxy_http proxy_wstunnel rewrite include systemctl restart apache2 chmod 755 /etc/qemu-ifup endif ifeq ($(ARCH),Arch) useradd --system -m --home-dir $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop --badname _qemu-web-desktop chown -R _qemu-web-desktop $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop ln -sf $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop $(DESTDIR)$(prefix)$(DIR_WWW)/qemu-web-desktop sed -i 's|/usr/share/novnc|$(DESTDIR)$(prefix)/usr/share/webapps/novnc|' $(DESTDIR)$(prefix)/etc/qemu-web-desktop/config.pl # MPM ITK requires prefork, that conflicts with mpm_event sed -i 's/LoadModule mpm_event/#LoadModule mpm_event/' $(DESTDIR)$(prefix)$(APACHE_CONF) sed -i 's/#LoadModule mpm_prefork/LoadModule mpm_prefork/' $(DESTDIR)$(prefix)$(APACHE_CONF) grep -q "mpm_itk" $(DESTDIR)$(prefix)$(APACHE_CONF) || echo "LoadModule mpm_itk_module modules/mpm_itk.so" >> $(DESTDIR)$(prefix)$(APACHE_CONF) grep -q "qemu-web-desktop" $(DESTDIR)$(prefix)$(APACHE_CONF) || echo "Include conf/extra/qemu-web-desktop.conf" >> $(DESTDIR)$(prefix)$(APACHE_CONF) systemctl enable httpd systemctl daemon-reload systemctl restart httpd endif ifeq ($(ARCH),RedHat) # There is no available MPM ITK module :-( chown -R apache $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop ln -sf $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop $(DESTDIR)$(prefix)$(DIR_WWW)/qemu-web-desktop usermod -a -G kvm apache systemctl enable httpd systemctl daemon-reload systemctl restart httpd # SElinux permissions: allow port 6080 (update if config.pl changes). # Currently this does not work: we get a KVM error from httpd daemon semanage port -a -t http_port_t -p tcp 6080 || true semanage port -a -t http_port_t -p tcp 5901 || true setsebool -P httpd_can_network_relay 1 setsebool -P httpd_can_network_connect 1 setsebool -P httpd_read_user_content 1 @echo "WARNING: $(ARCH): the web service will probably not work. Use: qwdctl start VM|ISO" endif ln -sf $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/machines.html $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop/html/desktop || true @echo " " @echo "[OK] QWD Configuration complete for $(ARCH)." qwdctl download @echo "Now connect to http://localhost/qemu-web-desktop for immediate use." @echo "or launch a VM with: qwdctl start VM" @echo "or refer to https://gitlab.com/soleil-data-treatment/soleil-software-projects/qemu-web-desktop" @echo "to configure the service." endif # not a Debian build # ------------------------------------------------------------------------------ test: -qwdctl stop ifneq ($(ARCH),Darwin) if timeout 10 perl cgi-bin/qemu-web-desktop.pl --dir_snapshots=/tmp --dir_cfg=/tmp --dir_machines=html/desktop/machines/ --oneshot=1 --machine=TinyCore-current.iso = 124; then echo "OK"; fi else @echo "Test is not available for Darwin/Apple macos" endif @echo Test OK uninstall: -rm -rf $(DESTDIR)$(prefix)/etc/qemu-web-desktop/ -rm -rf $(DESTDIR)$(prefix)/usr/share/qemu-web-desktop -rm -rf $(DESTDIR)$(prefix)/usr/share/doc/qemu-web-desktop -rm -f $(DESTDIR)$(prefix)/usr/share/man/man1/qwdctl.* -rm -f $(DESTDIR)$(prefix)/usr/bin/qwdctl -rm -rf $(DESTDIR)$(prefix)/var/lib/qemu-web-desktop/ -rm -rf $(DESTDIR)$(prefix)$(DIR_WWW)/qemu-web-desktop -rm -rf $(DESTDIR)$(prefix)$(DIR_WWW)/desktop -rm -f $(DESTDIR)$(prefix)$(DIR_APACHE_CONF_QWD)/qemu-web-desktop.conf -rm -f $(DESTDIR)$(prefix)$(DIR_CGI_BIN)/qemu-web-desktop.pl if [ -e $(DESTDIR)$(prefix)/etc/httpd/conf/httpd.conf ]; then \ sed -i 's|Include conf/extra/qemu-web-desktop.conf|#Include conf/extra/qemu-web-desktop.conf|' $(DESTDIR)$(prefix)$(APACHE_CONF); \ fi -apachectl restart -killall -9 websockify -deluser _qemu-web-desktop || userdel _qemu-web-desktop || true @echo "[OK] QWD uninstalled." dist: tar --create \ --auto-compress \ --file=../qemu-web-desktop-$(VERSION).tar.gz \ --transform=s,^./,qemu-web-desktop-$(VERSION)/, \ --exclude=./html/desktop/machines \ --exclude=./.git* \ --exclude=*~ \ --exclude=./debian \ . deb: @echo "Building Debian package" # requires: git-buildpackage dh-apache2 dh-sysuser devscripts -rm -rf debian build cp -r packaging/debian . # remove too big ISO mv html/desktop/machines/slax.iso . debuild -b || true rm -rf debian build mv slax.iso html/desktop/machines/slax.iso @echo "[OK] Build deb" .PHONY: all install uninstall .NOTPARALLEL: copy config