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.

ezsync 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. export LC_ALL="C"
  84. trap 'die "Process killed! This may lead into unexpected problems!"' 1 2 3 9 15 17 18 23
  85. # Load necessary public keys
  86. printInfo "Loading public keys..."
  87. eval `keychain --noask --eval id_dsa id_rsa &> /dev/null`
  88. [ ${?} -ne 0 ] && die "EzBuild was unable to load public keys!" 1
  89. # Execute all 'presync' enabled modules
  90. for MODULE in ${MODULES_PRESYNC}; do
  91. loadModule ${MODULE} "presync"
  92. RESULT=${?}
  93. if [ ${RESULT} -eq 255 ]; then
  94. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: presync!"
  95. elif [ ${RESULT} -ne 0 ]; then
  96. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  97. fi
  98. unloadModule
  99. done
  100. # Update local copy of Portage that is being built
  101. printInfo "Refreshing constructed Portage tree..."
  102. pullRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} ${PORTAGE_BUILD[2]} ${PORTAGE_BUILD[3]}
  103. [ ${?} -ne 0 ] && die "EzBuild was unable to refresh local copy of constructed Portage tree!" 2
  104. # Update local copy of mainline Portage
  105. if ! hasElement "mainline" ${EZNOSYNC} && ! hasElement "portage" ${EZNOSYNC}; then
  106. printInfo "Refreshing mainline Portage tree..."
  107. pullRepository ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]} ${PORTAGE_MAINLINE[1]} ${PORTAGE_MAINLINE[2]} ${PORTAGE_MAINLINE[3]}
  108. [ ${?} -ne 0 ] && die "EzBuild was unable to refresh local copy of mainline Portage tree!" 2
  109. [ -e ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/cache ] && rm -rf ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/metadata/cache
  110. echo "distfiles/*" > ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/.gitignore
  111. echo "packages/*" >> ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/.gitignore
  112. if [ ! -d ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask ]; then
  113. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask.bak &> /dev/null
  114. makeDirectory ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask
  115. mv ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask.bak ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/profiles/package.mask/${PORTAGE_MAINLINE[0]%-*} &> /dev/null
  116. fi
  117. fi
  118. # Update all overlays (including the one that's optionally going to be built)
  119. SYNC_OVERLAYS=( ${MERGED_OVERLAY[*]} ${MERGED_PORTAGE[*]} )
  120. for OVERLAY in ${SYNC_OVERLAYS[*]}; do
  121. TEMP="\${$OVERLAY[*]}"
  122. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  123. if ! hasElement "${CURRENT_OVERLAY[0]}" ${EZNOSYNC}; then
  124. printInfo "Refreshing overlay: ${CURRENT_OVERLAY[0]}..."
  125. pullRepository ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${CURRENT_OVERLAY[1]} ${CURRENT_OVERLAY[2]} ${CURRENT_OVERLAY[3]}
  126. [ ${?} -ne 0 ] && fail "EzBuild was unable to refresh local copy of overlay: ${CURRENT_OVERLAY[0]}!" 4
  127. fi
  128. done
  129. # Execute all 'postsync' enabled modules
  130. for MODULE in ${MODULES_POSTSYNC}; do
  131. loadModule ${MODULE} "postsync"
  132. RESULT=${?}
  133. if [ ${RESULT} -eq 255 ]; then
  134. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postsync!"
  135. elif [ ${RESULT} -ne 0 ]; then
  136. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  137. fi
  138. unloadModule
  139. done
  140. # Optionally merge data into build overlay
  141. if isSet MERGED_OVERLAY && isSet OVERLAY_BUILD; then
  142. printInfo "Merging ebuilds into Overlay..."
  143. for OVERLAY in ${MERGED_OVERLAY[*]}; do
  144. TEMP="\${$OVERLAY[*]}"
  145. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  146. mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
  147. [ ${?} -ne 0 ] && fail "EzBuild was unable to merge ebuilds into overlay!" 8
  148. done
  149. if ! isEnabled ${EZOPT_NOPUSH}; then
  150. pushRepository ${OVERLAYSDIR}/${OVERLAY_BUILD[0]} ${OVERLAY_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
  151. [ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote overlay repository!" 8
  152. fi
  153. fi
  154. # Merge data into build portage
  155. printInfo "Merging ebuilds into Portage..."
  156. pullRsync ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGESDIR}/${PORTAGE_MAINLINE[0]}/
  157. [ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
  158. for OVERLAY in ${MERGED_PORTAGE[*]}; do
  159. TEMP="\${$OVERLAY[*]}"
  160. CURRENT_OVERLAY=(`eval echo ${TEMP}`)
  161. mergeOverlay ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]} ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${CURRENT_OVERLAY[4]} ${CURRENT_OVERLAY[5]} ${CURRENT_OVERLAY[6]}
  162. [ ${?} -ne 0 ] && die "EzBuild was unable to merge ebuilds into Portage tree!" 16
  163. if [ -f ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ]; then
  164. run "cp -apf ${OVERLAYSDIR}/${CURRENT_OVERLAY[0]}/profiles/package.mask ${PORTAGESDIR}/${PORTAGE_BUILD[0]}/profiles/package.mask/${CURRENT_OVERLAY[0]%-*}"
  165. [ ${?} -ne 0 ] && die "EzBuild was unable to merge package.mask file into Portage tree!" 16
  166. fi
  167. done
  168. # Execute all 'precommit' enabled modules
  169. for MODULE in ${MODULES_PRECOMMIT}; do
  170. loadModule ${MODULE} "precommit"
  171. RESULT=${?}
  172. if [ ${RESULT} -eq 255 ]; then
  173. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: precommit!"
  174. elif [ ${RESULT} -ne 0 ]; then
  175. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  176. fi
  177. unloadModule
  178. done
  179. # Regenerate Portage cache
  180. printInfo "Updating constructed Portage cache..."
  181. run "FEATURES="metadata-transfer" PORTDIR="${PORTAGESDIR}/${PORTAGE_BUILD[0]}" egencache --update --portdir=${PORTAGESDIR}/${PORTAGE_BUILD[0]} --jobs=${MAXJOBS} --load-average=${LOADAVERAGE} --tolerant"
  182. [ ${?} -ne 0 ] && die "EzBuild was unable to regenerate cache!" 32
  183. # Optionally commit all changes to remote Portage repository
  184. if ! isEnabled ${EZOPT_NOPUSH}; then
  185. printInfo "Sending constructed Portage update..."
  186. pushRepository ${PORTAGESDIR}/${PORTAGE_BUILD[0]} ${PORTAGE_BUILD[1]} "Automatic update [$(date +"${PUSHDATEFORMAT}")]."
  187. [ ${?} -ne 0 ] && die "Ezbuild was unable to record changes to the remote Portage repository!" 64
  188. fi
  189. # Execute all 'postcommit' enabled modules
  190. for MODULE in ${MODULES_POSTCOMMIT}; do
  191. loadModule ${MODULE} "postcommit"
  192. RESULT=${?}
  193. if [ ${RESULT} -eq 255 ]; then
  194. printWarn "Trying to load module: ${MODULE}, that is incompatible with event: postcommit!"
  195. elif [ ${RESULT} -ne 0 ]; then
  196. fail "EzBuild was unable to execute module: ${MODULE}!" 255
  197. fi
  198. unloadModule
  199. done
  200. # Finally quit the application
  201. quit