diff --git a/mp-build/scripts/mp-build.sh b/mp-build/scripts/mp-build.sh index de85c68..9e757d7 100755 --- a/mp-build/scripts/mp-build.sh +++ b/mp-build/scripts/mp-build.sh @@ -91,6 +91,7 @@ help_cmd() { echo_color " $BOLD--no-cache$RESET: don't check cache" echo_color " $BOLD--no-opts$RESET: don't show/list options" echo_color " $BOLD--cores$RESET: how many cores to use for the build" + echo_color " $BOLD--out$RESET: directory for the output archive" echo info "Licensed under GPLv3, see for more information" } @@ -149,6 +150,7 @@ OPT_NO_STDOUT=0 # PACKAGE() function output is ENABLED OPT_NO_CACHE=0 # cache is ENABLED OPT_NO_OPTS=0 # showing/listing options is ENABLED OPT_CORES=$(nproc) # use ALL CPU cores +OPT_OUT="DEFAULT" # use the package dist directory for output # parses all the options for arg in "$@"; do @@ -166,7 +168,15 @@ for arg in "$@"; do "--no-opts") OPT_NO_OPTS=1 ;; "--cores"*) - OPT_CORES=$(echo "${arg}" | cut -d "=" -f2) ;; + OPT_CORES="$(echo "${arg}" | cut -d '=' -f2)" ;; + "--out"*) + OPT_OUT="$(echo "${arg}" | cut -d '=' -f2)" + OPT_OUT="$(echo "${OPT_OUT}" | sed "s/'//g")" + OPT_OUT="$(echo "${OPT_OUT}" | sed 's/"//g')" + if [ ! -d "${OPT_OUT}" ]; then + error "Failed to access to the output directory (${OPT_OUT})" + exit 1 + fi ;; --*) error "Unknown option: ${arg}" exit 1 ;; @@ -206,7 +216,8 @@ if [ $OPT_NO_OPTS -eq 0 ]; then print " $BOLD NO_SDTOUT = $(itoyn $OPT_NO_STDOUT)" print " $BOLD NO_CACHE = $(itoyn $OPT_NO_CACHE)" print " $BOLD NO_OPTS = $(itoyn $OPT_NO_OPTS)" - print " $BOLD CORES = $OPT_CORES" + print " $BOLD CORES = ${OPT_CORES}" + print " $BOLD OUT = ${OPT_OUT}" fi cd "${TARGET}" @@ -236,6 +247,11 @@ fi pkgpath="$(realpath .)" cachepath="$(realpath '.cache')" distpath="$(realpath 'dist')" +if [ "${OPT_OUT}" == "DEFAULT" ]; then + outpath="${distpath}" +else + outpath="${OPT_OUT}" +fi rootpath="$(realpath 'root')" mkdir -p "${rootpath}" @@ -249,7 +265,7 @@ if [ $OPT_NO_CACHE -eq 0 ] && [ -f "${cachepath}/last" ]; then package_cache=$(sed -n '1p' "${cachepath}/last") changes_cache=$(sed -n '2p' "${cachepath}/last") - if [[ "${package_cache}" == "${package_hash}" ]] && [[ "${changes_cache}" == "${changes_hash}" ]]; then + if [ -f "${outpath}/${NAME}_${VERSION}.mpf" ] && [[ "${package_cache}" == "${package_hash}" ]] && [[ "${changes_cache}" == "${changes_hash}" ]]; then info "Found build in the cache (add --no-cache if you want to rebuild anyway)" success "Build was successful" exit 0 @@ -431,6 +447,12 @@ clean_dist info "Cleaning the root directory" rm -rf "${rootpath}" +# move archive to out directory +if [ "$(realpath "${distpath}/${archive}")" != "$(realpath "${outpath}")" ]; then + mv "${distpath}/${archive}" "${outpath}" 2> /dev/null + check_ret "Failed to move the archive to the output directory" +fi + # update the cache unset_indent info "Updating the package cache" diff --git a/mp-pool/scripts/mp-pool-clean.sh b/mp-pool/scripts/mp-pool-clean.sh index e57f662..e7e704c 100755 --- a/mp-pool/scripts/mp-pool-clean.sh +++ b/mp-pool/scripts/mp-pool-clean.sh @@ -95,6 +95,8 @@ for pkg in "${srcpath}/"*; do files+=("${NAME}_${VERSION}.mpf") files+=("${NAME}_${VERSION}.mpf.sig") + + clean_pkg_vars pi=$((pi+1)) done diff --git a/mp-pool/scripts/mp-pool.sh b/mp-pool/scripts/mp-pool.sh index b45fb9c..f26b701 100755 --- a/mp-pool/scripts/mp-pool.sh +++ b/mp-pool/scripts/mp-pool.sh @@ -64,7 +64,7 @@ list_to_str(){ for el in "${list[@]}"; do if [ -z "${str}" ]; then str="${el}" - else + else printf -v str "${str}\n ${el}" fi done @@ -72,20 +72,20 @@ list_to_str(){ # run mp-build with options mp_build_opts(){ - local opts=("${1}" "--no-opts") + local opts=("${1}" "--no-opts" "--out='${2}'") if [ $OPT_NO_DEPEND -eq 1 ]; then opts+=("--no-depend") fi - + if [ $OPT_NO_STDOUT -eq 1 ]; then opts+=("--no-stdout") fi - + if [ $OPT_NO_CACHE -eq 1 ]; then opts+=("--no-cache") fi - + mp-build ${opts[@]} return "$?" } @@ -94,16 +94,16 @@ mp_build_opts(){ ## main script ## ################# OPT_SKIP_FAIL=0 # stop build when a package build fails -OPT_NO_DEPEND=0 # checking depends is ENABLED +OPT_NO_DEPEND=0 # checking depends is ENABLED OPT_NO_STDOUT=0 # build() function output is ENABLED -OPT_NO_CACHE=0 # cache is ENABLED -OPT_NO_OPTS=0 # showing/listing options is ENABLED +OPT_NO_CACHE=0 # cache is ENABLED +OPT_NO_OPTS=0 # showing/listing options is ENABLED OPT_NO_SIGN=0 # sign all the built packages OPT_CORES=$(nproc) # use ALL CPU cores # parses all the options -for arg in "$@"; do - case $arg in +for arg in "$@"; do + case $arg in "--help") help_cmd exit 0 @@ -114,26 +114,26 @@ for arg in "$@"; do OPT_NO_DEPEND=1 ;; "--no-stdout") OPT_NO_STDOUT=1 ;; - "--no-cache") + "--no-cache") OPT_NO_CACHE=1 ;; "--no-opts") OPT_NO_OPTS=1 ;; "--no-sign") OPT_NO_SIGN=1 ;; - "--cores"*) + "--cores"*) OPT_CORES=$(echo "${arg}" | cut -d "=" -f2) ;; --*) error "Unknown option: ${arg}" exit 1 ;; - *) - if [ -z "${TARGET}" ]; then + *) + if [ -z "${TARGET}" ]; then TARGET="${arg}" else error "Unknown argument: ${arg}" exit 1 fi ;; - esac + esac done if [ -z "${TARGET}" ]; then @@ -156,7 +156,7 @@ fi # print the options if [ $OPT_NO_OPTS -eq 0 ]; then - info "Running mp-pool with the options:" + info "Running mp-pool with the options:" print " $BOLD SKIP_FAIL = $(itoyn $OPT_SKIP_FAIL)" print " $BOLD NO_DEPEND = $(itoyn $OPT_NO_DEPEND)" print " $BOLD NO_SDTOUT = $(itoyn $OPT_NO_STDOUT)" @@ -203,14 +203,14 @@ for pkg in "${srcpath}/"*; do info "(${pi}/${pc}) Building \"${package}\"" if [ $OPT_SKIP_FAIL -eq 1 ]; then - mp_build_opts "${pkg}" + mp_build_opts "${pkg}" "${distpath}" if [ $? -ne "0" ]; then error "(${pi}/${pc}) Build failed for \"${package}\", skipping" pi=$((pi+1)) continue fi - else - mp_build_opts "${pkg}" + else + mp_build_opts "${pkg}" "${distpath}" check_ret "(${pi}/${pc}) Build failed for \"${package}\"" fi @@ -222,7 +222,7 @@ for pkg in "${srcpath}/"*; do mv "${archive}" "${distpath}" check_ret "(${pi}/${pc}) Moving package archive failed for \"${package}\"" fi - + success "(${pi}/${pc}) Build was successful for \"${package}\"" pi=$((pi+1)) done @@ -242,8 +242,8 @@ if [ "$OPT_NO_SIGN" -eq 0 ]; then check_ret "Failed to sign package archive: \"$(basename "${pkg}")\"" success "Signed archive: $(basename "${pkg}")" done - - success "Signing process was completed" + + success "Signing process was completed" unset_indent fi @@ -281,7 +281,7 @@ for pkg in "${distpath}/"*".mpf"; do done pushd "${distpath}/list" > /dev/null - tar czf "${distpath}/LIST" * + tar czf "${distpath}/LIST" * check_ret "(2/2) Failed to create list archive (LIST)" popd > /dev/null diff --git a/mtsc-common/common.sh b/mtsc-common/common.sh index 8d26080..e0053dd 100755 --- a/mtsc-common/common.sh +++ b/mtsc-common/common.sh @@ -109,12 +109,20 @@ itoyn() { fi } -# checks if all the required package vars/functions are set +# unsets all the pool script vars/functions +clean_pool_vars() { + unset NAME + unset MAINTAINER + unset PUBKEY + unset SRCDIR +} + +# checks if all the required pool script vars/functions are set check_pool_vars() { if [ ! -n "$NAME" ]; then error "Failed to load the pool script" set_indent - + error "Required pool variable is not set: \"\$NAME\"" unset_indent @@ -126,9 +134,9 @@ check_pool_vars() { error "Required pool variable is not set: \"\$MAINTAINER\"" unset_indent - return 1 + return 1 elif [ ! -n "$PUBKEY" ]; then - error "Failed to load the pool script" + error "Failed to load the pool script" set_indent error "Required pool variable is not set: \"\$PUBKEY\"" @@ -136,7 +144,7 @@ check_pool_vars() { return 1 elif [ ! -n "$SRCDIR" ]; then - error "Failed to load the pool script" + error "Failed to load the pool script" set_indent error "Required pool variable is not set: \"\$SRCDIR\"" @@ -144,7 +152,7 @@ check_pool_vars() { return 1 fi - + case "${NAME}" in *" "*) error "Pool name contains an invalid character: \" \"" @@ -155,7 +163,20 @@ check_pool_vars() { return 0 } -# checks if all the required package vars/functions are set +# unsets all the package script vars/functions +clean_pkg_vars() { + unset NAME + unset DESC + unset VERSION + unset FILES + unset HASHES + unset DEPENDS + unset BUILD + unset PACKAGE + unset INSTALL +} + +# checks if all the required package script vars/functions are set check_pkg_vars() { if [ ! -n "$NAME" ]; then error "Failed to load the package script"