reGen2 Linux Release Metatool
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 contents file
  62. # Parameters: %contentsfile% %archive%
  63. #-------------------------------------------------------------------------------
  64. function generateContents() {
  65. local OUTPUT="${1}"
  66. local ARCHIVE="${2}"
  67. [ ! -f ${ARCHIVE} ] && return 1
  68. case ${ARCHIVE} in
  69. *.iso)
  70. isoinfo -l -i ${ARCHIVE} > ${OUTPUT} || return 1
  71. ;;
  72. *.tar)
  73. tar -tvf ${ARCHIVE} > ${OUTPUT} || return 1
  74. ;;
  75. *.tar.gz|*.tar.xz|*.tar.z)
  76. tar -tvzf ${ARCHIVE} > ${OUTPUT} || return 1
  77. ;;
  78. *.tar.bz2)
  79. tar -tvjf ${ARCHIVE} > ${OUTPUT} || return 1
  80. ;;
  81. esac
  82. return 0
  83. }
  84. #-------------------------------------------------------------------------------
  85. # Generates a hash file
  86. # Parameters: %digestfile% %filelist%
  87. #-------------------------------------------------------------------------------
  88. function generateDigests() {
  89. if [ "${DIGESTS}" != "" ]; then
  90. local OUTPUT="${1}"
  91. shift
  92. local FILELIST="${@}"
  93. rm -f ${OUTPUT}
  94. for FILE in ${FILELIST}; do
  95. [ ! -f ${FILE} ] && return 1
  96. for DIGEST in ${DIGESTS}; do
  97. shash -a ${DIGEST} ${FILE} >> ${OUTPUT}
  98. done
  99. done
  100. fi
  101. return 0
  102. }
  103. #-------------------------------------------------------------------------------
  104. # Creates all components of the specified directories assuming thay are empty
  105. # Parameters: %directory%
  106. #-------------------------------------------------------------------------------
  107. function makeCleanDirectory() {
  108. rm -rf "${@}"
  109. makeDirectory "${@}"
  110. return ${?}
  111. }
  112. #-------------------------------------------------------------------------------
  113. # Creates all 'core' directories necessary for EzBuild to operate
  114. #-------------------------------------------------------------------------------
  115. function makeCoreDirectories() {
  116. local DIRS="${BINDIR} ${BUILDDIR} ${ECACHEDIR} ${LOGFILE%/*} \
  117. ${OVERLAYSDIR} ${PACKAGESDIR} ${PORTAGESDIR} ${STOREDIR} ${TEMPDIR}"
  118. for DIR in ${DIRS}; do
  119. makeDirectory ${DIR} || return 1
  120. done
  121. return 0
  122. }
  123. #-------------------------------------------------------------------------------
  124. # Creates base device nodes and symlinks in specified directory
  125. # Parameters: %directory%
  126. #-------------------------------------------------------------------------------
  127. function makeCoreNodes() {
  128. local DIR="${1}"
  129. makeNode ${DIR} 600 console c 5 1 || return 1
  130. makeNode ${DIR} 600 kmsg c 1 11 || return 1
  131. makeNode ${DIR} 777 null c 1 3 || return 1
  132. makeNode ${DIR} 666 ptmx c 5 2 || return 1
  133. makeNode ${DIR} 644 ptyp0 c 2 0 || return 1
  134. makeNode ${DIR} 666 random c 1 8 || return 1
  135. makeNode ${DIR} 666 tty c 5 0 || return 1
  136. makeNode ${DIR} 666 tty0 c 4 0 || return 1
  137. makeNode ${DIR} 644 ttyp0 c 3 0 || return 1
  138. makeNode ${DIR} 666 urandom c 1 9 || return 1
  139. makeNode ${DIR} 666 zero c 1 5 || return 1
  140. for n in {0..3}; do
  141. makeNode ${DIR} 600 ttyS${n} c 4 $(( 64 + $n )) || return 1
  142. done
  143. run "ln -sfv /proc/self/fd ${DIR}/fd" || return 1
  144. run "ln -sfv /proc/self/fd/0 ${DIR}/stdin" || return 1
  145. run "ln -sfv /proc/self/fd/1 ${DIR}/stdout" || return 1
  146. run "ln -sfv /proc/self/fd/2 ${DIR}/stderr" || return 1
  147. run "ln -sfv /proc/kcore ${DIR}/core" || return 1
  148. return 0
  149. }
  150. #-------------------------------------------------------------------------------
  151. # Creates all components of the specified directories
  152. # Parameters: %directory%
  153. #-------------------------------------------------------------------------------
  154. function makeDirectory() {
  155. local OUTPUT RESULT
  156. OUTPUT=$(install -d "${@}" 2>&1)
  157. RESULT=${?}
  158. if [ ${RESULT} -ne 0 ]; then
  159. logOutput "${OUTPUT}"
  160. fi
  161. return ${RESULT}
  162. }
  163. #-------------------------------------------------------------------------------
  164. # Creates a symbolic link between two files in specified target directory
  165. # Parameters: %source% %target_dir%
  166. #-------------------------------------------------------------------------------
  167. function makeLink() {
  168. local DESTDIR OUTPUT RESULT
  169. DESTDIR="${2%/*}"
  170. [[ ! -d ${DESTDIR} ]] && makeDirectory "${DESTDIR}"
  171. OUTPUT=$(ln -sfn "${1}" "${2}" 2>&1)
  172. RESULT=${?}
  173. if [ ${RESULT} -ne 0 ]; then
  174. logOutput "${OUTPUT}"
  175. fi
  176. return ${RESULT}
  177. }
  178. #-------------------------------------------------------------------------------
  179. # Makes block or character special file with specified mode bits
  180. # Parameters: %directory% %chmod% %name% %type% [%major%] [%minor%]
  181. #-------------------------------------------------------------------------------
  182. function makeNode() {
  183. local DIRECTORY="${1}"
  184. local CHMOD="${2}"
  185. local NAME="${3}"
  186. shift 3
  187. if [ ! -d ${DIRECTORY} ]; then
  188. makeDirectory ${DIRECTORY} || return 1
  189. fi
  190. cd ${DIRECTORY}
  191. rm -rf ${NAME}
  192. run "mknod ${NAME} ${*}" || return 1
  193. run "chmod ${CHMOD} ${NAME}" || return 1
  194. return 0
  195. }
  196. #-------------------------------------------------------------------------------
  197. # Merges data from source overlay into destination directory
  198. # Parameters: %src_directory$ %dest_directory% %files_to_copy% %files_to_skip%
  199. # %overwrite%
  200. #-------------------------------------------------------------------------------
  201. function mergeOverlay() {
  202. local DST="${2}"
  203. local FTC="${3}"
  204. local FTS="${4}"
  205. local ORW="${5}"
  206. local SRC="${1}"
  207. local TOPDIR="$(pwd)"
  208. makeCleanDirectory ${TEMPDIR}/ebuilds || return 1
  209. cd ${SRC}
  210. saveIFS ","
  211. if [ "$(toUpper ${FTC})" == "ALL" ]; then
  212. run "cp -apf *-* ${TEMPDIR}/ebuilds/"
  213. run "cp -apf eclass ${TEMPDIR}/ebuilds/"
  214. run "cp -apf licenses ${TEMPDIR}/ebuilds/"
  215. run "cp -apf virtual ${TEMPDIR}/ebuilds/"
  216. else
  217. for ITEM in ${FTC}; do
  218. run "cp -apf --parents ${ITEM} ${TEMPDIR}/ebuilds/" || return 1
  219. done
  220. fi
  221. if [ "$(toUpper ${FTS})" != "NONE" ] && [ "$(toUpper ${FTS})" != "N/A" ]; then
  222. for ITEM in ${FTS}; do
  223. rm -rf ${TEMPDIR}/ebuilds/${ITEM}
  224. done
  225. fi
  226. restoreIFS
  227. cd ${TEMPDIR}/ebuilds
  228. find -type d -name ".svn" -o -name "CVS" | xargs rm -rf {}
  229. while read CAT; do
  230. cd ${CAT}
  231. while read PACK; do
  232. if [ -e ${DST}/${CAT}/${PACK} ]; then
  233. if isEnabled ${ORW}; then
  234. rm -rf ${DST}/${CAT}/${PACK}
  235. else
  236. continue
  237. fi
  238. fi
  239. if [ ! -d ${DST}/${CAT} ]; then
  240. makeDirectory ${DST}/${CAT} || return 1
  241. fi
  242. run "cp -apf ${PACK} ${DST}/${CAT}/${PACK}" || return 1
  243. done < <(find * -maxdepth 0)
  244. cd ..
  245. done < <(find * -maxdepth 0 -type d)
  246. cd ${TOPDIR}
  247. rm -rf ${TEMPDIR}/ebuilds
  248. return 0
  249. }
  250. #-------------------------------------------------------------------------------
  251. # Extracts any tar based archive into specified directory
  252. # Parameters: %tarball% %dest_directory%
  253. #-------------------------------------------------------------------------------
  254. function unpack() {
  255. local DST EXT OUTPUT RESULT SRC
  256. SRC="${1}"
  257. DST="${2}"
  258. EXT=$(toLower "${SRC##*.}")
  259. if [ ! -d ${DST} ]; then
  260. makeDirectory ${DST} || return 1
  261. fi
  262. case "${EXT}" in
  263. bz2)
  264. if [ -e /usr/bin/pbzip2 ]; then
  265. OUTPUT=$(pbzip2 -dc "${SRC}" 2>&1 | tar xpf - -C "${DST}" 2>&1)
  266. else
  267. OUTPUT=$(tar xjpf "${SRC}" -C "${DST}" 2>&1)
  268. fi
  269. RESULT=${?}
  270. ;;
  271. gz|xz|z)
  272. OUTPUT=$(tar xpf "${SRC}" -C "${DST}" 2>&1)
  273. RESULT=${?}
  274. ;;
  275. *)
  276. OUTPUT="Unrecognized source compression for ${SRC}"
  277. RESULT=1
  278. ;;
  279. esac
  280. if [ ${RESULT} -ne 0 ]; then
  281. logOutput "${OUTPUT}"
  282. fi
  283. return ${RESULT}
  284. }