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.
 

226 lines
6.8 KiB

#!/bin/bash
# Copyright 2010-2012, Asio Software Technologies
# Distributed under the terms of the GNU General Public License v3
#-------------------------------------------------------------------------------
# Applies a diff file to an original
# Parameters: %original_dir% %patch%
#-------------------------------------------------------------------------------
function applyPatch() {
local DESTDIR="${1}"
local PATCH="${2}"
local PREFIX
for PREFIX in {0..4}; do
if run "patch -d ${DESTDIR} --dry-run -p ${PREFIX} -i ${PATCH} -s"; then
run "patch -d ${DESTDIR} -p ${PREFIX} -i ${PATCH}" && return 0
fi
done
return 1
}
#-------------------------------------------------------------------------------
# Completely removes log file
#-------------------------------------------------------------------------------
function cleanLog() {
rm -rf ${LOGFILE} &> /dev/null
}
#-------------------------------------------------------------------------------
# Completely removes whole temp directory
#-------------------------------------------------------------------------------
function cleanTemp() {
rm -rf ${TEMPDIR} &> /dev/null
}
#-------------------------------------------------------------------------------
# Downloads files into specified or current directory
# Parameters: %url% [%dest_directory%]
#-------------------------------------------------------------------------------
function download() {
local DEST FILENAME RESULT URL
DEST="${2}"
FILENAME="${1##*/}"
URL="${1}"
if isSet DEST; then
DEST="${DEST}/${FILENAME}"
else
DEST="./${FILENAME}"
fi
logMessage "Downloading ${URL} to ${DEST}" "DEBUG"
echo -ne " ${STAR_GREEN} ${FILENAME}: "
wget --progress=dot -c -t ${FETCHTRIES} -T ${FETCHTIMEOUT} -O "${DEST}" \
${URL} 2>&1 | grep --line-buffered "%" | sed -u -e "s/[\.\,]//g" | \
awk '{printf("\b\b\b\b%4s", $2)}'
RESULT=${PIPESTATUS[0]}
echo -ne "\b\b\b\b"
if [ ${RESULT} -ne 0 ]; then
logOutput "Unable to download ${URL}! Exit code: ${RESULT}"
echo -e "${COLOR_RED}${COLOR_BOLD}ERROR${COLOR_WHITE}${COLOR_NORMAL}"
else
echo -e "${COLOR_GREEN}${COLOR_BOLD}DONE${COLOR_WHITE}${COLOR_NORMAL}"
fi
return ${RESULT}
}
#-------------------------------------------------------------------------------
# Creates all 'core' directories necessary for EzBuild to operate
#-------------------------------------------------------------------------------
function makeCoreDirectories() {
local DIRS="${BINDIR} ${BUILDDIR} ${LOGFILE%/*} ${OVERLAYSDIR} \
${PACKAGESDIR} ${PORTAGESDIR} ${TEMPDIR} ${TRASHDIR}"
for DIR in ${DIRS}; do
makeDirectory ${DIR} || return 1
done
return 0
}
#-------------------------------------------------------------------------------
# Creates all components of the specified directories assuming thay are empty
# Parameters: %directory%
#-------------------------------------------------------------------------------
function makeCleanDirectory() {
rm -rf "${@}"
makeDirectory "${@}"
return ${?}
}
#-------------------------------------------------------------------------------
# Creates all components of the specified directories
# Parameters: %directory%
#-------------------------------------------------------------------------------
function makeDirectory() {
local OUTPUT RESULT
OUTPUT=$(install -d "${@}" 2>&1)
RESULT=${?}
if [ ${RESULT} -ne 0 ]; then
logOutput "${OUTPUT}"
fi
return ${RESULT}
}
#-------------------------------------------------------------------------------
# Creates a symbolic link between two files in specified target directory
# Parameters: %source% %target_dir%
#-------------------------------------------------------------------------------
function makeLink() {
local DESTDIR OUTPUT RESULT
DESTDIR="${2%/*}"
[[ ! -d ${DESTDIR} ]] && makeDirectory "${DESTDIR}"
OUTPUT=$(ln -sfn "${1}" "${2}" 2>&1)
RESULT=${?}
if [ ${RESULT} -ne 0 ]; then
logOutput "${OUTPUT}"
fi
return ${RESULT}
}
#-------------------------------------------------------------------------------
# Makes block or character special file with specified mode bits
# Parameters: %directory% %chmod% %name% %type% [%major%] [%minor%]
#-------------------------------------------------------------------------------
function makeNode() {
local DIRECTORY="${1}"
local CHMOD="${2}"
local NAME="${3}"
shift 3
if [ ! -d ${DIRECTORY} ]; then
makeDirectory ${DIRECTORY} || return 1
fi
cd ${DIRECTORY}
rm -rf ${NAME}
run "mknod ${NAME} ${*}" || return 1
run "chmod ${CHMOD} ${NAME}" || return 1
return 0
}
#-------------------------------------------------------------------------------
# Merges data from source overlay into destination directory
# Parameters: %src_directory$ %dest_directory% %files_to_copy% %files_to_skip%
# %overwrite%
#-------------------------------------------------------------------------------
function mergeOverlay() {
local DST="${2}"
local FTC="${3}"
local FTS="${4}"
local ORW="${5}"
local SRC="${1}"
local TOPDIR="$(pwd)"
makeCleanDirectory ${TRASHDIR}/ebuilds || return 1
cd ${SRC}
saveIFS ","
if [ "$(toUpper ${FTC})" == "ALL" ]; then
run "cp -apf *-* ${TRASHDIR}/ebuilds/"
run "cp -apf eclass ${TRASHDIR}/ebuilds/"
run "cp -apf licenses ${TRASHDIR}/ebuilds/"
run "cp -apf virtual ${TRASHDIR}/ebuilds/"
else
for ITEM in ${FTC}; do
run "cp -apf --parents ${ITEM} ${TRASHDIR}/ebuilds/" || return 1
done
fi
if [ "$(toUpper ${FTS})" != "NONE" ] && [ "$(toUpper ${FTS})" != "N/A" ]; then
for ITEM in ${FTS}; do
rm -rf ${TRASHDIR}/ebuilds/${ITEM}
done
fi
restoreIFS
cd ${TRASHDIR}/ebuilds
find -type d -name ".svn" -o -name "CVS" | xargs rm -rf {}
while read CAT; do
cd ${CAT}
while read PACK; do
if [ -e ${DST}/${CAT}/${PACK} ]; then
if isEnabled ${ORW}; then
rm -rf ${DST}/${CAT}/${PACK}
else
continue
fi
fi
if [ ! -d ${DST}/${CAT} ]; then
makeDirectory ${DST}/${CAT} || return 1
fi
run "cp -apf ${PACK} ${DST}/${CAT}/${PACK}" || return 1
done < <(find * -maxdepth 0)
cd ..
done < <(find * -maxdepth 0 -type d)
cd ${TOPDIR}
rm -rf ${TRASHDIR}/ebuilds
return 0
}
#-------------------------------------------------------------------------------
# Extracts any tar based archive into specified directory
# Parameters: %tarball% %dest_directory%
#-------------------------------------------------------------------------------
function unpack() {
local DST EXT OUTPUT RESULT SRC
SRC="${1}"
DST="${2}"
EXT=$(toLower "${SRC##*.}")
if [ ! -d ${DST} ]; then
makeDirectory ${DST} || return 1
fi
case "${EXT}" in
bz2)
if [ -e /usr/bin/pbzip2 ]; then
OUTPUT=$(pbzip2 -dc "${SRC}" 2>&1 | tar xpf - -C "${DST}" 2>&1)
else
OUTPUT=$(tar xjpf "${SRC}" -C "${DST}" 2>&1)
fi
RESULT=${?}
;;
gz|xz|z)
OUTPUT=$(tar xpf "${SRC}" -C "${DST}" 2>&1)
RESULT=${?}
;;
*)
OUTPUT="Unrecognized source compression for ${SRC}"
RESULT=1
;;
esac
if [ ${RESULT} -ne 0 ]; then
logOutput "${OUTPUT}"
fi
return ${RESULT}
}