-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
mpbb-install-port
160 lines (142 loc) · 5.78 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/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 [--source] <port>
Build and install the given port.
Options:
--source
Build the port from source, ignoring binary archives.
Run \`$prog help' for global options and a list of other subcommands.
EOF
}
install-port() {
local args
parseopt source "$@" || return
# $option_source is set by parseopt
# shellcheck disable=SC2154
: "${option_source=0}"
set -- ${args+"${args[@]}"}
local source_flag
[[ "${option_source}" -eq 1 ]] && source_flag=s
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"
rm -f "${option_work_dir}/requested_port"
# $option_prefix and $thisdir are set in mpbb
# shellcheck disable=SC2154
local imagepath=$("$(readlink "${option_prefix}/bin/port-tclsh")" "${thisdir}/tools/archive-path.tcl" "$@")
if [[ -f "$imagepath" || -d "${imagepath%.*}" ]]; then
echo "$* already installed, nothing to do"
# log: summary for the portwatcher
echo "Building '$port' ... [OK]" >> "$log_subports_progress"
echo "$@" >> "${option_work_dir}/requested_port"
return 0
elif [[ -n "$("${option_prefix}/bin/port" -q installed "$@")" ]]; then
# archive name differs, supported_archs probably changed
"${option_prefix}/bin/port" -fv uninstall "$@"
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" -d fetch "$@"; then
echo "Fetch of '$port' failed."
# log: summary for the portwatcher
echo "Fetching '$port' ... [ERROR] maintainers: $(get-maintainers "$port")." >> "$log_subports_progress"
# Do not add to failcache. This could be a temporary problem that will
# be resolved once the file appears on mirrors.
return 1
fi
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
if ! "${option_prefix}/bin/port" -d checksum "$@"; then
echo "Checksum of '$port' failed."
# log: summary for the portwatcher
echo "Checksum '$port' ... [ERROR] maintainers: $(get-maintainers "$port")." >> "$log_subports_progress"
# Do not add to failcache. This could be a temporary network or server problem.
# Delete the files so they will be re-fetched next time (hopefully correctly).
"${option_prefix}/bin/port" -d clean --dist "$@"
return 1
fi
# $option_prefix is set in mpbb
# shellcheck disable=SC2154
if "${option_prefix}/bin/port" "-dkn${source_flag}" install --unrequested "$@"; 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}/requested_port"
}