forked from macports/mpbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpbb-install-port
128 lines (112 loc) · 4.36 KB
/
mpbb-install-port
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
# -*- coding: utf-8; mode: sh; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=sh:et:sw=4:ts=4:sts=4
# Note:
# This script is sourced by the mpbb wrapper script.
# Do not execute this directly!
install-port-usage() {
# "prog" is defined in mpbb-help.
# shellcheck disable=SC2154
cat <<EOF
usage: $prog [<global opts>] install-port [<opts>] <port>
Build and install the given port.
Run \`$prog help' for global options and a list of other subcommands.
EOF
}
get-maintainers() {
# 'username@macports.org github_username' => 'username@macports.org'
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
"${option_prefix}/bin/port" info --index --maintainers --line "$@" \
| tr ', ' '\n' | fgrep '@' | tr '\n' ',' | sed 's/,$//'
}
install-port() {
local port=${1-}
if [[ -z $port ]]; then
err "Must specify a port"
return 1
fi
# $option_log_dir is set in mpbb
# shellcheck disable=SC2154
local log_port_contents="${option_log_dir}/port-contents.txt"
local log_port_stats="${option_log_dir}/port-statistics.txt"
local log_port_main="${option_log_dir}/main.log"
local log_subports_progress="${option_log_dir}/ports-progress.txt"
# prepare the log files and make sure to start with empty ones
mkdir -p "${option_log_dir}"
#> "$log_port_contents"
> "$log_port_stats"
# $option_prefix and $thisdir are set in mpbb
# shellcheck disable=SC2154
if [[ -f $("${option_prefix}/bin/port-tclsh" "${thisdir}/tools/archive-path.tcl" "$@") ]]; then
echo "$@ already installed, nothing to do"
# log: summary for the portwatcher
echo "Building '$port' ... [OK]" >> "$log_subports_progress"
echo "$@" >> "${option_work_dir}/all_ports"
return 0
fi
local time_start
local time_stop
time_start=$(date +%s)
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
if "${option_prefix}/bin/port" -dkn install "$@"; then
# Remove failcache if it exists
failcache_success "$@"
if [ $? -ne 0 ]; then
err "failcache_success" "$@" "failed."
return 1
fi
else
echo "Build of '$port' failed."
# log: summary for the portwatcher
echo "Building '$port' ... [ERROR] maintainers: $(get-maintainers "$port")." >> "$log_subports_progress"
# update failcache
failcache_failure "$@"
if [ $? -ne 0 ]; then
err "failcache_failure" "$@" "failed."
return 1
fi
return 1
fi
time_stop=$(date +%s)
# log: summary for the portwatcher
echo "Building '$port' ... [OK]" >> "$log_subports_progress"
# log: contents
"${option_prefix}/bin/port" -q contents "$port" > "$log_port_contents"
# log: statistics
echo "time: $((time_stop - time_start))s" >> "$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 "$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 $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
port_mainlog=$("${option_prefix}/bin/port" logfile "$port")
if [ $? -eq 0 ] && [ -f "$port_mainlog" ]; then
cp -f "$port_mainlog" "$log_port_main"
fi
echo "$@" >> "${option_work_dir}/all_ports"
}