Advertisement
fire219

SADIE v1.0 for testing

Jul 3rd, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. export NCURSES_NO_UTF8_ACS=1
  4.  
  5. if ! [ $(id -u) = 0 ]; then
  6. echo "SADIE must be run as root. Try 'sudo ./sadie.sh'."
  7. exit 1
  8. fi
  9.  
  10. echo "======================================================"
  11. echo "================= Welcome to SADIE ==================="
  12. echo "=== Simple Android Download and Install Executable ==="
  13. echo "======================================================"
  14. echo "============= Made for the Rock64 board ============="
  15. echo "============= by Matthew Petry (fire219) ============="
  16. echo "== Additional scripting by Kamil Trzciński (ayufan) =="
  17. echo "======================================================"
  18. echo ""
  19. echo "This script will download and flash Android 7.1 to your Rock64 board."
  20. echo ""
  21. echo "IMPORTANT NOTES:"
  22. echo "1. Before you continue, please locate a USB A-to-A cable."
  23. echo " It is critical to the installation process."
  24. echo ""
  25. echo "2. If you wish to install Android to onboard eMMC, you *MUST* remove"
  26. echo " your SD card if you have one."
  27. echo ""
  28. read -rsp $'Press any key to continue...\n' -n 1 key
  29.  
  30. HEIGHT=30
  31. WIDTH=80
  32. CHOICE_HEIGHT=4
  33. BACKTITLE="Simple Android Download and Install Executable (SADIE)"
  34. MENU="Please select one of the following options:"
  35.  
  36.  
  37.  
  38. clear
  39. echo "====Preparation===="
  40. echo "Script will now check to make sure all required tools are available."
  41. echo ""
  42. echo "Stage 1: Detect host distribution"
  43. HDISTRO=$(awk '/^ID=/' /etc/*-release | awk -F'=' '{ print tolower($2) }')
  44. case $HDISTRO in
  45. ubuntu) PKGINSTALL="apt-get install -q -y "
  46. echo "Ubuntu detected."
  47. ;;
  48. debian) PKGINSTALL="apt-get install -q -y "
  49. echo "Debian detected."
  50. ;;
  51. fedora) PKGINSTALL="yum install -q -y "
  52. echo "Fedora detected."
  53. ;;
  54. *) echo "SADIE cannot determine what Linux distribution you are using."
  55. echo "Without this, it cannot install any missing utilities. Exiting."
  56. exit 1
  57. ;;
  58. esac
  59. echo "Stage 2: Check for essential utilities"
  60. echo ""
  61. for i in dialog make gcc wget unzip; do
  62. if ! hash $i &> /dev/null ; then
  63. echo "$i not found. Now installing; please wait a moment."
  64. $($PKGINSTALL $i)
  65. else
  66. echo "$i is installed."
  67. fi
  68. done
  69. echo ""
  70. echo "Stage 3: Check for rkflashtool"
  71. if ! hash rkflashtool &> /dev/null ; then
  72. echo "rkflashtool not found. Must be compiled and installed. Please wait..."
  73. git clone https://github.com/ayufan-rock64/rkflashtool
  74. make -C rkflashtool
  75. make -C rkflashtool install
  76. else
  77. echo "rkflashtool detected."
  78. fi
  79. OPTIONS=(1 "Android 'Desktop' (currently unstable)"
  80. 2 "Android TV (Recommended)")
  81.  
  82. CHOICE=$(dialog --clear \
  83. --backtitle "$BACKTITLE" \
  84. --title "Android Image Selection" \
  85. --menu "$MENU" \
  86. $HEIGHT $WIDTH $CHOICE_HEIGHT \
  87. "${OPTIONS[@]}" \
  88. 2>&1 >/dev/tty)
  89.  
  90. case $CHOICE in
  91. 1)
  92. IMAGETYPE="desktop"
  93. clear
  94. IMAGEURL=$(wget fire219.kotori.me/sadie/desktop-image.txt -q -O -)
  95. ;;
  96. 2)
  97. IMAGETYPE="box"
  98. clear
  99. IMAGEURL=$(wget fire219.kotori.me/sadie/box-image.txt -q -O -)
  100. ;;
  101. esac
  102.  
  103. IMAGEFILEREL="${IMAGEURL##*/}"
  104. IMAGEFILE=$(pwd)"/${IMAGEURL##*/}"
  105.  
  106. if [ -e "$IMAGEFILE" ] ; then
  107. dialog --clear \
  108. --backtitle "$BACKTITLE" \
  109. --title "Image already downloaded." \
  110. --msgbox "SADIE has detected that the latest image zip was previously downloaded. Continuing with existing image." \
  111. 10 60 \
  112. 2>&1 >/dev/tty
  113.  
  114. else
  115. dialog --clear \
  116. --backtitle "$BACKTITLE" \
  117. --title "Download Confirmation" \
  118. --msgbox "SADIE will now download the selected image. This may take some time, depending on your connection speed." \
  119. 10 60 \
  120. 2>&1 >/dev/tty
  121.  
  122. clear
  123. echo "Please wait while this download completes."
  124. wget -nv --show-progress "$IMAGEURL"
  125. fi
  126. dialog --backtitle "$BACKTITLE" --title "Please Wait..." --infobox "Preparing Scripts..." 10 60
  127. if [ ! -e /usr/local/bin/rkinstall ] ; then
  128. wget fire219.kotori.me/sadie/rkinstall -q
  129. mv rkinstall /usr/local/bin/rkinstall
  130. chmod +x /usr/local/bin/rkinstall
  131. fi
  132. dialog --backtitle "$BACKTITLE" --title "Please Wait..." --infobox "Unzipping image..." 10 60
  133. IMAGEDIR="${IMAGEFILE%.*}"
  134. if [ -d $IMAGEDIR ] ; then
  135. rm -r $IMAGEDIR
  136. fi
  137. unzip -qq $IMAGEFILEREL
  138.  
  139. clear
  140. echo "===Loader Mode Instructions==="
  141. echo ""
  142. echo "To flash Android onto your Rock64, it must be put into Loader Mode."
  143. echo ""
  144. echo "This is accomplished by the following steps with power plugged in to the board:"
  145. echo ""
  146. echo "1. Remove the eMMC jumper near the Recovery button. Do not lose it."
  147. echo "2. Press and hold the Reset Button."
  148. echo "3. While still holding Reset, press and hold the Recovery Button."
  149. echo "4. Release the Reset Button, but keep holding Recovery for at least three seconds."
  150. echo ""
  151. echo "WARNING: IF YOU HAVE AN SD CARD PLUGGED IN, IT WILL BE OVERWRITTEN INSTEAD AND"
  152. echo "ALL DATA ON THE CARD WILL BE LOST."
  153. echo ""
  154. read -rsp $'Press any key to continue...\n' -n 1 key
  155.  
  156. rkflashtool n &> temprk
  157. if grep "interface claimed" temprk ; then
  158. echo "Rock64 confirmed to be in Loader Mode!"
  159. else
  160. loadermode="unready"
  161. while [ "$loadermode" = "unready" ] ; do
  162. echo "Rock64 is not in Loader Mode. Please follow the steps and try again."
  163. read -rsp $'Press any key...\n' -n 1 key
  164. rkflashtool n &> temprk
  165. if grep "interface claimed" temprk > /dev/null ; then
  166. echo "Rock64 confirmed to be in Loader Mode!"
  167. loadermode="ready"
  168. fi
  169. done
  170. fi
  171.  
  172. if (dialog --backtitle "$BACKTITLE" --title "Ready to Flash" --yesno "SADIE is ready to flash Android onto your Rock64. Continue?" 20 60) then
  173. cd $IMAGEDIR
  174. rkinstall
  175. else
  176. echo "Exiting without flashing."
  177. fi
  178. echo ""
  179. echo "Flash is complete! Your Rock64 now should be booting into Android! It will take some time for it to boot first time."
  180. echo "Enjoy your system. :)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement