Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2014 Canonical
  4. #
  5. # Author: Oliver Grawert <ogra@canonical.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. CUST_TARPATH=$2
  27. SYSIMG=$3
  28.  
  29. prepare_ubports_systemfs()
  30. {
  31. rm -f $WORKDIR/system.img
  32. dd if=/dev/zero of=$WORKDIR/system.img seek=500K bs=4096 count=0
  33. mkfs.ext2 -F $WORKDIR/system.img
  34. mkdir -p $WORKDIR/system
  35. mount -o loop $WORKDIR/system.img $WORKDIR/system/
  36. }
  37.  
  38. cleanup()
  39. {
  40. echo
  41. echo "cleaning up"
  42. mount | grep -q $WORKDIR/system 2>/dev/null && umount $WORKDIR/system
  43. cleanup_device
  44. #rm -rf $WORKDIR
  45. echo
  46. }
  47.  
  48. cleanup_device()
  49. {
  50. [ -e $WORKDIR/device-clean ] && return
  51. umount $WORKDIR/system/ && rm -rf $WORKDIR/system
  52. [ -e $WORKDIR ] && touch $WORKDIR/device-clean 2>/dev/null || true
  53. }
  54.  
  55. trap cleanup 0 1 2 3 9 15
  56.  
  57. SUDOARGS="$@"
  58.  
  59. if [ -z "$TARPATH" ]; then
  60. echo "need valid rootfs tarball path"
  61. usage
  62. fi
  63.  
  64. TARTYPE=$(file --mime-type $TARPATH|sed 's/^.* //')
  65. case ${TARTYPE#application\/} in
  66. gzip|x-gzip)
  67. ;;
  68. *)
  69. echo "Need valid rootfs tarball gzip type"
  70. usage
  71. ;;
  72. esac
  73.  
  74.  
  75. if [ -z "$CUST_$TARPATH" ]; then
  76. echo "need valid custom tarball path"
  77. usage
  78. fi
  79.  
  80. TARTYPE=$(file --mime-type $CUST_TARPATH|sed 's/^.* //')
  81. case ${TARTYPE#application\/} in
  82. gzip|x-gzip)
  83. ;;
  84. *)
  85. echo "Need valid custom tarball gzip type"
  86. usage
  87. ;;
  88. esac
  89.  
  90. if [ -z "$SYSIMG" ]; then
  91. echo "need valid systemfs tarball path"
  92. usage
  93. fi
  94.  
  95. if [ "$(file --mime-type $SYSIMG|sed 's/^.* //')" != "application/x-xz" ]; then
  96. echo "system tarball needs to be valid path and type .tar.xz"
  97. usage
  98. fi
  99.  
  100. [ $(id -u) -ne 0 ] && exec sudo $0 $SUDOARGS
  101.  
  102.  
  103. WORKDIR=$(mktemp -d /tmp/halium-install.XXXXX)
  104. TMPMOUNT="$WORKDIR/tmpmount"
  105.  
  106. prepare_ubports_systemfs
  107.  
  108. OUTDIR=$(pwd)
  109. TARBALL=$(readlink -f $TARPATH)
  110. echo -n "unpacking rootfs tarball to system-image ... "
  111. cd $WORKDIR/system && zcat $TARBALL | tar xf - --numeric-owner
  112. cd $OUTDIR
  113. echo "[done]"
  114.  
  115. echo "Testing for SWAP.swap"
  116. [ -e $WORKDIR/system/SWAP.swap ] && rm $WORKDIR/system/SWAP.swap
  117.  
  118. TARBALL=$(readlink -f $CUST_TARPATH)
  119. echo -n "adding custom tarball ... "
  120. # --strip-components=1 since the tarball dir is system/
  121. cd $WORKDIR/system && zcat $TARBALL | tar xf - --strip-components=1 --numeric-owner
  122. cd $OUTDIR
  123. echo "[done]"
  124.  
  125. TARBALL=$(readlink -f $SYSIMG)
  126. echo -n "unpacking systemfs tarball to system-image ... "
  127. # --strip-components=1 since the tarball dir is system/
  128. cd $WORKDIR/system && xzcat $TARBALL | tar xf - --exclude=partitions --strip-components=1 --numeric-owner
  129. cd $OUTDIR
  130. echo "[done]"
  131.  
  132. echo -n "prepare other stuff in system-image ... "
  133. cd $WORKDIR/system
  134. mkdir -p android/firmware
  135. mkdir -p android/persist
  136. mkdir -p userdata
  137. for link in cache data factory firmware persist system; do
  138. ln -s /android/$link $link
  139. done
  140. cd lib && ln -s /system/lib/modules modules && cd ..
  141. ln -s /android/system/vendor vendor
  142. [ -e etc/mtab ] && rm etc/mtab
  143. cd etc && ln -s /proc/mounts mtab && cd ..
  144.  
  145. cd $OUTDIR
  146. echo "[done]"
  147.  
  148. echo "umount .../system"
  149. umount $WORKDIR/system
  150. echo "save prepared systemfs"
  151. mv $WORKDIR/system.img $OUTDIR/prepared-system.img
  152.  
  153. echo -n "cleaning up on device ... "
  154. cleanup_device
  155. echo "[done]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement