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.

filesystem 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #!/bin/bash
  2. # Copyright 2010-2012, Asio Software Technologies
  3. # Distributed under the terms of the GNU General Public License v3
  4. #-------------------------------------------------------------------------------
  5. # Applies a diff file to an original
  6. # Parameters: %original_dir% %patch%
  7. #-------------------------------------------------------------------------------
  8. function applyPatch() {
  9. local DESTDIR="${1}"
  10. local PATCH="${2}"
  11. local PREFIX
  12. for PREFIX in {0..4}; do
  13. if run "patch -d ${DESTDIR} --dry-run -p ${PREFIX} -i ${PATCH} -s"; then
  14. run "patch -d ${DESTDIR} -p ${PREFIX} -i ${PATCH}" && return 0
  15. fi
  16. done
  17. return 1
  18. }
  19. #-------------------------------------------------------------------------------
  20. # Completely removes log file
  21. #-------------------------------------------------------------------------------
  22. function cleanLog() {
  23. rm -rf ${LOGFILE} &> /dev/null
  24. }
  25. #-------------------------------------------------------------------------------
  26. # Completely removes whole temp directory
  27. #-------------------------------------------------------------------------------
  28. function cleanTemp() {
  29. rm -rf ${STOREDIR} &> /dev/null
  30. }
  31. #-------------------------------------------------------------------------------
  32. # Downloads files into specified or current directory
  33. # Parameters: %url% [%dest_directory%]
  34. #-------------------------------------------------------------------------------
  35. function download() {
  36. local DEST FILENAME RESULT URL
  37. DEST="${2}"
  38. FILENAME="${1##*/}"
  39. URL="${1}"
  40. if isSet DEST; then
  41. DEST="${DEST}/${FILENAME}"
  42. else
  43. DEST="./${FILENAME}"
  44. fi
  45. logMessage "Downloading ${URL} to ${DEST}" "DEBUG"
  46. echo -ne " ${STAR_GREEN} ${FILENAME}: "
  47. wget --progress=dot -c -t ${FETCHTRIES} -T ${FETCHTIMEOUT} -O "${DEST}" \
  48. ${URL} 2>&1 | grep --line-buffered "%" | sed -u -e "s/[\.\,]//g" | \
  49. awk '{printf("\b\b\b\b%4s", $2)}'
  50. RESULT=${PIPESTATUS[0]}
  51. echo -ne "\b\b\b\b"
  52. if [ ${RESULT} -ne 0 ]; then
  53. logOutput "Unable to download ${URL}! Exit code: ${RESULT}"
  54. echo -e "${COLOR_RED}${COLOR_BOLD}ERROR${COLOR_WHITE}${COLOR_NORMAL}"
  55. else
  56. echo -e "${COLOR_GREEN}${COLOR_BOLD}DONE${COLOR_WHITE}${COLOR_NORMAL}"
  57. fi
  58. return ${RESULT}
  59. }
  60. #-------------------------------------------------------------------------------
  61. # Generates a hash file
  62. # Parameters: %digestfile% %filelist%
  63. #-------------------------------------------------------------------------------
  64. function generateDigests() {
  65. if [ "${DIGESTS}" != "" ]; then
  66. local OUTPUT="${1}"
  67. shift
  68. local FILELIST="${@}"
  69. rm -f ${OUTPUT}
  70. for FILE in ${FILELIST}; do
  71. [ ! -f ${FILE} ] && return 1
  72. for DIGEST in ${DIGESTS}; do
  73. shash -a ${DIGEST} ${FILE} >> ${OUTPUT}
  74. done
  75. done
  76. fi
  77. return 0
  78. }
  79. #-------------------------------------------------------------------------------
  80. # Creates all 'core' directories necessary for EzBuild to operate
  81. #-------------------------------------------------------------------------------
  82. function makeCoreDirectories() {
  83. local DIRS="${BINDIR} ${BUILDDIR} ${LOGFILE%/*} ${OVERLAYSDIR} \
  84. ${PACKAGESDIR} ${PORTAGESDIR} ${STOREDIR} ${TEMPDIR}"
  85. for DIR in ${DIRS}; do
  86. makeDirectory ${DIR} || return 1
  87. done
  88. return 0
  89. }
  90. #-------------------------------------------------------------------------------
  91. # Creates all components of the specified directories assuming thay are empty
  92. # Parameters: %directory%
  93. #-------------------------------------------------------------------------------
  94. function makeCleanDirectory() {
  95. rm -rf "${@}"
  96. makeDirectory "${@}"
  97. return ${?}
  98. }
  99. #-------------------------------------------------------------------------------
  100. # Creates all components of the specified directories
  101. # Parameters: %directory%
  102. #-------------------------------------------------------------------------------
  103. function makeDirectory() {
  104. local OUTPUT RESULT
  105. OUTPUT=$(install -d "${@}" 2>&1)
  106. RESULT=${?}
  107. if [ ${RESULT} -ne 0 ]; then
  108. logOutput "${OUTPUT}"
  109. fi
  110. return ${RESULT}
  111. }
  112. #-------------------------------------------------------------------------------
  113. # Creates a symbolic link between two files in specified target directory
  114. # Parameters: %source% %target_dir%
  115. #-------------------------------------------------------------------------------
  116. function makeLink() {
  117. local DESTDIR OUTPUT RESULT
  118. DESTDIR="${2%/*}"
  119. [[ ! -d ${DESTDIR} ]] && makeDirectory "${DESTDIR}"
  120. OUTPUT=$(ln -sfn "${1}" "${2}" 2>&1)
  121. RESULT=${?}
  122. if [ ${RESULT} -ne 0 ]; then
  123. logOutput "${OUTPUT}"
  124. fi
  125. return ${RESULT}
  126. }
  127. #-------------------------------------------------------------------------------
  128. # Makes block or character special file with specified mode bits
  129. # Parameters: %directory% %chmod% %name% %type% [%major%] [%minor%]
  130. #-------------------------------------------------------------------------------
  131. function makeNode() {
  132. local DIRECTORY="${1}"
  133. local CHMOD="${2}"
  134. local NAME="${3}"
  135. shift 3
  136. if [ ! -d ${DIRECTORY} ]; then
  137. makeDirectory ${DIRECTORY} || return 1
  138. fi
  139. cd ${DIRECTORY}
  140. rm -rf ${NAME}
  141. run "mknod ${NAME} ${*}" || return 1
  142. run "chmod ${CHMOD} ${NAME}" || return 1
  143. return 0
  144. }
  145. #-------------------------------------------------------------------------------
  146. # Merges data from source overlay into destination directory
  147. # Parameters: %src_directory$ %dest_directory% %files_to_copy% %files_to_skip%
  148. # %overwrite%
  149. #-------------------------------------------------------------------------------
  150. function mergeOverlay() {
  151. local DST="${2}"
  152. local FTC="${3}"
  153. local FTS="${4}"
  154. local ORW="${5}"
  155. local SRC="${1}"
  156. local TOPDIR="$(pwd)"
  157. makeCleanDirectory ${TEMPDIR}/ebuilds || return 1
  158. cd ${SRC}
  159. saveIFS ","
  160. if [ "$(toUpper ${FTC})" == "ALL" ]; then
  161. run "cp -apf *-* ${TEMPDIR}/ebuilds/"
  162. run "cp -apf eclass ${TEMPDIR}/ebuilds/"
  163. run "cp -apf licenses ${TEMPDIR}/ebuilds/"
  164. run "cp -apf virtual ${TEMPDIR}/ebuilds/"
  165. else
  166. for ITEM in ${FTC}; do
  167. run "cp -apf --parents ${ITEM} ${TEMPDIR}/ebuilds/" || return 1
  168. done
  169. fi
  170. if [ "$(toUpper ${FTS})" != "NONE" ] && [ "$(toUpper ${FTS})" != "N/A" ]; then
  171. for ITEM in ${FTS}; do
  172. rm -rf ${TEMPDIR}/ebuilds/${ITEM}
  173. done
  174. fi
  175. restoreIFS
  176. cd ${TEMPDIR}/ebuilds
  177. find -type d -name ".svn" -o -name "CVS" | xargs rm -rf {}
  178. while read CAT; do
  179. cd ${CAT}
  180. while read PACK; do
  181. if [ -e ${DST}/${CAT}/${PACK} ]; then
  182. if isEnabled ${ORW}; then
  183. rm -rf ${DST}/${CAT}/${PACK}
  184. else
  185. continue
  186. fi
  187. fi
  188. if [ ! -d ${DST}/${CAT} ]; then
  189. makeDirectory ${DST}/${CAT} || return 1
  190. fi
  191. run "cp -apf ${PACK} ${DST}/${CAT}/${PACK}" || return 1
  192. done < <(find * -maxdepth 0)
  193. cd ..
  194. done < <(find * -maxdepth 0 -type d)
  195. cd ${TOPDIR}
  196. rm -rf ${TEMPDIR}/ebuilds
  197. return 0
  198. }
  199. #-------------------------------------------------------------------------------
  200. # Extracts any tar based archive into specified directory
  201. # Parameters: %tarball% %dest_directory%
  202. #-------------------------------------------------------------------------------
  203. function unpack() {
  204. local DST EXT OUTPUT RESULT SRC
  205. SRC="${1}"
  206. DST="${2}"
  207. EXT=$(toLower "${SRC##*.}")
  208. if [ ! -d ${DST} ]; then
  209. makeDirectory ${DST} || return 1
  210. fi
  211. case "${EXT}" in
  212. bz2)
  213. if [ -e /usr/bin/pbzip2 ]; then
  214. OUTPUT=$(pbzip2 -dc "${SRC}" 2>&1 | tar xpf - -C "${DST}" 2>&1)
  215. else
  216. OUTPUT=$(tar xjpf "${SRC}" -C "${DST}" 2>&1)
  217. fi
  218. RESULT=${?}
  219. ;;
  220. gz|xz|z)
  221. OUTPUT=$(tar xpf "${SRC}" -C "${DST}" 2>&1)
  222. RESULT=${?}
  223. ;;
  224. *)
  225. OUTPUT="Unrecognized source compression for ${SRC}"
  226. RESULT=1
  227. ;;
  228. esac
  229. if [ ${RESULT} -ne 0 ]; then
  230. logOutput "${OUTPUT}"
  231. fi
  232. return ${RESULT}
  233. }