ROBOX:Upload robox scripts for IEC release 6
[iec.git] / src / use_cases / robox / setupenv / arm64_env_setup.sh
1 #!/bin/bash
2
3 set -e
4
5 ROBOX_SRC=download/robox
6
7 stage1(){
8     echo "Enable source"
9     sudo sed -i "s/^# deb-src/ deb-src/g" /etc/apt/sources.list
10     echo "update"
11     sudo apt update
12
13     echo "Install dependency"
14     sudo apt install -y dpkg libncurses5-dev libncursesw5-dev libssl-dev cmake cmake-data debhelper dbus google-mock libboost-dev libboost-filesystem-dev libboost-log-dev libboost-iostreams-dev libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev libcap-dev libsystemd-dev libdbus-1-dev libegl1-mesa-dev  libgles2-mesa-dev libglib2.0-dev libglm-dev libgtest-dev liblxc1 libproperties-cpp-dev libprotobuf-dev libsdl2-dev libsdl2-image-dev lxc-dev pkg-config protobuf-compiler
15
16 #TODO compare "Ubuntu 18.04.1 LTS \n \l" in /etc/issue
17     sudo apt install -y libboost-filesystem1.62.0 libboost-system1.62.0 docker.io dkms libboost-iostreams1.62.0
18
19     sudo apt install -y build-essential
20     sudo apt install -y mesa-common-dev
21
22     echo "install libprocess-cpp3 and libdbus(and dev)"
23     #TODO compare "Ubuntu 18.04.1 LTS \n \l" in /etc/issue
24     wget http://launchpadlibrarian.net/291649807/libprocess-cpp3_3.0.1-0ubuntu5_arm64.deb
25     wget http://launchpadlibrarian.net/291804794/libdbus-cpp5_5.0.0+16.10.20160809-0ubuntu2_arm64.deb
26     wget http://launchpadlibrarian.net/291804785/libdbus-cpp-dev_5.0.0+16.10.20160809-0ubuntu2_arm64.deb
27     sudo dpkg -i libprocess-cpp3_3.0.1-0ubuntu5_arm64.deb
28     sudo dpkg -i libdbus-cpp5_5.0.0+16.10.20160809-0ubuntu2_arm64.deb
29     sudo dpkg -i libdbus-cpp-dev_5.0.0+16.10.20160809-0ubuntu2_arm64.deb
30     rm libprocess-cpp3_3.0.1-0ubuntu5_arm64.deb
31     rm libdbus-cpp5_5.0.0+16.10.20160809-0ubuntu2_arm64.deb
32     rm libdbus-cpp-dev_5.0.0+16.10.20160809-0ubuntu2_arm64.deb
33
34     echo "Check docker storage driver type"
35     STORAGE_DRV=`sudo docker info |grep Storage | sed "s/\ //g" | cut -d : -f 2`
36     if [ "$STORAGE_DRV" == "overlay2" ] || [ "$STORAGE_DRV" == "overlay" ]; then
37        echo "Docker Storage driver ok"
38     else
39        echo "ERROR: docker storage driver should be overlay2"
40        exit
41     fi
42
43     echo install desktop
44     sudo apt install -y xfce4  xfce4-* xrdp
45
46     echo "setup remote desktop"
47     echo "enable remote desktop for current user"
48     echo "xfce4-session" > ~/.xsession
49     echo "enable remote desktop for root"
50     sudo su -c 'echo "xfce4-session" > /root/.xsession'
51     sudo /etc/init.d/xrdp restart
52
53     echo "Install the current latest kernel in ubuntu 18.04.1"
54     #sudo apt install -y linux-generic=4.15.0.163.152
55     echo "Please reboot to continue, or the location of kernel module might be wrong!"
56     exit
57 }
58
59 stage2() {
60     echo "Install kernel source"
61     sudo apt install linux-source-4.15.0
62
63     echo "downloading robox"
64     if [ -d "$ROBOX_SRC" ]; then
65        pushd $ROBOX_SRC
66        COMMIT=`git log --oneline -n1  e74a3c6cb1be683d31f742b2c8344d0e28577536`
67        if [ "$COMMIT" != "" ]; then
68          echo "robox exist, skip git clone"
69        else
70          cd ..
71          rm -rf robox
72          git clone https://github.com/kunpengcompute/robox.git
73         cd robox
74       fi
75     else
76       mkdir -p download
77       pushd download
78       git clone https://github.com/kunpengcompute/robox.git
79       cd robox
80     fi
81     echo "checkout to tested commit"
82     git checkout -f e74a3c6cb1be683d31f742b2c8344d0e28577536
83     popd
84
85     echo "build anbox module"
86     pushd $ROBOX_SRC/kernel/robox-modules/
87     sudo mkdir -p /etc/modules-load.d/
88     sudo cp -p anbox.conf /etc/modules-load.d/
89     sudo cp -p 99-anbox.rules /lib/udev/rules.d/
90     sudo cp -prT ashmem /usr/src/anbox-ashmem-1
91     sudo cp -prT binder /usr/src/anbox-binder-1
92     sudo dkms install anbox-ashmem/1
93     sudo dkms install anbox-binder/1
94     popd
95
96     echo "Install ashmem and binder modules"
97     sudo modprobe ashmem_linux
98     sudo rmmod binder_linux || true; sudo modprobe binder_linux num_devices=254
99     echo "check if module insert correctly"
100     lsmod|grep -e ashmem_linux -e binder_linux
101     sudo chmod 777 /dev/ashmem /dev/binder*
102     echo "Press any key to continue"
103     read
104
105     echo "build robox"
106     mkdir -p download/robox/build
107     pushd download/robox/build
108     cmake ..
109     echo "TODO: make it to idempotent"
110     sudo sed -i "s/^\#ifndef GLM_ENABLE_EXPERIMENTAL/\#define GLM_ENABLE_EXPERIMENTAL\n\#ifndef GLM_ENABLE_EXPERIMENTAL/g" /usr/include/glm/gtx/transform.hpp
111     make -j5
112     sudo make install
113     popd
114
115     echo "Enable graphics"
116     sudo apt install -y xfce4 mesa-utils x11vnc vainfo
117
118     echo "STEP: Installation mesa. mesa is a OpenGL library"
119     echo "### Clone mesa ###"
120     mkdir -p sources
121     pushd sources
122     if [ ! -d mesa ]; then
123        sudo apt-get install -y apt-transport-https ca-certificates
124        sudo update-ca-certificates
125        git clone https://anongit.freedesktop.org/git/mesa/mesa.git
126     fi
127     cd mesa
128     git checkout -f mesa-19.0.8
129
130     echo "### Build mesa ###"
131     sudo apt build-dep -y mesa
132     sudo apt install -y libomxil-bellagio-dev libva-dev  llvm-7  llvm-7-dev python-mako
133     ./autogen.sh  --enable-texture-float --with-gallium-drivers=radeonsi,swrast --with-dri-drivers=radeon,swrast --with-platforms=drm,x11 --enable-glx-tls --enable-shared-glapi --enable-dri3 --enable-lmsensors  --enable-gbm --enable-xa --enable-osmesa  --enable-vdpau --enable-nine --enable-omx-bellagio --enable-va --with-llvm-prefix=/usr/lib/llvm-7 --enable-llvm --target=aarch64-linux-gnu CFLAGS="-fsigned-char -O2" CPPFLAGS="-fsigned-char -O2" CXXFLAGS="-fsigned-char -O2" --enable-autotools
134     make -j5 && sudo make install
135     echo "TODO: make it to idempotent"
136     sudo sed -i "s/^/\/usr\/local\/lib\n/g" /etc/ld.so.conf
137     sudo ldconfig
138     popd
139 }
140
141 setup_android_image() {
142     echo "Downloading Android image"
143     ANDROID_IMG=android.img
144     ANDROID_MD5=`md5sum $ANDROID_IMG | cut -d \  -f 1`
145     if [ "$ANDROID_MD5" = "fc44fce9ddfcdca737200468bcb5615e" ]; then
146        echo "Huawei Android image already exist, skip download"
147     elif [ -f images/android.img ]; then
148        echo "Another Android image exist, skip download"
149        ANDROID_IMG=android.img
150     else
151        mkdir -p images
152        wget https://mirrors.huaweicloud.com/kunpeng/archive/kunpeng_solution/native/android.img -o images/android.img
153        echo "Downloaded"
154     fi
155
156     mkdir -p images/android
157     sudo mount images/$ANDROID_IMG images/android
158     pushd images/android
159     sudo tar --numeric-owner -cf - . | sudo docker import - android:robox
160     popd
161     sudo umount images/android
162 }
163
164 configure_gpu(){
165     sudo cp -p script/xorg.conf /etc/X11
166     IDS=`lspci |grep "AMD.*7100" | cut -d \  -f 1 | sed "s/[:.]/ /g"`
167     BUSID= ;for id in $IDS; do BUSID+=`echo -n "$((16#$id)) "`; done
168     BUSID=`echo $BUSID | sed "s/ /:/g" | sed "s/ $//g"`
169     sudo sed -i "s/BusID \"pci:.*:.*:.*\"\ *$/BusID \"pci:$BUSID\"/g" /etc/X11/xorg.conf
170 }
171
172 echo "SHOULD Allow apt installer restart service without prompt"
173 stage1
174 stage2
175 setup_android_image
176 configure_gpu