qubes_core 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. #
  3. # chkconfig: 345 90 90
  4. # description: Executes Qubes core scripts at VM boot
  5. #
  6. # Source function library.
  7. . /etc/rc.d/init.d/functions
  8. start()
  9. {
  10. echo -n $"Executing Qubes Core scripts:"
  11. if ! [ -d /rw/home ] ; then
  12. echo
  13. echo "--> Virgin boot of the VM: Linking /home to /rw/home"
  14. mv /home /home.orig
  15. mkdir -p /rw/config
  16. mkdir -p /rw/home
  17. ln -s /rw/home/ /home
  18. # chcon --reference /home.orig /rw/home
  19. cp -a /home.orig/user /home
  20. touch /rw/config/rc.local
  21. rm -fr /home.orig
  22. touch /var/lib/qubes/first_boot_completed
  23. else
  24. mv /home /home.tmpl
  25. ln -s /rw/home/ /home
  26. fi
  27. if ! [ -x /usr/bin/xenstore-read ] ; then
  28. echo "ERROR: /usr/bin/xenstore-read not found!"
  29. exit 1
  30. fi
  31. name=$(/usr/bin/xenstore-read name)
  32. hostname $name
  33. vmtype=$(/usr/bin/xenstore-read qubes_vm_type)
  34. if [ $vmtype == 'NetVM' ] ; then
  35. # Setup gateway for all the VMs this netVM is serviceing...
  36. brctl addbr br0
  37. gateway=$(/usr/bin/xenstore-read qubes_netvm_gateway)
  38. netmask=$(/usr/bin/xenstore-read qubes_netvm_netmask)
  39. network=$(/usr/bin/xenstore-read qubes_netvm_network)
  40. ifconfig br0 $gateway netmask $netmask up
  41. echo "1" > /proc/sys/net/ipv4/ip_forward
  42. dnsmasq
  43. iptables -t nat -A POSTROUTING -s $network/$netmask -j MASQUERADE
  44. else
  45. ip=$(/usr/bin/xenstore-read qubes_ip)
  46. netmask=$(/usr/bin/xenstore-read qubes_netmask)
  47. gateway=$(/usr/bin/xenstore-read qubes_gateway)
  48. if [ x$ip != x ]; then
  49. /sbin/ifconfig eth0 $ip netmask $netmask up
  50. /sbin/route add default gw $gateway
  51. echo "nameserver $gateway" > /etc/resolv.conf
  52. fi
  53. fi
  54. [ -x /rw/config/rc.local ] && /rw/config/rc.local
  55. success
  56. echo ""
  57. return 0
  58. }
  59. stop()
  60. {
  61. return 0
  62. }
  63. case "$1" in
  64. start)
  65. start
  66. ;;
  67. stop)
  68. stop
  69. ;;
  70. *)
  71. echo $"Usage: $0 {start|stop}"
  72. exit 3
  73. ;;
  74. esac
  75. exit $RETVAL