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.3KB

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