media-suite_update.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. #!/bin/bash
  2. # shellcheck disable=SC2086
  3. while true; do
  4. case $1 in
  5. --build32=*)
  6. build32="${1#*=}"
  7. shift
  8. ;;
  9. --build64=*)
  10. build64="${1#*=}"
  11. shift
  12. ;;
  13. --update=*)
  14. update="${1#*=}"
  15. shift
  16. ;;
  17. --CC=*)
  18. CC="${1#*=}"
  19. shift
  20. ;;
  21. --)
  22. shift
  23. break
  24. ;;
  25. -*)
  26. echo "Error, unknown option: '$1'."
  27. exit 1
  28. ;;
  29. *) break ;;
  30. esac
  31. done
  32. [[ "$(uname)" == *6.1* ]] && nargs="-n 4"
  33. # start suite update
  34. if [[ -d "/trunk/build" ]]; then
  35. cd "/trunk/build" || exit 1
  36. else
  37. cd "$(cygpath -w /)../build" || exit 1
  38. fi
  39. [[ -f media-suite_helper.sh ]] && source media-suite_helper.sh
  40. [[ -f media-suite_deps.sh ]] && source media-suite_deps.sh
  41. do_pacman_remove -m mercurial
  42. # --------------------------------------------------
  43. # update suite
  44. # --------------------------------------------------
  45. if [[ $update == "yes" ]]; then
  46. echo
  47. echo "-------------------------------------------------------------------------------"
  48. echo "checking if suite has been updated..."
  49. echo "-------------------------------------------------------------------------------"
  50. echo
  51. if [[ ! -d ../.git ]] && command -v git > /dev/null; then
  52. if ! git clone "${SOURCE_REPO_MABS:-https://github.com/m-ab-s/media-autobuild_suite.git}" ab-git; then
  53. git -C ab-git fetch
  54. fi
  55. cp -fr ab-git/.git ..
  56. fi
  57. cd_safe ..
  58. if [[ -d .git ]]; then
  59. if [[ -n "$(git diff --name-only)" ]]; then
  60. diffname="$(date +%F-%H.%M.%S)"
  61. git diff --diff-filter=M >> "build/user-changes-${diffname}.diff"
  62. echo "Your changes have been exported to build/user-changes-${diffname}.diff."
  63. git reset --hard "@{upstream}"
  64. fi
  65. git fetch -t
  66. oldHead=$(git rev-parse HEAD)
  67. git reset --hard "@{upstream}"
  68. newHead=$(git rev-parse HEAD)
  69. if [[ $oldHead != "$newHead" ]]; then
  70. echo "Suite has been updated!"
  71. echo "If you had an issue try running the suite again before reporting."
  72. else
  73. echo "Suite up-to-date."
  74. echo "If you had an issue, please report it in GitHub."
  75. fi
  76. read -r -t 15 -p '<Enter> to close' ret
  77. fi
  78. fi # end suite update
  79. # --------------------------------------------------
  80. # packet update system
  81. # --------------------------------------------------
  82. # remove buggy crap
  83. grep -q abrepo /etc/pacman.conf && sed -i '/abrepo/d' /etc/pacman.conf
  84. rm -f /etc/pacman.d/abrepo.conf
  85. rm -rf /opt/cargo/bin
  86. echo
  87. echo "-------------------------------------------------------------------------------"
  88. echo "Updating pacman database..."
  89. echo "-------------------------------------------------------------------------------"
  90. echo
  91. pacman -Sy --ask=20 --noconfirm
  92. { pacman -Qqe | grep -q sed && pacman -Qqg base | pacman -D --asdeps - && pacman -D --asexplicit mintty flex; } > /dev/null
  93. do_unhide_all_sharedlibs
  94. # make sure that pacutils is always installed for pacsift
  95. { pacman -Qq pacutils || pacman -S --needed --noconfirm pacutils; } > /dev/null 2>&1
  96. extract_pkg_prefix() (
  97. case $1 in
  98. *32) [[ $build32 != "yes" ]] && return 1 ;;
  99. *64) [[ $build64 != "yes" ]] && return 1 ;;
  100. esac
  101. . shell "$1"
  102. echo "$MINGW_PACKAGE_PREFIX-"
  103. )
  104. if [[ -f /etc/pac-base.pk && -f /etc/pac-mingw.pk ]]; then
  105. new=$(mktemp)
  106. old=$(mktemp)
  107. echo
  108. echo "-------------------------------------------------------------------------------"
  109. echo "Checking pacman packages..."
  110. echo "-------------------------------------------------------------------------------"
  111. echo
  112. dos2unix -O /etc/pac-base.pk 2> /dev/null | sort -u >> "$new"
  113. mapfile -t newmingw < <(dos2unix -O /etc/pac-mingw.pk /etc/pac-mingw-extra.pk 2>/dev/null | sort -u)
  114. mapfile -t newmsys < <(dos2unix -O /etc/pac-msys-extra.pk 2> /dev/null | sort -u)
  115. prefix_32='' prefix_64=''
  116. case $CC in
  117. *clang*) prefix_32=$(extract_pkg_prefix clang32) prefix_64=$(extract_pkg_prefix clang64) ;;
  118. *) prefix_32=$(extract_pkg_prefix mingw32) prefix_64=$(extract_pkg_prefix mingw64) ;;
  119. esac
  120. for pkg in "${newmingw[@]}"; do
  121. if [[ $build32 == "yes" ]] &&
  122. pacman -Ss "$prefix_32$pkg" > /dev/null 2>&1; then
  123. printf %s\\n "$prefix_32$pkg" >> "$new"
  124. fi
  125. if [[ $build64 == "yes" ]] &&
  126. pacman -Ss "$prefix_64$pkg" > /dev/null 2>&1; then
  127. printf %s\\n "$prefix_64$pkg" >> "$new"
  128. fi
  129. done
  130. for pkg in "${newmsys[@]}"; do
  131. pacman -Ss "^${pkg}$" > /dev/null 2>&1 && printf %s\\n "$pkg" >> "$new"
  132. done
  133. pacman -Qqe | sort -u >> "$old"
  134. sort -uo "$new"{,}
  135. # mapfile -t new < <(printf %s\\n "${new[@]}" | sort -u)
  136. mapfile -t install < <(diff --changed-group-format='%>' --unchanged-group-format='' "$old" "$new")
  137. mapfile -t uninstall < <(diff --changed-group-format='%<' --unchanged-group-format='' "$old" "$new")
  138. if [[ ${#uninstall[@]} -gt 0 ]]; then
  139. echo
  140. echo "-------------------------------------------------------------------------------"
  141. echo "You have more packages than needed!"
  142. echo "Do you want to remove them?"
  143. echo "-------------------------------------------------------------------------------"
  144. echo
  145. echo "Remove:"
  146. echo "${uninstall[*]}"
  147. while true; do
  148. read -r -p "remove packs [y/n]? " yn
  149. case $yn in
  150. [Yy]*)
  151. pacman -Rs --noconfirm "${uninstall[@]}" >&2 2> /dev/null
  152. for pkg in "${uninstall[@]}"; do
  153. pacman -Qs "^${pkg}$" && pacman -D --noconfirm --asdeps "$pkg" > /dev/null
  154. done
  155. break
  156. ;;
  157. [Nn]*)
  158. pacman --noconfirm -D --asdeps "${uninstall[@]}"
  159. break
  160. ;;
  161. *) echo "Please answer yes or no" ;;
  162. esac
  163. done
  164. fi
  165. if [[ ${#install[@]} -gt 0 ]]; then
  166. echo "You're missing some packages!"
  167. echo "Proceeding with installation..."
  168. pacman -Sw --noconfirm --needed "${install[@]}"
  169. pacman -S --noconfirm --needed "${install[@]}"
  170. pacman -D --asexplicit "${install[@]}"
  171. fi
  172. rm -f /etc/pac-{base,mingw}.pk "$new" "$old"
  173. fi
  174. if [[ -d "/trunk" ]]; then
  175. cd "/trunk" || exit 1
  176. else
  177. cd_safe "$(cygpath -w /).."
  178. fi
  179. # --------------------------------------------------
  180. # packet msys2 system
  181. # --------------------------------------------------
  182. have_updates="$(pacman -Qu | grep -v ignored]$ | cut -d' ' -f1)"
  183. if [[ -n $have_updates ]]; then
  184. echo "-------------------------------------------------------------------------------"
  185. echo "Updating msys2 system and installed packages..."
  186. echo "-------------------------------------------------------------------------------"
  187. /usr/bin/grep -Eq '^(pacman|bash|msys2-runtime)$' <<< "$have_updates" &&
  188. touch /build/update_core &&
  189. have_updates="$(/usr/bin/grep -Ev '^(pacman|bash|msys2-runtime)$' <<< "$have_updates")"
  190. xargs $nargs pacman -S --noconfirm --overwrite "/mingw64/*" \
  191. --overwrite "/mingw32/*" --overwrite "/usr/*" <<< "$have_updates"
  192. fi
  193. [[ ! -s /usr/ssl/certs/ca-bundle.crt ]] &&
  194. pacman -S --noconfirm --asdeps ca-certificates
  195. # do a final overall installation for potential downgrades
  196. pacman -Syuu --noconfirm --overwrite "/mingw64/*" \
  197. --overwrite "/mingw32/*" --overwrite "/usr/*"
  198. do_hide_all_sharedlibs
  199. echo "-------------------------------------------------------------------------------"
  200. echo "Updates finished."
  201. echo "-------------------------------------------------------------------------------"
  202. sleep 2
  203. exit