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.

260 lines
10 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
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. -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. if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask ]; then
  131. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask.bak &> /dev/null
  132. makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask
  133. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.unmask/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
  134. fi
  135. if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use ]; then
  136. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use.bak &> /dev/null
  137. makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use
  138. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.use/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
  139. fi
  140. fi
  141. # Update all overlays (including the one that's optionally going to be built)
  142. SYNC_OVERLAYS=( ${MERGED_OVERLAY[*]} ${MERGED_PORTAGE[*]} )
  143. for OVERLAY in ${SYNC_OVERLAYS[*]}; do
  144. TEMP="\${$OVERLAY[*]}"
  145. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  146. if ! hasElement "${CURRENT_OVERLAY[0]}" ${EZNOSYNC}; then
  147. printInfo "Refreshing overlay: ${CURRENT_OVERLAY[0]}..."
  148. pullRepository ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${CURRENT_OVERLAY[1]} ${CURRENT_OVERLAY[2]} ${CURRENT_OVERLAY[3]}
  149. [ ${?} -ne 0 ] && fail "EzBuild was unable to refresh local copy of overlay: ${CURRENT_OVERLAY[0]}!" 4
  150. fi
  151. done
  152. # Execute all 'postsync' enabled modules
  153. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  154. for MODULE in ${MODULES_POSTSYNC}; do
  155. loadModule ${MODULE} "postsync"
  156. RESULT=${?}
  157. if [ ${RESULT} -eq 255 ]; then
  158. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postsync!"
  159. elif [ ${RESULT} -ne 0 ]; then
  160. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  161. fi
  162. unloadModule
  163. done
  164. fi
  165. # Optionally merge data into build overlay
  166. if isSet MERGED_OVERLAY && isSet OVERLAY_BUILD; then
  167. printInfo "Merging ebuilds into Overlay..."
  168. for OVERLAY in ${MERGED_OVERLAY[*]}; do
  169. TEMP="\${$OVERLAY[*]}"
  170. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  171. mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
  172. [ ${?} -ne 0 ] && fail "EzBuild was unable to merge ebuilds into overlay!" 8
  173. done
  174. if ! isEnabled ${EZOPT_NOPUSH}; then
  175. pushRepository ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${OVERLAY_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
  176. [ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote overlay repository!" 8
  177. fi
  178. fi
  179. # Merge data into build portage
  180. printInfo "Merging ebuilds into Portage..."
  181. pullRsync ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/
  182. [ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
  183. for OVERLAY in ${MERGED_PORTAGE[*]}; do
  184. TEMP="\${$OVERLAY[*]}"
  185. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  186. mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
  187. [ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
  188. if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ]; then
  189. run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.mask/${CURRENT_OVERLAY[0]%-*}"
  190. [ ${?} -ne 0 ] && die "EzBuild was unable to merge package.mask file into Portage tree!" 16
  191. fi
  192. if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.unmask ]; then
  193. run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.unmask ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.unmask/${CURRENT_OVERLAY[0]%-*}"
  194. [ ${?} -ne 0 ] && die "EzBuild was unable to merge package.unmask file into Portage tree!" 16
  195. fi
  196. if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.use ]; then
  197. run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.use ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.use/${CURRENT_OVERLAY[0]%-*}"
  198. [ ${?} -ne 0 ] && die "EzBuild was unable to merge package.use file into Portage tree!" 16
  199. fi
  200. done
  201. # Execute all 'precommit' enabled modules
  202. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  203. for MODULE in ${MODULES_PRECOMMIT}; do
  204. loadModule ${MODULE} "precommit"
  205. RESULT=${?}
  206. if [ ${RESULT} -eq 255 ]; then
  207. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: precommit!"
  208. elif [ ${RESULT} -ne 0 ]; then
  209. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  210. fi
  211. unloadModule
  212. done
  213. fi
  214. # Regenerate Portage cache
  215. printInfo "Updating constructed Portage cache..."
  216. run "FEATURES="metadata-transfer" PORTDIR="${PORTAGESDIR}/${PORTAGE_BUILD[0]}" egencache --update --portdir=${PORTAGESDIR}/${PORTAGE_BUILD[0]} --jobs=${MAXJOBS} --load-average=${LOADAVERAGE} --tolerant"
  217. [ ${?} -ne 0 ] && die "EzBuild was unable to regenerate cache!" 32
  218. # Optionally commit all changes to remote Portage repository
  219. if ! isEnabled ${EZOPT_NOPUSH}; then
  220. printInfo "Sending constructed Portage update..."
  221. pushRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
  222. [ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote Portage repository!" 64
  223. fi
  224. # Execute all 'postcommit' enabled modules
  225. if ! isEnabled ${EZOPT_NOTRIGGER}; then
  226. for MODULE in ${MODULES_POSTCOMMIT}; do
  227. loadModule ${MODULE} "postcommit"
  228. RESULT=${?}
  229. if [ ${RESULT} -eq 255 ]; then
  230. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postcommit!"
  231. elif [ ${RESULT} -ne 0 ]; then
  232. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  233. fi
  234. unloadModule
  235. done
  236. fi
  237. # Finally quit the application
  238. quit