2010-04-05 22:25:37 +00:00
|
|
|
#
|
|
|
|
# This SPEC is for bulding RPM packages that contain complete Qubes Template files
|
|
|
|
# This includes the VM's root image, patched with all qubes rpms, etc
|
|
|
|
#
|
|
|
|
|
2011-07-02 12:34:17 +00:00
|
|
|
%{!?version: %define version %(cat version)}
|
2015-03-10 03:19:28 +00:00
|
|
|
%{!?rel: %define rel %(cat build_timestamp_%{template_name})}
|
2010-04-05 22:25:37 +00:00
|
|
|
|
|
|
|
Name: qubes-template-%{template_name}
|
|
|
|
Version: %{version}
|
2012-11-06 09:43:45 +00:00
|
|
|
Release: %{rel}
|
2010-04-05 22:25:37 +00:00
|
|
|
Summary: Qubes template for %{template_name}
|
|
|
|
|
|
|
|
License: GPL
|
|
|
|
URL: http://www.qubes-os.org
|
|
|
|
Source: .
|
|
|
|
|
2010-09-30 15:28:58 +00:00
|
|
|
Requires: xdg-utils
|
2013-01-23 00:29:54 +00:00
|
|
|
Requires(post): tar
|
2013-02-06 13:14:55 +00:00
|
|
|
Provides: qubes-template
|
2014-04-22 17:43:35 +00:00
|
|
|
Obsoletes: %{name} > %{version}-%{release}
|
2010-04-05 22:25:37 +00:00
|
|
|
|
|
|
|
%define _builddir %(pwd)
|
|
|
|
%define _rpmdir %(pwd)/rpm
|
|
|
|
%define dest_dir /var/lib/qubes/vm-templates/%{template_name}
|
|
|
|
|
2010-09-16 17:23:32 +00:00
|
|
|
%define _binaries_in_noarch_packages_terminate_build 0
|
2010-04-05 22:25:37 +00:00
|
|
|
%description
|
|
|
|
Qubes template for %{template_name}
|
|
|
|
|
|
|
|
%build
|
2016-04-20 08:23:36 +00:00
|
|
|
cd qubeized_images/%{template_name}
|
2010-04-05 22:25:37 +00:00
|
|
|
rm -f root.img.part.*
|
2015-03-09 12:38:09 +00:00
|
|
|
tar --sparse --dereference -cf - root.img | split -d -b 1G - root.img.part.
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2017-09-26 16:52:38 +00:00
|
|
|
if [ "0$DISCARD_PREPARED_IMAGE" -eq 1 ]; then
|
|
|
|
rm -f root.img
|
|
|
|
fi
|
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
%install
|
|
|
|
rm -rf $RPM_BUILD_ROOT
|
|
|
|
mkdir -p $RPM_BUILD_ROOT/%{dest_dir}
|
2015-03-09 12:38:09 +00:00
|
|
|
for i in qubeized_images/%{template_name}/root.img.part.* ; do mv $i $RPM_BUILD_ROOT/%{dest_dir}/ ; done
|
2010-04-05 22:25:37 +00:00
|
|
|
touch $RPM_BUILD_ROOT/%{dest_dir}/root.img # we will create the real file in %post
|
|
|
|
touch $RPM_BUILD_ROOT/%{dest_dir}/private.img # we will create the real file in %post
|
2011-09-26 17:16:31 +00:00
|
|
|
touch $RPM_BUILD_ROOT/%{dest_dir}/volatile.img # we will create the real file in %post
|
2015-03-07 02:43:33 +00:00
|
|
|
touch $RPM_BUILD_ROOT/%{dest_dir}/clean-volatile.img.tar # we will create the real file in %post
|
2011-03-19 02:30:23 +00:00
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
mkdir -p $RPM_BUILD_ROOT/%{dest_dir}/apps.templates
|
2014-09-09 20:04:45 +00:00
|
|
|
mkdir -p $RPM_BUILD_ROOT/%{dest_dir}/apps.tempicons
|
2010-04-05 22:25:37 +00:00
|
|
|
mkdir -p $RPM_BUILD_ROOT/%{dest_dir}/apps
|
2011-07-10 21:42:54 +00:00
|
|
|
cp appmenus/whitelisted-appmenus.list appmenus/vm-whitelisted-appmenus.list $RPM_BUILD_ROOT/%{dest_dir}/
|
2012-05-01 00:09:35 +00:00
|
|
|
cp appmenus/netvm-whitelisted-appmenus.list $RPM_BUILD_ROOT/%{dest_dir}/
|
2010-04-05 22:25:37 +00:00
|
|
|
touch $RPM_BUILD_ROOT/%{dest_dir}/icon.png
|
|
|
|
|
2010-10-01 13:40:01 +00:00
|
|
|
%pre
|
|
|
|
|
|
|
|
export XDG_DATA_DIRS=/usr/share/
|
|
|
|
if [ "$1" -gt 1 ] ; then
|
|
|
|
# upgrading already installed template...
|
|
|
|
echo "--> Removing previous menu shortcuts..."
|
|
|
|
xdg-desktop-menu uninstall --mode system %{dest_dir}/apps/*.directory %{dest_dir}/apps/*.desktop
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
%post
|
2016-11-02 05:07:00 +00:00
|
|
|
|
|
|
|
if command -v qvm-template-postprocess >/dev/null 2>&1; then
|
|
|
|
qvm-template-postprocess --really post-install %{template_name} %{dest_dir}
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
echo "--> Processing the root.img... (this might take a while)"
|
|
|
|
cat %{dest_dir}/root.img.part.* | tar --sparse -xf - -C %{dest_dir}
|
|
|
|
rm -f %{dest_dir}/root.img.part.*
|
|
|
|
chown root.qubes %{dest_dir}/root.img
|
|
|
|
chmod 0660 %{dest_dir}/root.img
|
|
|
|
|
2011-03-19 21:12:52 +00:00
|
|
|
echo "--> Processing the volatile.img..."
|
2015-03-09 18:54:51 +00:00
|
|
|
/usr/lib/qubes/prepare-volatile-img.sh %{dest_dir}/volatile.img $[ `stat -c '%s' %{dest_dir}/root.img` / 1024 / 1024 ] || exit 1
|
2011-03-19 21:12:52 +00:00
|
|
|
chown root.qubes %{dest_dir}/volatile.img
|
|
|
|
chmod 0660 %{dest_dir}/volatile.img
|
2015-03-07 02:43:33 +00:00
|
|
|
tar --sparse -cf %{dest_dir}/clean-volatile.img.tar -C %{dest_dir} volatile.img
|
|
|
|
chown root.qubes %{dest_dir}/clean-volatile.img.tar
|
|
|
|
chmod 0660 %{dest_dir}/clean-volatile.img.tar
|
2011-03-19 02:30:23 +00:00
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
if [ "$1" = 1 ] ; then
|
|
|
|
# installing for the first time
|
|
|
|
echo "--> Creating private.img..."
|
|
|
|
truncate -s 2G %{dest_dir}/private.img
|
2014-09-05 20:06:05 +00:00
|
|
|
mkfs.ext4 -m 0 -q -F %{dest_dir}/private.img
|
2010-04-05 22:25:37 +00:00
|
|
|
chown root.qubes %{dest_dir}/private.img
|
|
|
|
chmod 0660 %{dest_dir}/private.img
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
export XDG_DATA_DIRS=/usr/share/
|
|
|
|
|
|
|
|
echo "--> Instaling menu shortcuts..."
|
|
|
|
ln -sf /usr/share/qubes/icons/template.png %{dest_dir}/icon.png
|
|
|
|
|
2015-05-16 22:01:09 +00:00
|
|
|
local_user=`getent group qubes | cut -d : -f 4 | cut -d , -f 1`
|
|
|
|
if [ -n "$local_user" ]; then
|
|
|
|
call_as_user() {
|
|
|
|
su -c "$*" - $local_user
|
|
|
|
}
|
|
|
|
else
|
|
|
|
# This will be the case during installation - user will be created in
|
|
|
|
# firstboot. There is also a code to fix file permissions, so not a big problem
|
|
|
|
call_as_user() {
|
|
|
|
$*
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
if [ "$1" = 1 ] ; then
|
|
|
|
# installing for the first time
|
2015-05-16 22:01:09 +00:00
|
|
|
call_as_user qvm-add-template --rpm %{template_name}
|
2010-04-05 22:25:37 +00:00
|
|
|
fi
|
|
|
|
|
2013-05-18 03:56:30 +00:00
|
|
|
# If running inside of chroot (means - from anaconda), force offline mode
|
|
|
|
if [ "`stat -c %d:%i /`" != "`stat -c %d:%i /proc/1/root/.`" ]; then
|
|
|
|
qvm-template-commit --offline-mode %{template_name}
|
2015-05-16 22:01:09 +00:00
|
|
|
call_as_user /usr/libexec/qubes-appmenus/create-apps-for-appvm.sh \
|
2015-07-08 03:10:02 +00:00
|
|
|
%{dest_dir}/apps.templates %{template_name} vm-templates appvm-black
|
2013-05-18 03:56:30 +00:00
|
|
|
else
|
|
|
|
qvm-template-commit %{template_name}
|
2015-05-16 22:01:09 +00:00
|
|
|
qvm-prefs --force-root -s %{template_name} netvm none
|
2015-03-07 02:43:33 +00:00
|
|
|
qvm-start --no-guid %{template_name}
|
2015-05-16 22:01:09 +00:00
|
|
|
call_as_user qvm-sync-appmenus --force-root %{template_name}
|
2015-03-07 02:43:33 +00:00
|
|
|
qvm-shutdown --wait %{template_name}
|
2015-05-16 22:01:09 +00:00
|
|
|
qvm-prefs --force-root -s %{template_name} netvm default
|
2015-03-18 19:05:44 +00:00
|
|
|
# restore default firewall settings, which was reset by setting netvm=none
|
|
|
|
rm -f %{dest_dir}/firewall.xml
|
2015-03-07 02:43:33 +00:00
|
|
|
chgrp -R qubes %{dest_dir}
|
|
|
|
chmod g+rwX -R %{dest_dir}
|
2013-05-18 03:56:30 +00:00
|
|
|
fi
|
2015-03-11 06:26:29 +00:00
|
|
|
exit 0
|
2011-03-16 08:52:21 +00:00
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
%preun
|
|
|
|
if [ "$1" = 0 ] ; then
|
|
|
|
# no more packages left
|
2016-11-02 05:07:00 +00:00
|
|
|
|
|
|
|
if command -v qvm-template-postprocess >/dev/null 2>&1; then
|
|
|
|
qvm-template-postprocess --really pre-remove %{template_name} %{dest_dir}
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2011-04-05 13:20:10 +00:00
|
|
|
# First remove DispVM template (even if not exists...)
|
2012-01-06 12:25:14 +00:00
|
|
|
qvm-remove --force-root -q %{template_name}-dvm
|
2011-04-05 13:20:10 +00:00
|
|
|
|
2012-01-06 12:25:14 +00:00
|
|
|
if ! qvm-remove --force-root -q --just-db %{template_name}; then
|
2011-04-05 13:20:10 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2010-04-05 22:25:37 +00:00
|
|
|
|
2013-12-13 03:18:25 +00:00
|
|
|
rm -f %{dest_dir}/root-cow.img
|
|
|
|
rm -f %{dest_dir}/root-cow.img.old
|
|
|
|
rm -f %{dest_dir}/firewall.xml
|
|
|
|
rm -f %{dest_dir}/%{template_name}.conf
|
|
|
|
rm -f %{dest_dir}/updates.stat
|
|
|
|
|
2010-04-05 22:25:37 +00:00
|
|
|
# we need to have it here, because rpm -U <template>
|
|
|
|
# apparently executes %preun of the old package *after* %post of the new packages...
|
|
|
|
echo "--> Removing menu shortcuts..."
|
|
|
|
export XDG_DATA_DIRS=/usr/share/
|
|
|
|
xdg-desktop-menu uninstall --mode system %{dest_dir}/apps/*.directory %{dest_dir}/apps/*.desktop
|
|
|
|
|
2013-12-13 03:18:25 +00:00
|
|
|
rm -rf %{dest_dir}/apps %{dest_dir}/apps.templates
|
2015-11-26 02:35:34 +00:00
|
|
|
rm -rf %{dest_dir}/apps.icons %{dest_dir}/apps.tempicons
|
2010-04-05 22:25:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
%clean
|
|
|
|
rm -rf $RPM_BUILD_ROOT
|
|
|
|
|
|
|
|
%files
|
|
|
|
%defattr(660,root,qubes,770)
|
2013-05-19 23:36:45 +00:00
|
|
|
%attr(2770,root,qubes) %dir %{dest_dir}
|
2010-04-05 22:25:37 +00:00
|
|
|
%ghost %{dest_dir}/root.img
|
|
|
|
%{dest_dir}/root.img.part.*
|
2011-03-19 02:30:23 +00:00
|
|
|
%{dest_dir}/clean-volatile.img.tar
|
2011-03-19 21:12:52 +00:00
|
|
|
%ghost %{dest_dir}/volatile.img
|
2010-04-05 22:25:37 +00:00
|
|
|
%ghost %{dest_dir}/private.img
|
|
|
|
%attr (775,root,qubes) %dir %{dest_dir}/apps
|
|
|
|
%attr (775,root,qubes) %dir %{dest_dir}/apps.templates
|
2014-09-09 20:04:45 +00:00
|
|
|
%attr (775,root,qubes) %dir %{dest_dir}/apps.tempicons
|
2011-07-10 21:42:54 +00:00
|
|
|
%attr (664,root,qubes) %{dest_dir}/whitelisted-appmenus.list
|
|
|
|
%attr (664,root,qubes) %{dest_dir}/vm-whitelisted-appmenus.list
|
2012-05-01 00:09:35 +00:00
|
|
|
%attr (664,root,qubes) %{dest_dir}/netvm-whitelisted-appmenus.list
|
2010-04-05 22:25:37 +00:00
|
|
|
%{dest_dir}/icon.png
|