Various changes relating to create Fedora (LXDE or KDE) Desktop 92/45492/11
authorDariusz Michaluk <d.michaluk@samsung.com>
Wed, 30 Sep 2015 09:01:49 +0000 (11:01 +0200)
committerJan Olszak <j.olszak@samsung.com>
Wed, 21 Oct 2015 11:06:04 +0000 (04:06 -0700)
[Bug/Feature]   Various changes relating to create Fedora Desktop
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, run server, run tests.

Change-Id: I847ab904012bea962b9961ad70a4e6bed9a69968

15 files changed:
packaging/vasum.spec
server/configs/daemon.conf.in
server/configs/templates/fedora-kde-demo.conf [new file with mode: 0644]
server/configs/templates/fedora-kde-demo.sh [new file with mode: 0755]
server/configs/templates/fedora-kde-wayland-demo.conf [new file with mode: 0644]
server/configs/templates/fedora-kde-wayland-demo.sh [new file with mode: 0755]
server/configs/templates/fedora-lxde-demo.conf [new file with mode: 0644]
server/configs/templates/fedora-lxde-demo.sh [new file with mode: 0755]
server/configs/templates/fedora-minimal.conf [moved from server/configs/templates/fedora.conf with 86% similarity]
server/configs/templates/fedora-minimal.sh [moved from server/configs/templates/fedora.sh with 97% similarity]
server/configs/templates/tizen-common-wayland.sh
server/configs/templates/ubuntu.sh
server/zones-manager-config.hpp
server/zones-manager.cpp
tests/unit_tests/configs/test-daemon.conf.in

index 546c782..447bbcf 100644 (file)
@@ -108,7 +108,7 @@ mkdir -p %{buildroot}/%{_datadir}/zones
 %if %{platform_type} == "TIZEN"
 ln -s tizen.conf %{buildroot}/etc/vasum/templates/default.conf
 %else
-ln -s fedora.conf %{buildroot}/etc/vasum/templates/default.conf
+ln -s fedora-minimal.conf %{buildroot}/etc/vasum/templates/default.conf
 %endif
 
 %clean
index 96d748f..d107343 100644 (file)
@@ -7,10 +7,11 @@
     "zoneTemplateDir" : "/etc/vasum/templates/",
     "runMountPointPrefix" : "/var/run/zones",
     "defaultId" : "",
-    "availableVTs" : [3, 4, 5, 6],
+    "hostVT" : 2,
+    "availableVTs" : [5, 6, 7, 8, 9],
     "inputConfig" : {"enabled" : false,
-                     "device" : "gpio_keys.6",
-                     "code" : 116,
+                     "device" : "DELL Dell USB Entry Keyboard",
+                     "code" : 1,
                      "numberOfEvents" : 2,
                      "timeWindowMs" : 500},
     "proxyCallRules" : []
