Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2014 Canonical
  4. #
  5. # Author: Oliver Grawert <ogra@canonical.com>, Marius Gripsgard <me@mariogrip.com>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation; either version 2 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  20. # USA
  21. #
  22.  
  23. set -e
  24.  
  25. TARPATH=$1
  26. SYSIMG=$2
  27.  
  28. check_prereq()
  29. {
  30. if [ ! $(which make_ext4fs) ] || [ ! -x $(which simg2img) ] || \
  31. [ ! -x $(which adb) ]; then
  32. echo "please install the android-tools-fsutils and android-tools-adb packages" && exit 1
  33. fi
  34. }
  35.  
  36. do_shell()
  37. {
  38. adb shell "$@"
  39. }
  40.  
  41. install_OPO()
  42. {
  43. adb push configs/70-bacon.rules /cache/system/usr/lib/lxc-android-config
  44. adb push configs/adbd.conf /cache/system/etc/init/
  45. do_shell "rm /cache/system/etc/init/ubuntu-location-service.conf"
  46. }
  47.  
  48.  
  49. convert_android_img()
  50. {
  51. simg2img $SYSIMG $WORKDIR/system.img.raw
  52. mkdir $TMPMOUNT
  53. mount -t ext4 -o loop $WORKDIR/system.img.raw $TMPMOUNT
  54. make_ext4fs -l 120M $WORKDIR/system.img $TMPMOUNT >/dev/null 2>&1
  55. }
  56.  
  57. prepare_ubuntu_system()
  58. {
  59. do_shell "rm -f /data/system.img"
  60. for data in system android; do
  61. do_shell "rm -rf /data/$data-data"
  62. done
  63. if [ -z "$KEEP" ]; then
  64. do_shell "rm -rf /data/user-data"
  65. else
  66. echo -n "keep option set, keeping user data ... "
  67. fi
  68. do_shell "dd if=/dev/zero of=/data/system.img seek=500K bs=4096 count=0 >/dev/null 2>&1"
  69. do_shell "mkfs.ext2 -F /data/system.img >/dev/null 2>&1"
  70. do_shell "mkdir -p /cache/system"
  71. do_shell "mount -o loop /data/system.img /cache/system/"
  72. }
  73.  
  74. usage()
  75. {
  76. echo "usage: $(basename $0) <path to rootfs tarball> <path to android system.img> [options]\n
  77. options:
  78. -h|--help this message
  79. -c|--custom path to customization tarball (needs to be tar.xz)
  80. -k|--keep-userdata do not wipe user data on device
  81. -w|--wipe-file absolute path of a file inside the image to wipe (empty)\n"
  82. exit 1
  83. }
  84.  
  85. SUDOARGS="$@"
  86.  
  87. while [ $# -gt 0 ]; do
  88. case "$1" in
  89. -h|--help)
  90. usage
  91. ;;
  92. -c|--custom)
  93. [ -n "$2" ] && CUST_TARPATH=$2 shift || usage
  94. ;;
  95. -k|--keep-userdata)
  96. KEEP=1
  97. ;;
  98. -w|--wipe-file)
  99. [ -n "$2" ] && WIPE_PATH=$2 shift || usage
  100. ;;
  101. esac
  102. shift
  103. done
  104.  
  105. TARBALL=$(basename $TARPATH)
  106.  
  107. if [ -z "$TARBALL" ]; then
  108. echo "need valid rootfs tarball path"
  109. usage
  110. fi
  111.  
  112. TARTYPE=$(file --mime-type $TARPATH|sed 's/^.* //')
  113. case ${TARTYPE#application\/} in
  114. gzip|x-gzip)
  115. ;;
  116. *)
  117. echo "Need valid rootfs tarball gzip type"
  118. usage
  119. ;;
  120. esac
  121.  
  122. if [ -z "$SYSIMG" ] || \
  123. [ "$(file --mime-type $SYSIMG|sed 's/^.* //')" != "application/octet-stream" ]; then
  124. echo "need valid system.img path and type application/octet-stream"
  125. usage
  126. fi
  127.  
  128. if [ ! -z "$CUST_TARPATH" ] && \
  129. [ "$(file --mime-type $CUST_TARPATH|sed 's/^.* //')" != "application/x-xz" ]; then
  130. echo "Custom tarball needs to be valid path and type .tar.xz"
  131. usage
  132. fi
  133.  
  134. [ $(id -u) -ne 0 ] && exec sudo $0 $SUDOARGS
  135.  
  136. check_prereq
  137.  
  138.  
  139. WORKDIR=$(mktemp -d /tmp/rootstock-touch-install.XXXXX)
  140. TMPMOUNT="$WORKDIR/tmpmount"
  141.  
  142. echo -n "transfering rootfs tarball ... "
  143. adb push $TARPATH /recovery/ >/dev/null 2>&1
  144. echo "[done]"
  145.  
  146. if [ ! -z "$CUST_TARPATH" ]; then
  147. CUST_TARBALL=$(basename $CUST_TARPATH)
  148. echo -n "transferring custom tarball"
  149. adb push $CUST_TARPATH /recovery/ >/dev/null 2>&1
  150. echo "[done]"
  151. fi
  152.  
  153. echo -n "preparing system-image on device ... "
  154. prepare_ubuntu_system
  155. echo "[done]"
  156.  
  157. echo -n "unpacking rootfs tarball to system-image ... "
  158. do_shell "cd /cache/system && zcat /recovery/$TARBALL | tar xf -"
  159. do_shell "mkdir -p /cache/system/android/firmware"
  160. do_shell "mkdir -p /cache/system/android/persist"
  161. do_shell "mkdir -p /cache/system/userdata"
  162. do_shell "[ -e /cache/system/SWAP.swap ] && mv /cache/system/SWAP.swap /data/SWAP.img"
  163. for link in cache data factory firmware persist system; do
  164. do_shell "cd /cache/system && ln -s /android/$link $link"
  165. done
  166. do_shell "cd /cache/system/lib && ln -s /system/lib/modules modules"
  167. do_shell "cd /cache/system && ln -s /android/system/vendor vendor"
  168. do_shell "[ -e /cache/system/etc/mtab ] && rm /cache/system/etc/mtab"
  169. do_shell "cd /cache/system/etc && ln -s /proc/mounts mtab"
  170. if [ ! -z "$WIPE_PATH" ]; then
  171. do_shell "echo ' ' >/cache/system/$WIPE_PATH || true"
  172. fi
  173. echo "[done]"
  174.  
  175. if [ ! -z "$CUST_TARPATH" ];then
  176. echo -n "unpacking custom tarball"
  177. do_shell "mkdir -p /cache/system/custom"
  178. do_shell "cd /cache && xzcat /recovery/$CUST_TARBALL | tar xf -"
  179. echo "[done]"
  180. fi
  181.  
  182. echo -n "adding android system image to installation ... "
  183. convert_android_img
  184. ANDROID_DIR="/cache/system/var/lib/lxc/android/"
  185. adb push $WORKDIR/system.img $ANDROID_DIR >/dev/null 2>&1
  186. echo "[done]"
  187.  
  188. echo -n "enabling Mir ... "
  189. do_shell "touch /cache/system/home/phablet/.display-mir"
  190. echo "[done]"
  191.  
  192. echo -n "Setting OnePlus one configs... "
  193. install_OPO
  194. echo "[done]"
  195.  
  196. echo "rebooting device"
  197. adb reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement