reGen2 Linux Release Metatool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
8.5 KiB

  1. #!/bin/bash
  2. # Copyright 2010-2012, Asio Software Technologies
  3. # Distributed under the terms of the GNU General Public License v3
  4. # Declare basic system variables
  5. EZNAME=$(basename ${0})
  6. EZROOT=$(dirname $(readlink -ne ${0}))
  7. # Load necessary files
  8. source /etc/profile
  9. source ${EZROOT}/libraries/common
  10. # Load EzBuild libraries & configuration
  11. loadLibraries
  12. loadConfiguration
  13. # Print EzBuild notice and parse arguments
  14. printNotice
  15. until [[ -z "${1}" ]]; do
  16. case "${1}" in
  17. -c|--cleanlog)
  18. EZOPT_CLEANLOG=true
  19. ;;
  20. -D|--tarballdate)
  21. shift
  22. if [ -z ${1} ]; then
  23. die "--tarballdate requires an additional argument!"
  24. else
  25. TARBALLDATE="${1}"
  26. fi
  27. ;;
  28. -h|--help)
  29. showEzsyncUsage
  30. ;;
  31. -l|--listmods)
  32. listModules
  33. ;;
  34. -n|--nosync)
  35. shift
  36. if [ -z ${1} ]; then
  37. die "--nosync requires an additional argument!"
  38. else
  39. EZNOSYNC=${EZNOSYNC+"$EZNOSYNC "}"${1}"
  40. fi
  41. ;;
  42. -N|--nopush)
  43. EZOPT_NOPUSH=true
  44. ;;
  45. -p|--purge)
  46. EZOPT_PURGETMP=true
  47. ;;
  48. -P|--purgeonly)
  49. EZOPT_PURGETMP=true
  50. EZOPT_PURGEONLY=true
  51. ;;
  52. -s|--syscheck)
  53. EZOPT_SYSCHECKONLY=true
  54. ;;
  55. -t|--notrigger)
  56. EZOPT_NOTRIGGER=true
  57. ;;
  58. *)
  59. die "Unrecognized option ${1}"
  60. ;;
  61. esac
  62. shift
  63. done
  64. # Check system requirements
  65. printInfo "Checking system prerequisites..."
  66. checkPrerequisites
  67. [ ${?} -ne 0 ] && die "Your environment does not meet EzBuild requirements!" 1
  68. if isEnabled ${EZOPT_SYSCHECKONLY}; then
  69. printInfo "Your system meets all EzBuild requirements!"
  70. quit
  71. fi
  72. # Do not allow more than one working copy
  73. PID=$(pidof -s -o '%PPID' -x ${EZNAME})
  74. if [ ${PID} ]; then
  75. printWarn "The ${EZNAME} is already working with PID: ${PID}"
  76. printWarn "You cannot have more than one instancy running"
  77. exit 0
  78. fi
  79. # Optionally purge whole temp directory or log file only
  80. if isEnabled ${EZOPT_PURGETMP}; then
  81. printInfo "Clearing temp directory..."
  82. cleanTemp
  83. if isEnabled ${EZOPT_PURGEONLY}; then
  84. quit
  85. fi
  86. elif isEnabled ${EZOPT_CLEANLOG}; then
  87. printInfo "Clearing log file..."
  88. cleanLog
  89. fi
  90. # Initialize EzBuild environment
  91. makeCoreDirectories || die "EzBuild was unable to create all necessary directories!" 1
  92. EZNOTIFY="yes"
  93. prepareWrappers || die "EzBuild was unable to create a wrapper files!" 1
  94. export LC_ALL="C"
  95. trap 'die "Process killed! This may lead into unexpected problems!"' 1 2 3 9 15 17 18 23
  96. # Load necessary public keys
  97. printInfo "Loading public keys..."
  98. eval `keychain --noask --eval id_dsa id_rsa &> /dev/null`
  99. [ ${?} -ne 0 ] && die "EzBuild was unable to load public keys!" 1
  100. # Execute all 'presync' enabled modules
  101. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  102. for MODULE in ${MODULES_PRESYNC}; do
  103. loadModule ${MODULE} "presync"
  104. RESULT=${?}
  105. if [ ${RESULT} -eq 255 ]; then
  106. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: presync!"
  107. elif [ ${RESULT} -ne 0 ]; then
  108. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  109. fi
  110. unloadModule
  111. done
  112. fi
  113. # Update local copy of Portage that is being built
  114. printInfo "Refreshing constructed Portage tree..."
  115. pullRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} ${PORTAGE_BUILD[2]} ${PORTAGE_BUILD[3]}
  116. [ ${?} -ne 0 ] && die "EzBuild was unable to refresh local copy of constructed Portage tree!" 2
  117. # Update local copy of mainline Portage
  118. if ! hasElement "mainline" ${EZNOSYNC} && ! hasElement "portage" ${EZNOSYNC}; then
  119. printInfo "Refreshing mainline Portage tree..."
  120. pullRepository ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]} ${PORTAGE_MAINLINE[1]} ${PORTAGE_MAINLINE[2]} ${PORTAGE_MAINLINE[3]}
  121. [ ${?} -ne 0 ] && die "EzBuild was unable to refresh local copy of mainline Portage tree!" 2
  122. [ -e ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/cache ] && rm -rf ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/cache
  123. echo "distfiles/*" > ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/.gitignore
  124. echo "packages/*" >> ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/.gitignore
  125. if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask ]; then
  126. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask.bak &> /dev/null
  127. makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask
  128. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
  129. fi
  130. fi
  131. # Update all overlays (including the one that's optionally going to be built)
  132. SYNC_OVERLAYS=( ${MERGED_OVERLAY[*]} ${MERGED_PORTAGE[*]} )
  133. for OVERLAY in ${SYNC_OVERLAYS[*]}; do
  134. TEMP="\${$OVERLAY[*]}"
  135. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  136. if ! hasElement "${CURRENT_OVERLAY[0]}" ${EZNOSYNC}; then
  137. printInfo "Refreshing overlay: ${CURRENT_OVERLAY[0]}..."
  138. pullRepository ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${CURRENT_OVERLAY[1]} ${CURRENT_OVERLAY[2]} ${CURRENT_OVERLAY[3]}
  139. [ ${?} -ne 0 ] && fail "EzBuild was unable to refresh local copy of overlay: ${CURRENT_OVERLAY[0]}!" 4
  140. fi
  141. done
  142. # Execute all 'postsync' enabled modules
  143. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  144. for MODULE in ${MODULES_POSTSYNC}; do
  145. loadModule ${MODULE} "postsync"
  146. RESULT=${?}
  147. if [ ${RESULT} -eq 255 ]; then
  148. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postsync!"
  149. elif [ ${RESULT} -ne 0 ]; then
  150. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  151. fi
  152. unloadModule
  153. done
  154. fi
  155. # Optionally merge data into build overlay
  156. if isSet MERGED_OVERLAY && isSet OVERLAY_BUILD; then
  157. printInfo "Merging ebuilds into Overlay..."
  158. for OVERLAY in ${MERGED_OVERLAY[*]}; do
  159. TEMP="\${$OVERLAY[*]}"
  160. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  161. mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
  162. [ ${?} -ne 0 ] && fail "EzBuild was unable to merge ebuilds into overlay!" 8
  163. done
  164. if ! isEnabled ${EZOPT_NOPUSH}; then
  165. pushRepository ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${OVERLAY_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
  166. [ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote overlay repository!" 8
  167. fi
  168. fi
  169. # Merge data into build portage
  170. printInfo "Merging ebuilds into Portage..."
  171. pullRsync ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/
  172. [ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
  173. for OVERLAY in ${MERGED_PORTAGE[*]}; do
  174. TEMP="\${$OVERLAY[*]}"
  175. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  176. mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
  177. [ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
  178. if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ]; then
  179. run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.mask/${CURRENT_OVERLAY[0]%-*}"
  180. [ ${?} -ne 0 ] && die "EzBuild was unable to merge package.mask file into Portage tree!" 16
  181. fi
  182. done
  183. # Execute all 'precommit' enabled modules
  184. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  185. for MODULE in ${MODULES_PRECOMMIT}; do
  186. loadModule ${MODULE} "precommit"
  187. RESULT=${?}
  188. if [ ${RESULT} -eq 255 ]; then
  189. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: precommit!"
  190. elif [ ${RESULT} -ne 0 ]; then
  191. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  192. fi
  193. unloadModule
  194. done
  195. fi
  196. # Regenerate Portage cache
  197. printInfo "Updating constructed Portage cache..."
  198. run "FEATURES="metadata-transfer" PORTDIR="${PORTAGESDIR}/${PORTAGE_BUILD[0]}" egencache --update --portdir=${PORTAGESDIR}/${PORTAGE_BUILD[0]} --jobs=${MAXJOBS} --load-average=${LOADAVERAGE} --tolerant"
  199. [ ${?} -ne 0 ] && die "EzBuild was unable to regenerate cache!" 32
  200. # Optionally commit all changes to remote Portage repository
  201. if ! isEnabled ${EZOPT_NOPUSH}; then
  202. printInfo "Sending constructed Portage update..."
  203. pushRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
  204. [ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote Portage repository!" 64
  205. fi
  206. # Execute all 'postcommit' enabled modules
  207. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  208. for MODULE in ${MODULES_POSTCOMMIT}; do
  209. loadModule ${MODULE} "postcommit"
  210. RESULT=${?}
  211. if [ ${RESULT} -eq 255 ]; then
  212. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postcommit!"
  213. elif [ ${RESULT} -ne 0 ]; then
  214. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  215. fi
  216. unloadModule
  217. done
  218. fi
  219. # Finally quit the application
  220. quit