Advertisement
Aclegg2011

build-rom.sh

Dec 16th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Build Shell Variables
  4. rompath=$(pwd)
  5. bliss_device=""
  6. build_options=""
  7. bliss_branch=""
  8. rom_variant=""
  9.  
  10. # Option switches
  11. clean="n"
  12. cleanOption=""
  13. official="n"
  14. officialOption=""
  15. patchOption=""
  16. releaseOption=""
  17. sync="n"
  18. syncOption=""
  19. upload="n"
  20.  
  21.  
  22. # Setup Environment and jobs variable
  23. if [ -z "$USER" ];then
  24. export USER="$(id -un)"
  25. fi
  26.  
  27. if [[ $(uname -s) = "Darwin" ]];then
  28. jobs=$(sysctl -n hw.ncpu)
  29. elif [[ $(uname -s) = "Linux" ]];then
  30. jobs=$(nproc)
  31. fi
  32.  
  33. while test $# -gt 0
  34. do
  35. case $1 in
  36.  
  37. # Normal option processing
  38. -h | --help)
  39. echo "Usage: $0 options device_name"
  40. echo "options:"
  41. echo "-c | --clean : Does make clean && make clobber"
  42. echo "-o | --official : Builds the rom as OFFICIAL"
  43. echo "-s | --sync : Repo sync repos"
  44. echo "-u | --upload : Uploads Official Builds to Bliss and Local sFTP"
  45. echo "-v | --version : Version Info"
  46. echo "-----------------------------------------------------------------"
  47. echo "Treble Only Flags"
  48. echo "-----------------------------------------------------------------"
  49. echo "-p | --patch : "
  50. echo "-r | --release : "
  51. echo ""
  52. ;;
  53. -c | --clean)
  54. clean="y";
  55. echo "Clean build."
  56. ;;
  57. -s | --sync)
  58. sync="y"
  59. echo "Repo sync."
  60. ;;
  61. -o | --official)
  62. official="y"
  63. echo "Building Official Bliss ROM."
  64. ;;
  65. -p | --patch)
  66. patchOption="p";
  67. echo "patching selected."
  68. ;;
  69. -r | --release)
  70. releaseOption="r";
  71. echo "Building as release selected."
  72. ;;
  73. -u | --upload)
  74. upload="y"
  75. echo "Upload to Bliss and Personal sFTP."
  76. ;;
  77. -v | --version)
  78. echo "Version: Bliss ROM Builder 0.4"
  79. echo "Updated: 12/16/2018"
  80. ;;
  81.  
  82.  
  83. # ...
  84.  
  85. # Special cases
  86. --)
  87. break
  88. ;;
  89. --*)
  90. # error unknown (long) option $1
  91. ;;
  92. -?)
  93. # error unknown (short) option $1
  94. ;;
  95.  
  96. # FUN STUFF HERE:
  97. # Split apart combined short options
  98. -*)
  99. split=$1
  100. shift
  101. set -- $(echo "$split" | cut -c 2- | sed 's/./-& /g') "$@"
  102. continue
  103. ;;
  104.  
  105. # Done with options
  106. *)
  107. break
  108. ;;
  109. esac
  110.  
  111. # for testing purposes:
  112. shift
  113. done
  114.  
  115. if [[ $sync == "y" && $1 = "arm" ]];then
  116. repo sync -c -j$jobs --force-sync
  117.  
  118. elif [ $sync == "y" ];then
  119. syncOption="s"
  120. fi
  121.  
  122. if [[ $clean == "y" && $1 = "arm" ]];then
  123. make -j$jobs clean
  124.  
  125. elif [ $clean == "y" ];then
  126. cleanOption="c"
  127. fi
  128.  
  129. if [[ $official == "y" && $1 = "arm" ]];then
  130. export BLISS_BUILDTYPE=OFFICIAL
  131.  
  132. elif [ $official == "y" ];then
  133. officialOption="o"
  134.  
  135. else
  136. export BLISS_BUILDTYPE=UNOFFICIAL
  137. fi
  138.  
  139. blissSFTP(){
  140. FILEPATH=$rompath/out/target/product/$bliss_variant_name
  141. cd $FILEPATH
  142. echo ""
  143. BLISSZIP=$(ls Bliss-*.zip)
  144. BLISSMD5=$(ls Bliss-*.md5)
  145. BLISSLOG=$(ls Changelog-Bliss-*.txt)
  146.  
  147. if [[ -a $BLISSZIP && -a $BLISSMD5 && -a $BLISSLOG ]]; then
  148. echo $BLISSZIP
  149. echo $BLISSMD5
  150. echo $BLISSLOG
  151. else
  152. echo "Upload(s) Failed due to missing files"
  153. return 0
  154. fi
  155.  
  156. BLISSPASS=password
  157. sshpass -p $password sftp -P xx xxxx@xxxx <<EOF
  158. cd Pie/$bliss_variant_name
  159. put $BLISSZIP
  160. put $BLISSMD5
  161. put $BLISSLOG
  162. bye
  163. EOF
  164.  
  165. BLISSPASS=password
  166. sshpass -p $BLISSPASS sftp -P xx xxx@xxx <<EOF
  167. cd $bliss_variant_name
  168. put $BLISSZIP
  169. put $BLISSMD5
  170. put $BLISSLOG
  171. bye
  172. EOF
  173.  
  174. }
  175.  
  176. blissBuildVariant_arm() {
  177. lunch bliss_$2-userdebug
  178. make -j$jobs blissify
  179. }
  180.  
  181. blissBuildVariant_treble() {
  182. bash /build/make/core/treble/build-treble.sh $1 $2 $3
  183. }
  184.  
  185. bliss_branch=$3
  186. bliss_device=$2
  187. rom_variant=$1
  188. build_options=$cleanOption$syncOption$officialOption$patchOption$releaseOption
  189.  
  190. # If rom_variant is empty, stop the script
  191. if [ -z $rom_variant ];then
  192. echo "No Rom variant was selected"
  193. exit
  194. fi
  195.  
  196. # If bliss_device is empty, stop the script
  197. if [ -z $bliss_device ];then
  198. echo "No Device was selected"
  199. exit
  200. fi
  201.  
  202. # If build_options is not empty add the - options flag
  203. if [ ! -z "$build_options" ];then
  204. build_options=-$cleanOption$syncOption$officialOption$patchOption$releaseOption
  205. fi
  206.  
  207. if [ $rom_variant = "arm" ];then
  208. . build/envsetup.sh
  209. blissBuildVariant_arm $rom_variant $bliss_device
  210.  
  211. elif [ $rom_variant = "treble" ];then
  212. blissBuildVariant_treble $build_options $bliss_device $bliss_branch
  213. fi
  214.  
  215. if [[ $upload == "y" && $official="y" ]];then
  216. blissSFTP $bliss_device
  217. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement