qubes_core 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 ! [ -x /usr/bin/xenstore-read ] ; then
  12. echo "ERROR: /usr/bin/xenstore-read not found!"
  13. exit 1
  14. fi
  15. # Set permissions to /proc/xen/xenbus, so normal user can use xenstore-read
  16. chmod 666 /proc/xen/xenbus
  17. mkdir -p /var/run/xen-hotplug
  18. name=$(/usr/bin/xenstore-read name)
  19. if ! [ -f /etc/this_is_dvm ] ; then
  20. # we don't want to set hostname for DispVM
  21. # because it makes some of the pre-created dotfiles invalid (e.g. .kde/cache-<hostname>)
  22. # (let's be frank: nobody's gonna use xterm on DispVM)
  23. hostname $name
  24. sed -i "s/^\(127\.0\.0\.1 .*\) \($name \)\?\(.*\)/\1\2 $name/" /etc/hosts
  25. fi
  26. timezone=`/usr/bin/xenstore-read qubes-timezone 2> /dev/null`
  27. if [ -n "$timezone" ]; then
  28. ln -f /usr/share/zoneinfo/$timezone /etc/localtime
  29. echo "# Clock configuration autogenerated based on Qubes dom0 settings" > /etc/sysconfig/clock
  30. echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
  31. fi
  32. yum_proxy_setup=$(/usr/bin/xenstore-read qubes-service/yum-proxy-setup 2> /dev/null)
  33. type=$(/usr/bin/xenstore-read qubes_vm_type)
  34. if [ "$yum_proxy_setup" != "0" ] || [ -z "$yum_proxy_setup" -a "$type" == "TemplateVM" ]; then
  35. echo proxy=http://10.137.255.254:8082/ > /etc/yum.conf.d/qubes-proxy.conf
  36. else
  37. echo > /etc/yum.conf.d/qubes-proxy.conf
  38. fi
  39. # Set IP address again (besides action in udev rules); this is needed by
  40. # DispVM (to override DispVM-template IP) and in case when qubes_ip was
  41. # called by udev before loading evtchn kernel module - in which case
  42. # xenstore-read fails
  43. INTERFACE=eth0 /usr/lib/qubes/setup_ip
  44. mkdir -p /var/run/qubes
  45. if [ -e /dev/xvdb ] ; then
  46. mount /rw
  47. if ! [ -d /rw/home ] ; then
  48. echo
  49. echo "--> Virgin boot of the VM: Linking /home to /rw/home"
  50. mkdir -p /rw/config
  51. touch /rw/config/rc.local
  52. mkdir -p /rw/home
  53. cp -a /home.orig/user /home
  54. mkdir -p /rw/usrlocal
  55. cp -a /usr/local.orig/* /usr/local
  56. touch /var/lib/qubes/first_boot_completed
  57. fi
  58. fi
  59. /usr/lib/qubes/qrexec_agent 2>/var/log/qubes/qrexec_agent.log &
  60. [ -x /rw/config/rc.local ] && /rw/config/rc.local
  61. if ! [ -f /home/user/.gnome2/nautilus-scripts/.scripts_created ] ; then
  62. echo "Creating symlinks for nautilus actions..."
  63. su user -c 'mkdir -p /home/user/.gnome2/nautilus-scripts'
  64. su user -c 'ln -s /usr/lib/qubes/qvm-copy-to-vm.gnome /home/user/.gnome2/nautilus-scripts/"Copy to other AppVM"'
  65. su user -c 'ln -s /usr/bin/qvm-open-in-dvm /home/user/.gnome2/nautilus-scripts/"Open in DisposableVM"'
  66. su user -c 'touch /home/user/.gnome2/nautilus-scripts/.scripts_created'
  67. fi
  68. if ! [ -f /home/user/.gnome2/nautilus-scripts/.scripts_created2 ] ; then
  69. # as we have recently renamed tools, the symlinks would need to be fixed for older templates
  70. su user -c 'ln -sf /usr/lib/qubes/qvm-copy-to-vm.gnome /home/user/.gnome2/nautilus-scripts/"Copy to other AppVM"'
  71. su user -c 'ln -sf /usr/bin/qvm-open-in-dvm /home/user/.gnome2/nautilus-scripts/"Open in DisposableVM"'
  72. su user -c 'touch /home/user/.gnome2/nautilus-scripts/.scripts_created2'
  73. fi
  74. success
  75. echo ""
  76. start_ntpd=$(/usr/bin/xenstore-read qubes-service/ntpd 2> /dev/null)
  77. if [ "$start_ntpd" == "1" ]; then
  78. /sbin/service ntpd start
  79. fi
  80. return 0
  81. }
  82. stop()
  83. {
  84. su -c 'mkdir -p /home_volatile/user/.local/share/applications' user
  85. su -c 'cp -a /usr/share/applications/defaults.list /home_volatile/user/.local/share/applications/' user
  86. if [ -r '/home/user/.local/share/applications/defaults.list' ]; then
  87. su -c 'cat /home/user/.local/share/applications/defaults.list >> /home_volatile/user/.local/share/applications/defaults.list' user
  88. fi
  89. return 0
  90. }
  91. case "$1" in
  92. start)
  93. start
  94. ;;
  95. stop)
  96. stop
  97. ;;
  98. *)
  99. echo $"Usage: $0 {start|stop}"
  100. exit 3
  101. ;;
  102. esac
  103. exit $RETVAL