diff --git a/mpbb-cleanup b/mpbb-cleanup index e403225..7f6431f 100644 --- a/mpbb-cleanup +++ b/mpbb-cleanup @@ -10,15 +10,15 @@ cleanup-help() { cleanup() { echo "----> Deactivating ports" - # $option_prefix is set by mpbb - # shellcheck disable=SC2154 + # $option_prefix is set by mpbb + # shellcheck disable=SC2154 if [ -n "$("${option_prefix}/bin/port" -q installed active)" ]; then "${option_prefix}/bin/port" -fp deactivate active fi echo echo "----> Uninstalling obsolete ports" - # $thisdir is set by mpbb and points to the directory in which this script resides - # shellcheck disable=SC2154 + # $thisdir is set by mpbb and points to the directory in which this script resides + # shellcheck disable=SC2154 "${option_prefix}/bin/port-tclsh" "${thisdir}/tools/uninstall-old-ports.tcl" echo echo "----> Deleting distfiles" diff --git a/mpbb-gather-archives b/mpbb-gather-archives index c7f6d84..a771428 100644 --- a/mpbb-gather-archives +++ b/mpbb-gather-archives @@ -11,8 +11,12 @@ gather-archives-help() { gather-archives() { curl=/usr/bin/curl + # $option_prefix is set in mpbb + # shellcheck disable=SC2154 tclsh=${option_prefix}/bin/port-tclsh + # $option_staging_dir is set in mpbb + # shellcheck disable=SC2154 if [ -d "${option_staging_dir}" ]; then find "${option_staging_dir}" -type f -delete -print | sed -E -e "s|^.*/||" -e 's/^/Deleting previously staged archive: /' rm -rf "${option_staging_dir}" @@ -26,7 +30,11 @@ gather-archives() { archive_port=$(basename "$(dirname "${archive_path}")") archive_basename=$(basename "${archive_path}") + # $option_archive_site is set in mpbb + # shellcheck disable=SC2154 if ! ${curl} -fIsL "${option_archive_site}/${archive_port}/${archive_basename}" > /dev/null; then + # $option_workdir is set in mpbb + # shellcheck disable=SC2154 if "${tclsh}" "${option_workdir}/tools/port_binary_distributable.tcl" -v "${archive_port}"; then echo "Staging archive for upload: ${archive_basename}" mkdir -p "${option_staging_dir}/${archive_port}" || { status=$?; break; } diff --git a/mpbb-install-dependencies b/mpbb-install-dependencies index e99d695..f3701d2 100644 --- a/mpbb-install-dependencies +++ b/mpbb-install-dependencies @@ -13,10 +13,12 @@ install-dependencies() { local dependencies local dependencies_count local dependencies_counter + # $option_logdir is set in mpbb + # shellcheck disable=SC2154 local log_status_dependencies="${option_logdir}/dependencies-progress.txt" local log_subports_progress="${option_logdir}/ports-progress.txt" - if [ -z "${option_port}" ]; then + if [ -z "${option_port:-}" ]; then errmsg "--port is required" return 1 fi @@ -26,6 +28,8 @@ install-dependencies() { > "$log_status_dependencies" # calculate list of dependencies in-order + # $option_prefix and $thisdir are set in mpbb + # shellcheck disable=SC2154 dependencies=$("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/dependencies.tcl" "${option_port}") if [ $? -ne 0 ]; then echo "Calculating dependencies for '${option_port}' failed, aborting." >&2 @@ -51,7 +55,7 @@ install-dependencies() { echo >> "$log_status_dependencies" - echo "$dependencies" | while read dependency; do + echo "$dependencies" | while read -r dependency; do # Split portname +variant1+variant2 into portname and variants, where # the variants are optional. depname=${dependency%% *} @@ -60,6 +64,8 @@ install-dependencies() { text="Installing dependency ($dependencies_counter of $dependencies_count) '${depname}' with variants '${depvariants}'" echo "----> ${text}" echo -n "${text} ... " >> "$log_status_dependencies" + # $depvariants isn't quoted on purpose + # shellcheck disable=SC2086 if ! "${option_prefix}/bin/port" -d install --unrequested "$depname" $depvariants; then echo "Build of dependency '${depname}' failed, aborting." >&2 echo "[FAIL]" >> "$log_status_dependencies" diff --git a/mpbb-install-port b/mpbb-install-port index eb5155f..67abcb8 100644 --- a/mpbb-install-port +++ b/mpbb-install-port @@ -10,12 +10,14 @@ install-port-help() { } install-port() { + # $option_logdir is set in mpbb + # shellcheck disable=SC2154 local log_port_contents="${option_logdir}/port-contents.txt" local log_port_stats="${option_logdir}/port-statistics.txt" local log_port_main="${option_logdir}/main.log" local log_subports_progress="${option_logdir}/ports-progress.txt" - if [ -z "${option_port}" ]; then + if [ -z "${option_port:-}" ]; then errmsg "--port is required" return 1 fi @@ -28,13 +30,17 @@ install-port() { # log: summary for the portwatcher echo -n "- Installing ${option_port} ... " >> "$log_subports_progress" - local time_start=$(date +%s) + local time_start + local time_stop + time_start=$(date +%s) + # $option_prefix is set in mpbb + # shellcheck disable=SC2154 if ! "${option_prefix}/bin/port" -dk install "${option_port}"; then echo "Build of '${option_port}' failed." echo "[FAIL]" >> "$log_subports_progress" return 1 fi - local time_stop=$(date +%s) + time_stop=$(date +%s) echo "[OK]" >> "$log_subports_progress" @@ -44,22 +50,41 @@ install-port() { # TODO: printing statistics (and installing the port + dependencies) # only makes sense when the port hasn't been installed previously # log: statistics - echo "time: $(($time_stop - $time_start))s" >> "$log_port_stats" + echo "time: $((time_stop - time_start))s" >> "$log_port_stats" - local port_workdir=$("${option_prefix}/bin/port" work "${option_port}") - local port_workdir_size=$(du -ks "$port_workdir" | sed 's/^ *//' | tr '\t' '\n' | head -n 1) - echo "workdir: ${port_workdir_size}k" >> "$log_port_stats" - local port_destdir="$port_workdir/destroot" - if [ -d "$port_destdir" ]; then - local port_destdir_size=$(du -ks "$port_destdir" | sed 's/^ *//' | tr '\t' '\n' | head -n 1) - echo "destdir: ${port_destdir_size}k" >> "$log_port_stats" - else - echo "destdir: -" >> "$log_port_stats" + local port_workdir + local port_workdir_size="" + local port_destdir_size="" + local print_arg_workdir="ERROR" + local print_arg_destdir="ERROR" + # First, compute port_workdir_size and port_destdir_size + port_workdir=$("${option_prefix}/bin/port" work "${option_port}") + if [ -n "$port_workdir" ]; then + port_workdir_size=$(du -ks "$port_workdir" | sed 's/^ *//' | tr '\t' '\n' | head -n 1) + if [ $? -eq 0 ] && [ -n "$port_workdir_size" ]; then + print_arg_workdir="${port_workdir_size}k" + fi + + local port_destdir="$port_workdir/destroot" + # if we arrive here, 'port work $option_port' was successful, so we're + # at least going to print 'destdir: -' + print_arg_destdir="-" + if [ -d "$port_destdir" ]; then + port_destdir_size=$(du -ks "$port_destdir" | sed 's/^ *//' | tr '\t' '\n' | head -n 1) + if [ $? -eq 0 ] && [ -n "$port_destdir_size" ]; then + print_arg_destdir="${port_destdir_size}k" + fi + fi fi + # Then print them, or on error (or if destdir doesn't exist), print the + # appropriate message + echo "workdir: $print_arg_workdir" >> "$log_port_stats" + echo "destdir: $print_arg_destdir" >> "$log_port_stats" # log: main.log - local port_mainlog=$("${option_prefix}/bin/port" logfile "${option_port}") - if [ -f $port_mainlog ]; then + local port_mainlog + port_mainlog=$("${option_prefix}/bin/port" logfile "${option_port}") + if [ $? -eq 0 ] && [ -f "$port_mainlog" ]; then cp -f "$port_mainlog" "$log_port_main" fi } diff --git a/mpbb-list-subports b/mpbb-list-subports index bff3edc..d4fa80e 100644 --- a/mpbb-list-subports +++ b/mpbb-list-subports @@ -18,10 +18,14 @@ print-subports() { local exclude local exclude_reasons local reason + # $option_logdir is set in mpbb + # shellcheck disable=SC2154 local log_subports_progress="${option_logdir}/ports-progress.txt" os_version="$(sw_vers -productVersion | cut -d . -f 1-2)" is_64bit_capable="$(sysctl -n hw.cpu64bit_capable)" + # $optoin_prefix is set in mpbb + # shellcheck disable=SC2154 ports=$("${option_prefix}/bin/port" -q info --index --line --name "${portname}" "subportof:${portname}" 2>/dev/null) || return $? for port in $ports; do exclude=0 @@ -31,6 +35,8 @@ print-subports() { exclude=1 exclude_reasons+=("its name contains 'graveyard'") else + # $thisdir is set in mpbb + # shellcheck disable=SC2154 for portgroup in $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/portgroups.tcl" "$port"); do if [ "$portgroup" = "obsolete-1.0" ]; then exclude=1 @@ -41,7 +47,7 @@ print-subports() { if [[ $exclude -eq 0 && "${os_version}" = "10.6" && "${is_64bit_capable}" = "0" ]]; then supported_archs=$("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/supported-archs.tcl" "${port}") - if [[ -n "${supported_archs}" && !("${supported_archs}" == *"x86_64"* && "${supported_archs}" == *"i386"*) ]]; then + if [[ -n "${supported_archs}" && ! ("${supported_archs}" == *"x86_64"* && "${supported_archs}" == *"i386"*) ]]; then exclude=1 exclude_reasons+=("the ${os_version}_x86_64 builder will build it") fi @@ -69,7 +75,7 @@ print-subports() { list-subports() { local log_subports_progress="${option_logdir}/ports-progress.txt" - if [ $# -le 0 -a -z "${option_port}" ]; then + if [ $# -le 0 ] && [ -z "${option_port:-}" ]; then errmsg "Either --port or a list of positional arguments with port names is required." return 1 fi diff --git a/mpbb-selfupdate b/mpbb-selfupdate index 6f51ab6..fb3001a 100644 --- a/mpbb-selfupdate +++ b/mpbb-selfupdate @@ -9,6 +9,8 @@ selfupdate-help() { } selfupdate() { + # $option_prefix is set in mpbb + # shellcheck disable=SC2154 if [ ! -f "${option_prefix}/bin/port" ]; then macports_version=2.3.4 macports_distname=MacPorts-${macports_version} @@ -20,8 +22,8 @@ selfupdate() { tar -xjf ${macports_distfile} || return $? fi cd ${macports_distname} || return $? - ./configure --prefix=${option_prefix} --enable-readline || return $? - make -j$(sysctl -n hw.activecpu) || return $? + ./configure --prefix="${option_prefix}" --enable-readline || return $? + make -j"$(sysctl -n hw.activecpu)" || return $? make install || return $? cd .. || return $? rm -rf ${macports_distfile} ${macports_distname} || return $?