Advertisement
Transfusion

ubuntu touch mi2s rootstock install system2

Jul 24th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2014 Canonical
  4. #
  5. # Author: Oliver Grawert <[email protected]>
  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. convert_android_img()
  42. {
  43. simg2img $SYSIMG $WORKDIR/system.img.raw
  44. mkdir $TMPMOUNT
  45. mount -t ext4 -o loop $WORKDIR/system.img.raw $TMPMOUNT
  46. make_ext4fs -l 120M $WORKDIR/system.img $TMPMOUNT >/dev/null 2>&1
  47. }
  48.  
  49. prepare_ubuntu_system()
  50. {
  51. do_shell "rm -f /data/system.img"
  52. for data in system android; do
  53. do_shell "rm -rf /data/$data-data"
  54. done
  55. if [ -z "$KEEP" ]; then
  56. do_shell "rm -rf /data/user-data"
  57. else
  58. echo -n "keep option set, keeping user data ... "
  59. fi
  60. do_shell "dd if=/dev/zero of=/data/system.img seek=500K bs=4096 count=0 >/dev/null 2>&1"
  61. do_shell "mkfs.ext2 -F /data/system.img >/dev/null 2>&1"
  62. do_shell "mkdir -p /cache/system"
  63. do_shell "mount -o loop /data/system.img /cache/system/"
  64. }
  65.  
  66. cleanup()
  67. {
  68. mount | grep -q $TMPMOUNT 2>/dev/null && umount $TMPMOUNT
  69. cleanup_device
  70. rm -rf $WORKDIR
  71. echo
  72. }
  73.  
  74. cleanup_device()
  75. {
  76. [ -e $WORKDIR/device-clean ] && return
  77. do_shell "umount /cache/system/ 2>/dev/null && rm -rf /cache/system 2>/dev/null"
  78. do_shell "rm -f /recovery/$TARBALL"
  79. [ -e $WORKDIR ] && touch $WORKDIR/device-clean 2>/dev/null || true
  80. }
  81.  
  82. trap cleanup 0 1 2 3 9 15
  83.  
  84. usage()
  85. {
  86. echo "usage: $(basename $0) <path to rootfs tarball> <path to android system.img> [options]\n
  87. options:
  88. -h|--help this message
  89. -c|--custom path to customization tarball (needs to be tar.xz)
  90. -k|--keep-userdata do not wipe user data on device
  91. -w|--wipe-file absolute path of a file inside the image to wipe (empty)\n"
  92. exit 1
  93. }
  94.  
  95. SUDOARGS="$@"
  96.  
  97. while [ $# -gt 0 ]; do
  98. case "$1" in
  99. -h|--help)
  100. usage
  101. ;;
  102. -c|--custom)
  103. [ -n "$2" ] && CUST_TARPATH=$2 shift || usage
  104. ;;
  105. -k|--keep-userdata)
  106. KEEP=1
  107. ;;
  108. -w|--wipe-file)
  109. [ -n "$2" ] && WIPE_PATH=$2 shift || usage
  110. ;;
  111. esac
  112. shift
  113. done
  114.  
  115. TARBALL=$(basename $TARPATH)
  116.  
  117. if [ -z "$TARBALL" ]; then
  118. echo "need valid rootfs tarball path"
  119. usage
  120. fi
  121.  
  122. TARTYPE=$(file --mime-type $TARPATH|sed 's/^.* //')
  123. case ${TARTYPE#application\/} in
  124. gzip|x-gzip)
  125. ;;
  126. *)
  127. echo "Need valid rootfs tarball gzip type"
  128. usage
  129. ;;
  130. esac
  131.  
  132. if [ -z "$SYSIMG" ] || \
  133. [ "$(file --mime-type $SYSIMG|sed 's/^.* //')" != "application/octet-stream" ]; then
  134. echo "need valid system.img path and type application/octet-stream"
  135. usage
  136. fi
  137.  
  138. if [ ! -z "$CUST_TARPATH" ] && \
  139. [ "$(file --mime-type $CUST_TARPATH|sed 's/^.* //')" != "application/x-xz" ]; then
  140. echo "Custom tarball needs to be valid path and type .tar.xz"
  141. usage
  142. fi
  143.  
  144. [ $(id -u) -ne 0 ] && exec sudo $0 $SUDOARGS
  145.  
  146. check_prereq
  147.  
  148. if ! adb devices | grep -q recovery; then
  149. echo "please make sure the device is attched via USB in recovery mode"
  150. exit 1
  151. fi
  152.  
  153. WORKDIR=$(mktemp -d /tmp/rootstock-touch-install.XXXXX)
  154. TMPMOUNT="$WORKDIR/tmpmount"
  155.  
  156. echo -n "transfering rootfs tarball ... "
  157. adb push $TARPATH /recovery/ >/dev/null 2>&1
  158. echo "[done]"
  159.  
  160. if [ ! -z "$CUST_TARPATH" ]; then
  161. CUST_TARBALL=$(basename $CUST_TARPATH)
  162. echo -n "transferring custom tarball"
  163. adb push $CUST_TARPATH /recovery/ >/dev/null 2>&1
  164. echo "[done]"
  165. fi
  166.  
  167. echo -n "preparing system-image on device ... "
  168. prepare_ubuntu_system
  169. echo "[done]"
  170.  
  171. echo -n "unpacking rootfs tarball to system-image ... "
  172. do_shell "cd /cache/system && zcat /recovery/$TARBALL | tar xf -"
  173. do_shell "mkdir -p /cache/system/android/firmware"
  174. do_shell "mkdir -p /cache/system/android/persist"
  175. do_shell "mkdir -p /cache/system/userdata"
  176. do_shell "[ -e /cache/system/SWAP.swap ] && mv /cache/system/SWAP.swap /data/SWAP.img"
  177. for link in cache data factory firmware persist system; do
  178. do_shell "cd /cache/system && ln -s /android/$link $link"
  179. done
  180. do_shell "cd /cache/system/lib && ln -s /system/lib/modules modules"
  181. do_shell "cd /cache/system && ln -s /android/system/vendor vendor"
  182. do_shell "[ -e /cache/system/etc/mtab ] && rm /cache/system/etc/mtab"
  183. do_shell "cd /cache/system/etc && ln -s /proc/mounts mtab"
  184. if [ ! -z "$WIPE_PATH" ]; then
  185. do_shell "echo ' ' >/cache/system/$WIPE_PATH || true"
  186. fi
  187. echo "[done]"
  188.  
  189. if [ ! -z "$CUST_TARPATH" ];then
  190. echo -n "unpacking custom tarball"
  191. do_shell "mkdir -p /cache/system/custom"
  192. do_shell "cd /cache && xzcat /recovery/$CUST_TARBALL | tar xf -"
  193. echo "[done]"
  194. fi
  195.  
  196. echo -n "adding android system image to installation ... "
  197. convert_android_img
  198. ANDROID_DIR="/cache/system/var/lib/lxc/android/"
  199. adb push $WORKDIR/system.img $ANDROID_DIR >/dev/null 2>&1
  200. echo "[done]"
  201.  
  202. echo -n "enabling Mir ... "
  203. do_shell "touch /cache/system/home/phablet/.display-mir"
  204. echo "[done]"
  205.  
  206. echo -n "cleaning up on device ... "
  207. cleanup_device
  208. echo "[done]"
  209.  
  210. echo "rebooting device"
  211. adb reboot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement