/install-playstore.sh

https://github.com/geeks-r-us/anbox-playstore-installer · Shell · 310 lines · 213 code · 57 blank · 40 comment · 35 complexity · 2f03fabab59b9231dcd542169b316a0b MD5 · raw file

  1. #!/bin/bash
  2. # Copyright 2019 root@geeks-r-us.de
  3. # Permission is hereby granted, free of charge, to any person obtaining a copy
  4. # of this software and associated documentation files (the "Software"), to deal
  5. # in the Software without restriction, including without limitation the rights to
  6. # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. # of the Software, and to permit persons to whom the Software is furnished to do so,
  8. # subject to the following conditions:
  9. # The above copyright notice and this permission notice shall be included in all
  10. # copies or substantial portions of the Software.
  11. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  12. # INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13. # PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  14. # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  15. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
  16. # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. # For further information see: http://geeks-r-us.de/2017/08/26/android-apps-auf-dem-linux-desktop/
  18. # If you find this piece of software useful and or want to support it's development think of
  19. # buying me a coffee https://ko-fi.com/geeks_r_us
  20. # die when an error occurs
  21. set -e
  22. WORKDIR="$(pwd)/anbox-work"
  23. # use sudo if installed
  24. if [ ! "$(which sudo)" ]; then
  25. SUDO=""
  26. else
  27. SUDO=$(which sudo)
  28. fi
  29. # clean downloads
  30. if [ "$1" = "--clean" ]; then
  31. $SUDO rm -rf "$WORKDIR"
  32. exit 0
  33. fi
  34. # check if script was started with BASH
  35. if [ ! "$(ps -p $$ -oargs= | awk '{print $1}' | grep -E 'bash$')" ]; then
  36. echo "Please use BASH to start the script!"
  37. exit 1
  38. fi
  39. # check if lzip is installed
  40. if [ ! "$(which lzip)" ]; then
  41. echo -e "lzip is not installed. Please install lzip.\nExample: sudo apt install lzip"
  42. exit 1
  43. fi
  44. # check if squashfs-tools are installed
  45. if [ ! "$(which mksquashfs)" ] || [ ! "$(which unsquashfs)" ]; then
  46. echo -e "squashfs-tools is not installed. Please install squashfs-tools.\nExample: sudo apt install squashfs-tools"
  47. exit 1
  48. else
  49. MKSQUASHFS=$(which mksquashfs)
  50. UNSQUASHFS=$(which unsquashfs)
  51. fi
  52. # check if wget is installed
  53. if [ ! "$(which wget)" ]; then
  54. echo -e "wget is not installed. Please install wget.\nExample: sudo apt install wget"
  55. exit 1
  56. else
  57. WGET=$(which wget)
  58. fi
  59. # check if curl is installed
  60. if [ ! "$(which curl)" ]; then
  61. echo -e "curl is not installed. Please install curl.\nExample: sudo apt install curl"
  62. exit 1
  63. else
  64. CURL=$(which curl)
  65. fi
  66. # check if unzip is installed
  67. if [ ! "$(which unzip)" ]; then
  68. echo -e "unzip is not installed. Please install unzip.\nExample: sudo apt install unzip"
  69. exit 1
  70. else
  71. UNZIP=$(which unzip)
  72. fi
  73. # check if tar is installed
  74. if [ ! "$(which tar)" ]; then
  75. echo -e "tar is not installed. Please install tar.\nExample: sudo apt install tar"
  76. exit 1
  77. else
  78. TAR=$(which tar)
  79. fi
  80. # get latest releasedate based on tag_name for latest x86_64 build
  81. OPENGAPPS_RELEASEDATE="$($CURL -s https://api.github.com/repos/opengapps/x86_64/releases/latest | head -n 10 | grep tag_name | grep -o "\"[0-9][0-9]*\"" | grep -o "[0-9]*")"
  82. OPENGAPPS_FILE="open_gapps-x86_64-7.1-pico-$OPENGAPPS_RELEASEDATE.zip"
  83. OPENGAPPS_URL="https://sourceforge.net/projects/opengapps/files/x86_64/$OPENGAPPS_RELEASEDATE/$OPENGAPPS_FILE"
  84. HOUDINI_Y_URL="http://dl.android-x86.org/houdini/7_y/houdini.sfs"
  85. HOUDINI_Z_URL="http://dl.android-x86.org/houdini/7_z/houdini.sfs"
  86. ANBOX=$(which anbox)
  87. SNAP_TOP=""
  88. if ( [ -d '/var/snap' ] || [ -d '/snap' ] ) && \
  89. ( [ ${ANBOX} = "/snap/bin/anbox" ] || [ ${ANBOX} == /var/lib/snapd/snap/bin/anbox ] );then
  90. if [ -d '/snap' ];then
  91. SNAP_TOP=/snap
  92. else
  93. SNAP_TOP=/var/lib/snapd/snap
  94. fi
  95. COMBINEDDIR="/var/snap/anbox/common/combined-rootfs"
  96. OVERLAYDIR="/var/snap/anbox/common/rootfs-overlay"
  97. WITH_SNAP=true
  98. else
  99. COMBINEDDIR="/var/lib/anbox/combined-rootfs"
  100. OVERLAYDIR="/var/lib/anbox/rootfs-overlay"
  101. WITH_SNAP=false
  102. fi
  103. if [ ! -d "$COMBINEDDIR" ]; then
  104. # enable overlay fs
  105. if $WITH_SNAP;then
  106. $SUDO snap set anbox rootfs-overlay.enable=true
  107. $SUDO snap restart anbox.container-manager
  108. else
  109. $SUDO cat >/etc/systemd/system/anbox-container-manager.service.d/override.conf<<EOF
  110. [Service]
  111. ExecStart=
  112. ExecStart=/usr/bin/anbox container-manager --daemon --privileged --data-path=/var/lib/anbox --use-rootfs-overlay
  113. EOF
  114. $SUDO systemctl daemon-reload
  115. $SUDO systemctl restart anbox-container-manager.service
  116. fi
  117. sleep 20
  118. fi
  119. echo $OVERLAYDIR
  120. if [ ! -d "$OVERLAYDIR" ]; then
  121. echo -e "Overlay no enabled ! Please check error messages!"
  122. exit 1
  123. fi
  124. echo $WORKDIR
  125. if [ ! -d "$WORKDIR" ]; then
  126. mkdir "$WORKDIR"
  127. fi
  128. cd "$WORKDIR"
  129. if [ -d "$WORKDIR/squashfs-root" ]; then
  130. $SUDO rm -rf squashfs-root
  131. fi
  132. echo "Extracting anbox android image"
  133. # get image from anbox
  134. if $WITH_SNAP;then
  135. cp $SNAP_TOP/anbox/current/android.img .
  136. else
  137. cp /var/lib/anbox/android.img .
  138. fi
  139. $SUDO $UNSQUASHFS android.img
  140. # get opengapps and install it
  141. cd "$WORKDIR"
  142. echo "Loading open gapps from $OPENGAPPS_URL"
  143. while : ;do
  144. if [ ! -f ./$OPENGAPPS_FILE ]; then
  145. $WGET -q --show-progress $OPENGAPPS_URL
  146. else
  147. $WGET -q --show-progress -c $OPENGAPPS_URL
  148. fi
  149. [ $? = 0 ] && break
  150. done
  151. echo "extracting open gapps"
  152. $UNZIP -d opengapps ./$OPENGAPPS_FILE
  153. cd ./opengapps/Core/
  154. for filename in *.tar.lz
  155. do
  156. $TAR --lzip -xvf ./$filename
  157. done
  158. cd "$WORKDIR"
  159. APPDIR="$OVERLAYDIR/system/priv-app"
  160. if [ ! -d "$APPDIR" ]; then
  161. $SUDO mkdir -p "$APPDIR"
  162. fi
  163. $SUDO cp -r ./$(find opengapps -type d -name "PrebuiltGmsCore") $APPDIR
  164. $SUDO cp -r ./$(find opengapps -type d -name "GoogleLoginService") $APPDIR
  165. $SUDO cp -r ./$(find opengapps -type d -name "Phonesky") $APPDIR
  166. $SUDO cp -r ./$(find opengapps -type d -name "GoogleServicesFramework") $APPDIR
  167. cd "$APPDIR"
  168. $SUDO chown -R 100000:100000 Phonesky GoogleLoginService GoogleServicesFramework PrebuiltGmsCore
  169. echo "adding lib houdini"
  170. # load houdini_y and spread it
  171. cd "$WORKDIR"
  172. if [ ! -f ./houdini_y.sfs ]; then
  173. $WGET -O houdini_y.sfs -q --show-progress $HOUDINI_Y_URL
  174. mkdir -p houdini_y
  175. $SUDO $UNSQUASHFS -f -d ./houdini_y ./houdini_y.sfs
  176. fi
  177. LIBDIR="$OVERLAYDIR/system/lib"
  178. if [ ! -d "$LIBDIR" ]; then
  179. $SUDO mkdir -p "$LIBDIR"
  180. fi
  181. $SUDO mkdir -p "$LIBDIR/arm"
  182. $SUDO cp -r ./houdini_y/* "$LIBDIR/arm"
  183. $SUDO chown -R 100000:100000 "$LIBDIR/arm"
  184. $SUDO mv "$LIBDIR/arm/libhoudini.so" "$LIBDIR/libhoudini.so"
  185. # load houdini_z and spread it
  186. if [ ! -f ./houdini_z.sfs ]; then
  187. $WGET -O houdini_z.sfs -q --show-progress $HOUDINI_Z_URL
  188. mkdir -p houdini_z
  189. $SUDO $UNSQUASHFS -f -d ./houdini_z ./houdini_z.sfs
  190. fi
  191. LIBDIR64="$OVERLAYDIR/system/lib64"
  192. if [ ! -d "$LIBDIR64" ]; then
  193. $SUDO mkdir -p "$LIBDIR64"
  194. fi
  195. $SUDO mkdir -p "$LIBDIR64/arm64"
  196. $SUDO cp -r ./houdini_z/* "$LIBDIR64/arm64"
  197. $SUDO chown -R 100000:100000 "$LIBDIR64/arm64"
  198. $SUDO mv "$LIBDIR64/arm64/libhoudini.so" "$LIBDIR64/libhoudini.so"
  199. # add houdini parser
  200. BINFMT_DIR="/proc/sys/fs/binfmt_misc/register"
  201. set +e
  202. echo ':arm_exe:M::\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28::/system/lib/arm/houdini:P' | $SUDO tee -a "$BINFMT_DIR"
  203. echo ':arm_dyn:M::\x7f\x45\x4c\x46\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x28::/system/lib/arm/houdini:P' | $SUDO tee -a "$BINFMT_DIR"
  204. echo ':arm64_exe:M::\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7::/system/lib64/arm64/houdini64:P' | $SUDO tee -a "$BINFMT_DIR"
  205. echo ':arm64_dyn:M::\x7f\x45\x4c\x46\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\xb7::/system/lib64/arm64/houdini64:P' | $SUDO tee -a "$BINFMT_DIR"
  206. set -e
  207. echo "Modify anbox features"
  208. # add features
  209. C=$(cat <<-END
  210. <feature name="android.hardware.touchscreen" />\n
  211. <feature name="android.hardware.audio.output" />\n
  212. <feature name="android.hardware.camera" />\n
  213. <feature name="android.hardware.camera.any" />\n
  214. <feature name="android.hardware.location" />\n
  215. <feature name="android.hardware.location.gps" />\n
  216. <feature name="android.hardware.location.network" />\n
  217. <feature name="android.hardware.microphone" />\n
  218. <feature name="android.hardware.screen.portrait" />\n
  219. <feature name="android.hardware.screen.landscape" />\n
  220. <feature name="android.hardware.wifi" />\n
  221. <feature name="android.hardware.bluetooth" />"
  222. END
  223. )
  224. C=$(echo $C | sed 's/\//\\\//g')
  225. C=$(echo $C | sed 's/\"/\\\"/g')
  226. if [ ! -d "$OVERLAYDIR/system/etc/permissions/" ]; then
  227. $SUDO mkdir -p "$OVERLAYDIR/system/etc/permissions/"
  228. $SUDO cp "$WORKDIR/squashfs-root/system/etc/permissions/anbox.xml" "$OVERLAYDIR/system/etc/permissions/anbox.xml"
  229. fi
  230. $SUDO sed -i "/<\/permissions>/ s/.*/${C}\n&/" "$OVERLAYDIR/system/etc/permissions/anbox.xml"
  231. # make wifi and bt available
  232. $SUDO sed -i "/<unavailable-feature name=\"android.hardware.wifi\" \/>/d" "$OVERLAYDIR/system/etc/permissions/anbox.xml"
  233. $SUDO sed -i "/<unavailable-feature name=\"android.hardware.bluetooth\" \/>/d" "$OVERLAYDIR/system/etc/permissions/anbox.xml"
  234. if [ ! -x "$OVERLAYDIR/system/build.prop" ]; then
  235. $SUDO cp "$WORKDIR/squashfs-root/system/build.prop" "$OVERLAYDIR/system/build.prop"
  236. fi
  237. if [ ! -x "$OVERLAYDIR/default.prop" ]; then
  238. $SUDO cp "$WORKDIR/squashfs-root/default.prop" "$OVERLAYDIR/default.prop"
  239. fi
  240. # set processors
  241. $SUDO sed -i "/^ro.product.cpu.abilist=x86_64,x86/ s/$/,armeabi-v7a,armeabi,arm64-v8a/" "$OVERLAYDIR/system/build.prop"
  242. $SUDO sed -i "/^ro.product.cpu.abilist32=x86/ s/$/,armeabi-v7a,armeabi/" "$OVERLAYDIR/system/build.prop"
  243. $SUDO sed -i "/^ro.product.cpu.abilist64=x86_64/ s/$/,arm64-v8a/" "$OVERLAYDIR/system/build.prop"
  244. echo "persist.sys.nativebridge=1" | $SUDO tee -a "$OVERLAYDIR/system/build.prop"
  245. $SUDO sed -i '/ro.zygote=zygote64_32/a\ro.dalvik.vm.native.bridge=libhoudini.so' "$OVERLAYDIR/default.prop"
  246. # enable opengles
  247. echo "ro.opengles.version=131072" | $SUDO tee -a "$OVERLAYDIR/system/build.prop"
  248. echo "Restart anbox"
  249. if $WITH_SNAP;then
  250. $SUDO snap restart anbox.container-manager
  251. else
  252. $SUDO systemctl restart anbox-container-manager.service
  253. fi