diff --git a/server/configs/templates/fedora-kde-demo.conf b/server/configs/templates/fedora-kde-demo.conf
new file mode 100644 (file)
index 0000000..ca47a33
--- /dev/null
@@ -0,0 +1,19 @@
+{
+    "zoneTemplate" : "fedora-kde-demo.sh",
+    "initWithArgs" : [],
+    "requestedState" : "stopped",
+    "ipv4Gateway" : "",
+    "ipv4" : "",
+    "cpuQuotaForeground" : -1,
+    "cpuQuotaBackground" : -1,
+    "privilege" : 10,
+    "vt" : 0,
+    "shutdownTimeout" : 10,
+    "switchToDefaultAfterTimeout" : true,
+    "runMountPoint" : "~NAME~/run",
+    "provisions" : [],
+    "validLinkPrefixes" : [ "/tmp/",
+                            "/run/",
+                            "/opt/usr/data/",
+                            "/opt/usr/dbsapce/" ]
+}
diff --git a/server/configs/templates/fedora-kde-demo.sh b/server/configs/templates/fedora-kde-demo.sh
new file mode 100755 (executable)
index 0000000..971a102
--- /dev/null
@@ -0,0 +1,214 @@
+#!/bin/bash
+
+#  template script for creating Fedora LXC container
+#  This script is a wrapper for the lxc-fedora template
+#
+#  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Dariusz Michaluk  <d.michaluk@samsung.com>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+usage()
+{
+    cat <<EOF
+usage:
+    $1 -n|--name=<zone_name>
+        [-p|--path=<path>] [--rootfs=<rootfs>] [--vt=<vt>]
+        [--ipv4=<ipv4>] [--ipv4-gateway=<ipv4_gateway>] [-h|--help]
+Mandatory args:
+  -n,--name         zone name
+  -p,--path         path to zone config files
+  --rootfs          path to zone rootfs
+Optional args:
+  --vt              zone virtual terminal
+  --ipv4            zone IP address
+  --ipv4-gateway    zone gateway
+  -h,--help         print help
+EOF
+    return 0
+}
+
+options=$(getopt -o hp:n: -l help,rootfs:,path:,vt:,name:,ipv4:,ipv4-gateway: -- "$@")
+if [ $? -ne 0 ]; then
+    usage $(basename $0)
+    exit 1
+fi
+eval set -- "$options"
+
+while true
+do
+    case "$1" in
+        -h|--help)      usage $(basename $0) && exit 0;;
+        --rootfs)       rootfs=$2; shift 2;;
+        -p|--path)      path=$2; shift 2;;
+        --vt)           vt=$2; shift 2;;
+        -n|--name)      name=$2; shift 2;;
+        --ipv4)         ipv4=$2; shift 2;;
+        --ipv4-gateway) ipv4_gateway=$2; shift 2;;
+        --)             shift 1; break ;;
+        *)              break ;;
+    esac
+done
+
+if [ "$(id -u)" != "0" ]; then
+    echo "This script should be run as 'root'"
+    exit 1
+fi
+
+if [ -z $name ]; then
+    echo "Zone name must be given"
+    exit 1
+fi
+
+if [ -z "$path" ]; then
+    echo "'path' parameter is required"
+    exit 1
+fi
+
+if [ -z "$rootfs" ]; then
+    echo "'rootfs' parameter is required"
+    exit 1
+fi
+
+/usr/share/lxc/templates/lxc-fedora --name="$name" --path="$path" --rootfs="$rootfs"
+
+if [ "$vt" -gt "0" ]; then
+    echo "Setup Desktop"
+    chroot $rootfs yum -y --nogpgcheck groupinstall "KDE Plasma Workspaces"
+    chroot $rootfs yum -y --nogpgcheck groupinstall "Firefox Web Browser"
+    chroot $rootfs yum -y --nogpgcheck install openarena
+    chroot $rootfs yum -y --nogpgcheck install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
+                                               http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
+    chroot $rootfs yum -y --nogpgcheck install gstreamer1-libav gstreamer1-vaapi gstreamer1-plugins-{good,good-extras,ugly}
+    chroot $rootfs yum -y remove pulseaudio
+    chroot $rootfs passwd -d root
+
+    cat <<EOF >>${rootfs}/etc/X11/xorg.conf
+Section "ServerFlags"
+  Option "AutoAddDevices" "false"
+EndSection
+Section "InputDevice"
+  Identifier "event0"
+  Driver "evdev"
+  Option "Device" "/dev/input/event0"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event1"
+  Driver "evdev"
+  Option "Device" "/dev/input/event1"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event10"
+  Driver "evdev"
+  Option "Device" "/dev/input/event10"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event2"
+  Driver "evdev"
+  Option "Device" "/dev/input/event2"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event3"
+  Driver "evdev"
+  Option "Device" "/dev/input/event3"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event4"
+  Driver "evdev"
+  Option "Device" "/dev/input/event4"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event5"
+  Driver "evdev"
+  Option "Device" "/dev/input/event5"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event6"
+  Driver "evdev"
+  Option "Device" "/dev/input/event6"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event7"
+  Driver "evdev"
+  Option "Device" "/dev/input/event7"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event8"
+  Driver "evdev"
+  Option "Device" "/dev/input/event8"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event9"
+  Driver "evdev"
+  Option "Device" "/dev/input/event9"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "mice"
+  Driver "evdev"
+  Option "Device" "/dev/input/mice"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "mouse0"
+  Driver "evdev"
+  Option "Device" "/dev/input/mouse0"
+  Option "AutoServerLayout" "true"
+EndSection
+EOF
+
+    chroot  ${rootfs} rm -rf /etc/systemd/system/display-manager.service
+    cat <<EOF >${rootfs}/etc/systemd/system/display-manager.service
+[Unit]
+Description=Start Desktop
+
+[Service]
+ExecStartPre=/bin/mknod /dev/tty${vt} c 0x4 0x${vt}
+ExecStart=/bin/startx -- :0 vt${vt}
+
+[Install]
+WantedBy=graphical.target
+EOF
+
+    chroot $rootfs sed -i 's/configDir=${HOME}/export HOME=\/root; configDir=${HOME}/g' /bin/startkde
+    chroot $rootfs ln -sf /dev/null /etc/systemd/system/initial-setup-graphical.service
+    chroot $rootfs ln -sf /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target
+    chroot $rootfs mkdir -p /etc/systemd/system/graphical.target.wants
+    chroot $rootfs ln -sf /etc/systemd/system/display-manager.service /etc/systemd/system/graphical.target.wants/display-manager.service
+
+    cat <<EOF >>${path}/config
+lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
+lxc.mount.entry = /dev/input dev/input none bind,optional,create=dir
+lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
+### /dev/dri/*
+lxc.cgroup.devices.allow = c 226:* rwm
+### /dev/input/*
+lxc.cgroup.devices.allow = c 13:* rwm
+### /dev/snd/*
+lxc.cgroup.devices.allow = c 116:* rwm
+### /dev/tty*
+lxc.cgroup.devices.allow = c 4:* rwm
+EOF
+
+fi
diff --git a/server/configs/templates/fedora-kde-wayland-demo.conf b/server/configs/templates/fedora-kde-wayland-demo.conf
new file mode 100644 (file)
index 0000000..2131567
--- /dev/null
@@ -0,0 +1,19 @@
+{
+    "zoneTemplate" : "fedora-kde-wayland-demo.sh",
+    "initWithArgs" : [],
+    "requestedState" : "stopped",
+    "ipv4Gateway" : "",
+    "ipv4" : "",
+    "cpuQuotaForeground" : -1,
+    "cpuQuotaBackground" : -1,
+    "privilege" : 10,
+    "vt" : 0,
+    "shutdownTimeout" : 10,
+    "switchToDefaultAfterTimeout" : true,
+    "runMountPoint" : "~NAME~/run",
+    "provisions" : [],
+    "validLinkPrefixes" : [ "/tmp/",
+                            "/run/",
+                            "/opt/usr/data/",
+                            "/opt/usr/dbsapce/" ]
+}
diff --git a/server/configs/templates/fedora-kde-wayland-demo.sh b/server/configs/templates/fedora-kde-wayland-demo.sh
new file mode 100755 (executable)
index 0000000..f915a9f
--- /dev/null
@@ -0,0 +1,217 @@
+#!/bin/bash
+
+#  template script for creating Fedora LXC container
+#  This script is a wrapper for the lxc-fedora template
+#
+#  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Dariusz Michaluk  <d.michaluk@samsung.com>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+usage()
+{
+    cat <<EOF
+usage:
+    $1 -n|--name=<zone_name>
+        [-p|--path=<path>] [--rootfs=<rootfs>] [--vt=<vt>]
+        [--ipv4=<ipv4>] [--ipv4-gateway=<ipv4_gateway>] [-h|--help]
+Mandatory args:
+  -n,--name         zone name
+  -p,--path         path to zone config files
+  --rootfs          path to zone rootfs
+Optional args:
+  --vt              zone virtual terminal
+  --ipv4            zone IP address
+  --ipv4-gateway    zone gateway
+  -h,--help         print help
+EOF
+    return 0
+}
+
+options=$(getopt -o hp:n: -l help,rootfs:,path:,vt:,name:,ipv4:,ipv4-gateway: -- "$@")
+if [ $? -ne 0 ]; then
+    usage $(basename $0)
+    exit 1
+fi
+eval set -- "$options"
+
+while true
+do
+    case "$1" in
+        -h|--help)      usage $(basename $0) && exit 0;;
+        --rootfs)       rootfs=$2; shift 2;;
+        -p|--path)      path=$2; shift 2;;
+        --vt)           vt=$2; shift 2;;
+        -n|--name)      name=$2; shift 2;;
+        --ipv4)         ipv4=$2; shift 2;;
+        --ipv4-gateway) ipv4_gateway=$2; shift 2;;
+        --)             shift 1; break ;;
+        *)              break ;;
+    esac
+done
+
+if [ "$(id -u)" != "0" ]; then
+    echo "This script should be run as 'root'"
+    exit 1
+fi
+
+if [ -z $name ]; then
+    echo "Zone name must be given"
+    exit 1
+fi
+
+if [ -z "$path" ]; then
+    echo "'path' parameter is required"
+    exit 1
+fi
+
+if [ -z "$rootfs" ]; then
+    echo "'rootfs' parameter is required"
+    exit 1
+fi
+
+/usr/share/lxc/templates/lxc-fedora --name="$name" --path="$path" --rootfs="$rootfs"
+
+if [ "$vt" -gt "0" ]; then
+    echo "Setup Desktop"
+    chroot $rootfs yum -y --nogpgcheck groupinstall "KDE Plasma Workspaces"
+    chroot $rootfs yum -y --nogpgcheck install kwin-wayland qt5-qtwayland xorg-x11-server-Xwayland
+    chroot $rootfs yum -y --nogpgcheck groupinstall "Firefox Web Browser"
+    chroot $rootfs yum -y remove pulseaudio
+    chroot $rootfs passwd -d root
+
+    cat <<EOF >>${rootfs}/etc/X11/xorg.conf
+Section "ServerFlags"
+  Option "AutoAddDevices" "false"
+EndSection
+Section "InputDevice"
+  Identifier "event0"
+  Driver "evdev"
+  Option "Device" "/dev/input/event0"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event1"
+  Driver "evdev"
+  Option "Device" "/dev/input/event1"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event10"
+  Driver "evdev"
+  Option "Device" "/dev/input/event10"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event2"
+  Driver "evdev"
+  Option "Device" "/dev/input/event2"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event3"
+  Driver "evdev"
+  Option "Device" "/dev/input/event3"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event4"
+  Driver "evdev"
+  Option "Device" "/dev/input/event4"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event5"
+  Driver "evdev"
+  Option "Device" "/dev/input/event5"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event6"
+  Driver "evdev"
+  Option "Device" "/dev/input/event6"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event7"
+  Driver "evdev"
+  Option "Device" "/dev/input/event7"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event8"
+  Driver "evdev"
+  Option "Device" "/dev/input/event8"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event9"
+  Driver "evdev"
+  Option "Device" "/dev/input/event9"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "mice"
+  Driver "evdev"
+  Option "Device" "/dev/input/mice"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "mouse0"
+  Driver "evdev"
+  Option "Device" "/dev/input/mouse0"
+  Option "AutoServerLayout" "true"
+EndSection
+EOF
+
+    chroot  ${rootfs} rm -rf /etc/systemd/system/display-manager.service
+    cat <<EOF >${rootfs}/etc/systemd/system/display-manager.service
+[Unit]
+Description=Start Desktop
+
+[Service]
+ExecStartPre=/bin/mknod /dev/tty${vt} c 0x4 0x${vt}
+ExecStart=/bin/startx -- :0 vt${vt}
+
+[Install]
+WantedBy=graphical.target
+EOF
+
+    chroot $rootfs rm -rf /bin/startkde
+    chroot $rootfs cp /bin/startplasmacompositor /bin/startkde
+    chroot $rootfs sed -i 's/--libinput/--width=1920 --height=1080 --libinput/g' /bin/startkde
+    chroot $rootfs sed -i 's/\/usr\/libexec\/startplasma/\/bin\/plasmashell/g' /bin/startkde
+    chroot $rootfs sed -i 's/configDir=${HOME}/export XDG_RUNTIME_DIR=\/tmp; configDir=${HOME}/g' /bin/startkde
+    chroot $rootfs sed -i 's/X-KDE-Kded-autoload=true/X-KDE-Kded-autoload=false/g' /usr/share/kservices5/kded/*.desktop
+
+    chroot $rootfs ln -sf /dev/null /etc/systemd/system/initial-setup-graphical.service
+    chroot $rootfs ln -sf /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target
+    chroot $rootfs mkdir -p /etc/systemd/system/graphical.target.wants
+    chroot $rootfs ln -sf /etc/systemd/system/display-manager.service /etc/systemd/system/graphical.target.wants/display-manager.service
+
+    cat <<EOF >>${path}/config
+lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
+lxc.mount.entry = /dev/input dev/input none bind,optional,create=dir
+lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
+### /dev/dri/*
+lxc.cgroup.devices.allow = c 226:* rwm
+### /dev/input/*
+lxc.cgroup.devices.allow = c 13:* rwm
+### /dev/snd/*
+lxc.cgroup.devices.allow = c 116:* rwm
+### /dev/tty*
+lxc.cgroup.devices.allow = c 4:* rwm
+EOF
+
+fi
diff --git a/server/configs/templates/fedora-lxde-demo.conf b/server/configs/templates/fedora-lxde-demo.conf
new file mode 100644 (file)
index 0000000..847bb4d
--- /dev/null
@@ -0,0 +1,19 @@
+{
+    "zoneTemplate" : "fedora-lxde-demo.sh",
+    "initWithArgs" : [],
+    "requestedState" : "stopped",
+    "ipv4Gateway" : "",
+    "ipv4" : "",
+    "cpuQuotaForeground" : -1,
+    "cpuQuotaBackground" : -1,
+    "privilege" : 10,
+    "vt" : 0,
+    "shutdownTimeout" : 10,
+    "switchToDefaultAfterTimeout" : true,
+    "runMountPoint" : "~NAME~/run",
+    "provisions" : [],
+    "validLinkPrefixes" : [ "/tmp/",
+                            "/run/",
+                            "/opt/usr/data/",
+                            "/opt/usr/dbsapce/" ]
+}
diff --git a/server/configs/templates/fedora-lxde-demo.sh b/server/configs/templates/fedora-lxde-demo.sh
new file mode 100755 (executable)
index 0000000..7bd4e02
--- /dev/null
@@ -0,0 +1,213 @@
+#!/bin/bash
+
+#  template script for creating Fedora LXC container
+#  This script is a wrapper for the lxc-fedora template
+#
+#  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Dariusz Michaluk  <d.michaluk@samsung.com>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+usage()
+{
+    cat <<EOF
+usage:
+    $1 -n|--name=<zone_name>
+        [-p|--path=<path>] [--rootfs=<rootfs>] [--vt=<vt>]
+        [--ipv4=<ipv4>] [--ipv4-gateway=<ipv4_gateway>] [-h|--help]
+Mandatory args:
+  -n,--name         zone name
+  -p,--path         path to zone config files
+  --rootfs          path to zone rootfs
+Optional args:
+  --vt              zone virtual terminal
+  --ipv4            zone IP address
+  --ipv4-gateway    zone gateway
+  -h,--help         print help
+EOF
+    return 0
+}
+
+options=$(getopt -o hp:n: -l help,rootfs:,path:,vt:,name:,ipv4:,ipv4-gateway: -- "$@")
+if [ $? -ne 0 ]; then
+    usage $(basename $0)
+    exit 1
+fi
+eval set -- "$options"
+
+while true
+do
+    case "$1" in
+        -h|--help)      usage $(basename $0) && exit 0;;
+        --rootfs)       rootfs=$2; shift 2;;
+        -p|--path)      path=$2; shift 2;;
+        --vt)           vt=$2; shift 2;;
+        -n|--name)      name=$2; shift 2;;
+        --ipv4)         ipv4=$2; shift 2;;
+        --ipv4-gateway) ipv4_gateway=$2; shift 2;;
+        --)             shift 1; break ;;
+        *)              break ;;
+    esac
+done
+
+if [ "$(id -u)" != "0" ]; then
+    echo "This script should be run as 'root'"
+    exit 1
+fi
+
+if [ -z $name ]; then
+    echo "Zone name must be given"
+    exit 1
+fi
+
+if [ -z "$path" ]; then
+    echo "'path' parameter is required"
+    exit 1
+fi
+
+if [ -z "$rootfs" ]; then
+    echo "'rootfs' parameter is required"
+    exit 1
+fi
+
+/usr/share/lxc/templates/lxc-fedora --name="$name" --path="$path" --rootfs="$rootfs"
+
+if [ "$vt" -gt "0" ]; then
+    echo "Setup Desktop"
+    chroot $rootfs yum -y --nogpgcheck groupinstall "LXDE Desktop"
+    chroot $rootfs yum -y --nogpgcheck groupinstall "Firefox Web Browser"
+    chroot $rootfs yum -y --nogpgcheck install openarena
+    chroot $rootfs yum -y --nogpgcheck install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
+                                               http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
+    chroot $rootfs yum -y --nogpgcheck install gstreamer1-libav gstreamer1-vaapi gstreamer1-plugins-{good,good-extras,ugly}
+    chroot $rootfs yum -y remove pulseaudio
+    chroot $rootfs passwd -d root
+
+    cat <<EOF >>${rootfs}/etc/X11/xorg.conf
+Section "ServerFlags"
+  Option "AutoAddDevices" "false"
+EndSection
+Section "InputDevice"
+  Identifier "event0"
+  Driver "evdev"
+  Option "Device" "/dev/input/event0"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event1"
+  Driver "evdev"
+  Option "Device" "/dev/input/event1"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event10"
+  Driver "evdev"
+  Option "Device" "/dev/input/event10"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event2"
+  Driver "evdev"
+  Option "Device" "/dev/input/event2"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event3"
+  Driver "evdev"
+  Option "Device" "/dev/input/event3"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event4"
+  Driver "evdev"
+  Option "Device" "/dev/input/event4"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event5"
+  Driver "evdev"
+  Option "Device" "/dev/input/event5"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event6"
+  Driver "evdev"
+  Option "Device" "/dev/input/event6"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event7"
+  Driver "evdev"
+  Option "Device" "/dev/input/event7"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event8"
+  Driver "evdev"
+  Option "Device" "/dev/input/event8"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "event9"
+  Driver "evdev"
+  Option "Device" "/dev/input/event9"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "mice"
+  Driver "evdev"
+  Option "Device" "/dev/input/mice"
+  Option "AutoServerLayout" "true"
+EndSection
+Section "InputDevice"
+  Identifier "mouse0"
+  Driver "evdev"
+  Option "Device" "/dev/input/mouse0"
+  Option "AutoServerLayout" "true"
+EndSection
+EOF
+
+    chroot  ${rootfs} rm -rf /etc/systemd/system/display-manager.service
+    cat <<EOF >${rootfs}/etc/systemd/system/display-manager.service
+[Unit]
+Description=Start Desktop
+
+[Service]
+ExecStartPre=/bin/mknod /dev/tty${vt} c 0x4 0x${vt}
+ExecStart=/bin/startx -- :0 vt${vt}
+
+[Install]
+WantedBy=graphical.target
+EOF
+
+    chroot $rootfs ln -sf /dev/null /etc/systemd/system/initial-setup-graphical.service
+    chroot $rootfs ln -sf /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target
+    chroot $rootfs mkdir -p /etc/systemd/system/graphical.target.wants
+    chroot $rootfs ln -sf /etc/systemd/system/display-manager.service /etc/systemd/system/graphical.target.wants/display-manager.service
+
+    cat <<EOF >>${path}/config
+lxc.mount.entry = /dev/dri dev/dri none bind,optional,create=dir
+lxc.mount.entry = /dev/input dev/input none bind,optional,create=dir
+lxc.mount.entry = /dev/snd dev/snd none bind,optional,create=dir
+### /dev/dri/*
+lxc.cgroup.devices.allow = c 226:* rwm
+### /dev/input/*
+lxc.cgroup.devices.allow = c 13:* rwm
+### /dev/snd/*
+lxc.cgroup.devices.allow = c 116:* rwm
+### /dev/tty*
+lxc.cgroup.devices.allow = c 4:* rwm
+EOF
+
+fi
similarity index 86%
rename from server/configs/templates/fedora.conf
rename to server/configs/templates/fedora-minimal.conf
index 12e0d2a..e8271ec 100644 (file)
@@ -1,11 +1,11 @@
 {
-    "zoneTemplate" : "fedora.sh",
+    "zoneTemplate" : "fedora-minimal.sh",
     "initWithArgs" : [],
     "requestedState" : "stopped",
     "ipv4Gateway" : "",
     "ipv4" : "",
     "cpuQuotaForeground" : -1,
-    "cpuQuotaBackground" : 1000,
+    "cpuQuotaBackground" : -1,
     "privilege" : 10,
     "vt" : -1,
     "shutdownTimeout" : 10,
similarity index 97%
rename from server/configs/templates/fedora.sh
rename to server/configs/templates/fedora-minimal.sh
index dc4db3b..604b08c 100755 (executable)
@@ -49,7 +49,7 @@ eval set -- "$options"
 while true
 do
     case "$1" in
-        -h|--help)      usage $0 && exit 0;;
+        -h|--help)      usage $(basename $0) && exit 0;;
         --rootfs)       rootfs=$2; shift 2;;
         -p|--path)      path=$2; shift 2;;
         --vt)           vt=$2; shift 2;;
index 05cca6d..4f7c407 100755 (executable)
@@ -48,7 +48,7 @@ eval set -- "$options"
 while true
 do
     case "$1" in
-        -h|--help)      usage $0 && exit 0;;
+        -h|--help)      usage $(basename $0) && exit 0;;
         --rootfs)       rootfs=$2; shift 2;;
         -p|--path)      path=$2; shift 2;;
         --vt)           vt=$2; shift 2;;
index edcf649..1253b4c 100755 (executable)
@@ -49,7 +49,7 @@ eval set -- "$options"
 while true
 do
     case "$1" in
-        -h|--help)      usage $0 && exit 0;;
+        -h|--help)      usage $(basename $0) && exit 0;;
         --rootfs)       rootfs=$2; shift 2;;
         -p|--path)      path=$2; shift 2;;
         --vt)           vt=$2; shift 2;;
index e300e75..cd7d4c0 100644 (file)
@@ -65,6 +65,11 @@ struct ZonesManagerConfig {
     std::string zoneTemplateDir;
 
     /**
+     * Host VT
+     */
+    int hostVT;
+
+    /**
      * VTs available for zones
      */
     std::vector<int> availableVTs;
