core-netvm.spec 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  5. # Copyright (C) 2010 Rafal Wojtczuk <rafal@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. #
  21. #
  22. %{!?version: %define version %(cat version_vm)}
  23. Name: qubes-core-netvm
  24. Version: %{version}
  25. Release: 1
  26. Summary: The Qubes core files for NetVM
  27. Group: Qubes
  28. Vendor: Invisible Things Lab
  29. License: GPL
  30. URL: http://www.qubes-os.org
  31. Requires: /usr/bin/xenstore-read
  32. Requires: fedora-release = 13
  33. Requires: NetworkManager >= 0.8.1-1
  34. Provides: qubes-core-vm
  35. %define _builddir %(pwd)/netvm
  36. %description
  37. The Qubes core files for installation inside a Qubes NetVM.
  38. %pre
  39. mkdir -p $RPM_BUILD_ROOT/var/lib/qubes
  40. if [ -e $RPM_BUILD_ROOT/etc/fstab ] ; then
  41. mv $RPM_BUILD_ROOT/etc/fstab $RPM_BUILD_ROOT/var/lib/qubes/fstab.orig
  42. fi
  43. %build
  44. %install
  45. mkdir -p $RPM_BUILD_ROOT/etc/sysconfig
  46. cp ../common/iptables $RPM_BUILD_ROOT/etc/sysconfig
  47. mkdir -p $RPM_BUILD_ROOT/etc
  48. cp fstab $RPM_BUILD_ROOT/etc/fstab
  49. mkdir -p $RPM_BUILD_ROOT/etc/init.d
  50. cp qubes_core $RPM_BUILD_ROOT/etc/init.d/
  51. mkdir -p $RPM_BUILD_ROOT/var/lib/qubes
  52. mkdir -p $RPM_BUILD_ROOT/usr/lib/qubes
  53. cp ../common/qubes_setup_dnat_to_ns $RPM_BUILD_ROOT/usr/lib/qubes
  54. cp ../common/qubes_fix_nm_conf.sh $RPM_BUILD_ROOT/usr/lib/qubes
  55. mkdir -p $RPM_BUILD_ROOT/etc/dhclient.d
  56. ln -s /usr/lib/qubes/qubes_setup_dnat_to_ns $RPM_BUILD_ROOT/etc/dhclient.d/qubes_setup_dnat_to_ns.sh
  57. mkdir -p $RPM_BUILD_ROOT/etc/NetworkManager/dispatcher.d/
  58. cp ../common/qubes_nmhook $RPM_BUILD_ROOT/etc/NetworkManager/dispatcher.d/
  59. mkdir -p $RPM_BUILD_ROOT/etc/yum.repos.d
  60. cp ../netvm/qubes.repo $RPM_BUILD_ROOT/etc/yum.repos.d
  61. mkdir -p $RPM_BUILD_ROOT/sbin
  62. cp ../common/qubes_serial_login $RPM_BUILD_ROOT/sbin
  63. mkdir -p $RPM_BUILD_ROOT/etc
  64. cp ../common/serial.conf $RPM_BUILD_ROOT/var/lib/qubes/
  65. mkdir -p $RPM_BUILD_ROOT/var/run/qubes
  66. mkdir -p $RPM_BUILD_ROOT/etc/xen/scripts
  67. cp ../common/vif-route-qubes $RPM_BUILD_ROOT/etc/xen/scripts
  68. %triggerin -- initscripts
  69. cp /var/lib/qubes/serial.conf /etc/init/serial.conf
  70. %post
  71. /usr/lib/qubes/qubes_fix_nm_conf.sh
  72. if [ "$1" != 1 ] ; then
  73. # do this whole %post thing only when updating for the first time...
  74. exit 0
  75. fi
  76. sed 's/^net.ipv4.ip_forward.*/net.ipv4.ip_forward = 1/' -i /etc/sysctl.conf
  77. usermod -L root
  78. if ! [ -f /var/lib/qubes/serial.orig ] ; then
  79. cp /etc/init/serial.conf /var/lib/qubes/serial.orig
  80. fi
  81. #echo "--> Disabling SELinux..."
  82. sed -e s/^SELINUX=.*$/SELINUX=disabled/ </etc/selinux/config >/etc/selinux/config.processed
  83. mv /etc/selinux/config.processed /etc/selinux/config
  84. setenforce 0 2>/dev/null
  85. #echo "--> Turning off unnecessary services..."
  86. # FIXME: perhaps there is more elegant way to do this?
  87. for f in /etc/init.d/*
  88. do
  89. srv=`basename $f`
  90. [ $srv = 'functions' ] && continue
  91. [ $srv = 'killall' ] && continue
  92. [ $srv = 'halt' ] && continue
  93. [ $srv = 'single' ] && continue
  94. chkconfig $srv off
  95. done
  96. #echo "--> Enabling essential services..."
  97. chkconfig iptables on
  98. chkconfig rsyslog on
  99. chkconfig haldaemon on
  100. chkconfig messagebus on
  101. chkconfig NetworkManager on
  102. chkconfig --add qubes_core || echo "WARNING: Cannot add service qubes_core!"
  103. chkconfig qubes_core on || echo "WARNING: Cannot enable service qubes_core!"
  104. # TODO: make this not display the silly message about security context...
  105. sed -i s/^id:.:initdefault:/id:3:initdefault:/ /etc/inittab
  106. # Remove most of the udev scripts to speed up the VM boot time
  107. # Just leave the xen* scripts, that are needed if this VM was
  108. # ever used as a net backend (e.g. as a VPN domain in the future)
  109. #echo "--> Removing unnecessary udev scripts..."
  110. mkdir -p /var/lib/qubes/removed-udev-scripts
  111. for f in /etc/udev/rules.d/*
  112. do
  113. if [ $(basename $f) == "xen-backend.rules" ] ; then
  114. continue
  115. fi
  116. if [ $(basename $f) == "xend.rules" ] ; then
  117. continue
  118. fi
  119. if [ $(basename $f) == "qubes.rules" ] ; then
  120. continue
  121. fi
  122. if [ $(basename $f) == "90-hal.rules" ] ; then
  123. continue
  124. fi
  125. mv $f /var/lib/qubes/removed-udev-scripts/
  126. done
  127. #rm -f /etc/mtab
  128. #echo "--> Removing HWADDR setting from /etc/sysconfig/network-scripts/ifcfg-eth0"
  129. #mv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.orig
  130. #grep -v HWADDR /etc/sysconfig/network-scripts/ifcfg-eth0.orig > /etc/sysconfig/network-scripts/ifcfg-eth0
  131. %preun
  132. if [ "$1" = 0 ] ; then
  133. # no more packages left
  134. chkconfig qubes_core off
  135. mv /var/lib/qubes/fstab.orig /etc/fstab
  136. mv /var/lib/qubes/removed-udev-scripts/* /etc/udev/rules.d/
  137. mv /var/lib/qubes/serial.orig /etc/init/serial.conf
  138. fi
  139. %clean
  140. rm -rf $RPM_BUILD_ROOT
  141. %files
  142. %defattr(-,root,root,-)
  143. /etc/fstab
  144. /etc/sysconfig/iptables
  145. /etc/init.d/qubes_core
  146. /var/lib/qubes
  147. /usr/lib/qubes/qubes_setup_dnat_to_ns
  148. /usr/lib/qubes/qubes_fix_nm_conf.sh
  149. /etc/dhclient.d/qubes_setup_dnat_to_ns.sh
  150. /etc/NetworkManager/dispatcher.d/qubes_nmhook
  151. /etc/yum.repos.d/qubes.repo
  152. /sbin/qubes_serial_login
  153. /etc/xen/scripts/vif-route-qubes
  154. %dir /var/run/qubes