1#!/bin/bash 2 3set -e 4set -x 5 6echo "Setup docker host" 7 8SCRIPTPATH="$( 9 cd "$(dirname "$0")" 10 pwd -P 11)" 12cd $SCRIPTPATH 13 14JENKINS_AGENT_VERSION=4.6 15 16dpkg --add-architecture i386 17apt-get update 18apt-get install -y apt-utils software-properties-common apt-transport-https sudo curl wget zip unzip 19apt-get update 20apt-get dist-upgrade -y 21 22wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null 23wget -qO- https://deb.nodesource.com/setup_12.x | bash - 24wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - 25wget -qO- https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - 26 27apt-add-repository -y 'deb https://apt.kitware.com/ubuntu/ xenial main' 28echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list 29wget -qO- https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_unstable.list >/etc/apt/sources.list.d/dart_unstable.list 30 31./llvm.sh 10 32./llvm-update-alternatives.sh 10 1000 33 34apt-get update 35 36echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections 37 38apt-get install -y \ 39 autopoint \ 40 binutils \ 41 bison \ 42 build-essential \ 43 ca-certificates \ 44 cmake \ 45 dart \ 46 debhelper \ 47 debianutils \ 48 devscripts \ 49 flex \ 50 g++ \ 51 gcc \ 52 git \ 53 gnupg \ 54 gperf \ 55 intltool \ 56 lib32z1 \ 57 libc6-dbg \ 58 libcunit1-dev \ 59 libcurl4-openssl-dev \ 60 libgdk-pixbuf2.0-0 \ 61 libgdk-pixbuf2.0-dev \ 62 libtool \ 63 libtool-bin \ 64 lzip \ 65 make \ 66 mc \ 67 nano \ 68 ninja \ 69 nodejs \ 70 openjdk-8-jdk-headless \ 71 p7zip-full \ 72 ruby \ 73 scons \ 74 wine \ 75 yarn 76 77echo 'JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> /etc/environment 78 79mkdir -p /opt 80( 81 cd /opt 82 wget -qO swift.tar.gz https://swift.org/builds/swift-5.2.3-release/ubuntu1604/swift-5.2.3-RELEASE/swift-5.2.3-RELEASE-ubuntu16.04.tar.gz 83 tar -xf ./swift.tar.gz 84 rm -f ./swift.tar.gz 85) 86 87useradd -d /home/worker -m -s /bin/bash worker 88 89sudo -iu worker /bin/bash -i <<"EOF" 90set -e 91set -x 92 93echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64' >> ~/.profile 94echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.profile 95curl -s "https://get.sdkman.io" | /bin/bash 96EOF 97 98sudo -iu worker /bin/bash -i <<"EOF" 99set -e 100set -x 101 102sdk install gradle 5.4.1 103sdk install maven 104 105echo 'PATH=/usr/lib/dart/bin:$PATH' >> ~/.profile 106echo 'PATH=~/.sdkman/candidates/maven/current/bin:$PATH' >> ~/.profile 107echo 'PATH=~/.sdkman/candidates/gradle/current/bin:$PATH' >> ~/.profile 108echo 'PATH=$PATH:/opt/swift-5.2.3-RELEASE-ubuntu16.04/usr/bin' >> ~/.profile 109echo 'export PATH=$PATH:~/.yarn/bin' >> ~/.profile 110EOF 111 112sudo -iu worker /bin/bash -i <<"EOF" 113set -e 114set -x 115 116wget -O commandlinetools.zip https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip 117unzip commandlinetools.zip -d ./Android 118rm commandlinetools.zip 119 120echo 'export ANDROID_NDK_VERSION=21.1.6352462' >> ~/.profile 121echo 'export ANDROID_HOME=~/Android' >> ~/.profile 122echo 'export ANDROID_SDK_ROOT=${ANDROID_HOME}' >> ~/.profile 123echo 'PATH=$PATH:$ANDROID_HOME/tools' >> ~/.profile 124echo 'PATH=$PATH:$ANDROID_HOME/tools/bin' >> ~/.profile 125echo 'PATH=$PATH:$ANDROID_HOME/platform-tools' >> ~/.profile 126echo 'PATH=~/flutter/bin:$PATH' >> ~/.profile 127echo 'export PATH' >> ~/.profile 128echo 'export ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$ANDROID_NDK_VERSION' >> ~/.profile 129EOF 130 131sudo -iu worker /bin/bash -i <<"EOF" 132set -e 133set -x 134 135yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses 136sdkmanager --sdk_root=${ANDROID_HOME} \ 137 --install \ 138 "platform-tools" \ 139 "platforms;android-28" \ 140 "platforms;android-29" \ 141 "ndk;${ANDROID_NDK_VERSION}" \ 142 "build-tools;28.0.3" \ 143 "build-tools;29.0.3" 144 145sdkmanager --sdk_root=${ANDROID_HOME} tools 146yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses 147EOF 148 149sudo -iu worker /bin/bash -i <<"EOF" 150set -e 151set -x 152 153git clone https://github.com/flutter/flutter.git -b stable 154flutter config --android-sdk $ANDROID_HOME 155flutter doctor --android-licenses 156flutter precache 157EOF 158 159sudo -iu worker /bin/bash -i <<"EOF" 160set -e 161set -x 162 163mkdir -p ~/tmp && cd ~/tmp 164wget https://sourceware.org/pub/valgrind/valgrind-3.15.0.tar.bz2 165tar -xf ./valgrind-3.15.0.tar.bz2 166cd ./valgrind-3.15.0 167./configure --prefix=/home/worker/.local 168make && make install 169cd ~/ && rm -rf ./tmp/* 170EOF 171 172curl --create-dirs -fsSLo /usr/share/jenkins/agent.jar \ 173 https://repo.jenkins-ci.org/public/org/jenkins-ci/main/remoting/${JENKINS_AGENT_VERSION}/remoting-${JENKINS_AGENT_VERSION}.jar 174chmod 755 /usr/share/jenkins 175chmod 644 /usr/share/jenkins/agent.jar 176ln -sf /usr/share/jenkins/agent.jar /usr/share/jenkins/slave.jar 177 178sudo -iu worker /bin/bash -i <<"EOF" 179set -e 180set -x 181 182git clone https://github.com/mxe/mxe.git 183cd ./mxe 184echo 'JOBS := 1' > ./settings.mk 185echo 'MXE_TARGETS := x86_64-w64-mingw32.static' >> ./settings.mk 186echo 'LOCAL_PKG_LIST := cunit libiberty' >> ./settings.mk 187echo '.DEFAULT local-pkg-list:' >> ./settings.mk 188echo 'local-pkg-list: $(LOCAL_PKG_LIST)' >> ./settings.mk 189 190make 191echo 'export MXE_HOME=~/mxe' >> ~/.profile 192EOF 193 194sudo -iu worker /bin/bash -i <<"EOF" 195set -e 196set -x 197mkdir -p ~/.jenkins 198mkdir -p ~/agent 199cat ~/.profile 200echo $PATH 201EOF 202 203