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.

221 lines
8.0 KiB

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