@@ -91,6 +96,7 @@ struct ZonesManagerConfig {
         cleanUpZonesPath,
         zoneImagePath,
         zoneTemplateDir,
+        hostVT,
         availableVTs,
         inputConfig,
         runMountPointPrefix,
index baf3ed1..7a2bf11 100644 (file)
@@ -37,6 +37,7 @@
 #include "utils/fs.hpp"
 #include "utils/img.hpp"
 #include "utils/environment.hpp"
+#include "utils/vt.hpp"
 #include "api/messages.hpp"
 
 #include <boost/filesystem.hpp>
@@ -392,8 +393,7 @@ void ZonesManager::focusInternal(Zones::iterator iter)
     if (iter == mZones.end()) {
         if (!mActiveZoneId.empty()) {
             LOGI("Focus to: host");
-            // give back the focus to the host
-            // TODO switch to host vt
+            utils::activateVT(mConfig.hostVT);
             mActiveZoneId.clear();
         }
         return;
@@ -519,10 +519,7 @@ ZonesManager::Zones::iterator ZonesManager::getRunningForegroundZoneIterator()
     }
     auto iter = findZone(mActiveZoneId);
     if (!get(iter).isRunning()) {
-        // Can zone change its state by itself?
-        // Maybe when it is shut down by itself? TODO check it
         LOGW("Active zone " << mActiveZoneId << " is not running any more!");
-        assert(false);
         return mZones.end();
     }
     return iter;
@@ -1149,21 +1146,23 @@ void ZonesManager::generateNewConfig(const std::string& id,
                                                        ZONE_NAME_REGEX,
                                                        id);
 
-    if (dynamicConfig.vt >= 0 && !dynamicConfig.ipv4Gateway.empty() && !dynamicConfig.ipv4.empty()) {
+    if (dynamicConfig.vt >= 0) {
         // generate first free VT number
         const int freeVT = getVTForNewZone();
         LOGD("VT number: " << freeVT);
         dynamicConfig.vt = freeVT;
 
-        // generate third IP octet for network config
-        std::string thirdOctetStr = std::to_string(ZONE_IP_BASE_THIRD_OCTET + freeVT);
-        LOGD("IP third octet: " << thirdOctetStr);
-        dynamicConfig.ipv4Gateway = boost::regex_replace(dynamicConfig.ipv4Gateway,
-                                                         ZONE_IP_THIRD_OCTET_REGEX,
-                                                         thirdOctetStr);
-        dynamicConfig.ipv4 = boost::regex_replace(dynamicConfig.ipv4,
-                                                  ZONE_IP_THIRD_OCTET_REGEX,
-                                                  thirdOctetStr);
+        if (!dynamicConfig.ipv4Gateway.empty() && !dynamicConfig.ipv4.empty()) {
+            // generate third IP octet for network config
+            std::string thirdOctetStr = std::to_string(ZONE_IP_BASE_THIRD_OCTET + freeVT);
+            LOGD("IP third octet: " << thirdOctetStr);
+            dynamicConfig.ipv4Gateway = boost::regex_replace(dynamicConfig.ipv4Gateway,
+                                                             ZONE_IP_THIRD_OCTET_REGEX,
+                                                             thirdOctetStr);
+            dynamicConfig.ipv4 = boost::regex_replace(dynamicConfig.ipv4,
+                                                      ZONE_IP_THIRD_OCTET_REGEX,
+                                                      thirdOctetStr);
+        }
     }
 
     // save dynamic config
index 66ca69f..2ed411b 100644 (file)
@@ -7,6 +7,7 @@
     "zoneTemplateDir" : "@VSM_TEST_CONFIG_INSTALL_DIR@/templates/",
     "runMountPointPrefix" : "",
     "defaultId" : "",
+    "hostVT" : 2,
     "availableVTs" : [],
     "inputConfig" : {"enabled" : false,
                      "device" : "gpio-keys.4",