Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
184 lines (163 loc) · 6.08 KB
/
Copy pathbuild.sh
File metadata and controls
184 lines (163 loc) · 6.08 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"
export LINSCP_CONFIG_PATH="${LINSCP_CONFIG_PATH:-$PWD/config.ini}"
export LINSCP_DB_PATH="${LINSCP_DB_PATH:-$PWD/linscp.sqlite3}"
LOG_PATH="${LINSCP_BUILD_LOG:-$PWD/linscp-build.log}"
if [[ "${LINSCP_BUILD_LOG_ACTIVE:-0}" != "1" ]]; then
export LINSCP_BUILD_LOG_ACTIVE=1
rm -f "$LOG_PATH"
echo "[LinSCP Build] wrapper-start pwd=$PWD log=$LOG_PATH"
set +e
bash "$0" "$@" 2>&1 | tee "$LOG_PATH"
status=${PIPESTATUS[0]}
set -e
if [[ "$status" == "0" ]]; then
msg="[LinSCP Build] PROCESS build SUCCESS! exit=$status log=$LOG_PATH"
else
msg="[LinSCP Build] PROCESS build FAILED! exit=$status log=$LOG_PATH"
fi
echo "$msg"
echo "$msg" >> "$LOG_PATH"
if [[ "$status" != "0" ]]; then
echo "[LinSCP Build] Tail: tail -n 160 '$LOG_PATH'"
echo "[LinSCP Build] === LAST 60 LINES OF LOG ==="
tail -n 60 "$LOG_PATH" || true
echo "[LinSCP Build] === END TAIL ==="
fi
exit "$status"
fi
log(){ printf '[LinSCP Build] %s\n' "$*"; }
warn(){ printf '[LinSCP Build] WARN: %s\n' "$*" >&2; }
trace(){ printf '[LinSCP Build] TRACE line=%s :: %s\n' "${1:-?}" "${2:-}"; }
have(){ command -v "$1" >/dev/null 2>&1; }
on_err() {
local rc=$?
local line=$1
local cmd=$2
echo "[LinSCP Build] TRAP-ERR rc=$rc line=$line cmd=$cmd" >&2
echo "[LinSCP Build] TRAP-ERR cwd=$(pwd) ls=$(ls -la 2>&1 | head -30)" >&2
}
on_exit() {
local rc=$?
echo "[LinSCP Build] TRAP-EXIT rc=$rc reached-end=${INNER_REACHED_END:-no}"
}
trap 'on_err ${LINENO} "$BASH_COMMAND"' ERR
trap 'on_exit' EXIT
INNER_REACHED_END=no
NO_INSTALL=0
NO_TEST=0
NO_LAUNCH=0
for arg in "$@"; do
case "$arg" in
--no-install) NO_INSTALL=1 ;;
--no-tests|--no-test) NO_TEST=1 ;;
--no-launch) NO_LAUNCH=1 ;;
--help|-h)
cat <<'USAGE'
Usage: ./build.sh [--no-install] [--no-tests] [--no-launch]
Builds LinSCP inside the mounted Debian container.
USAGE
INNER_REACHED_END=yes
exit 0 ;;
*) warn "Ignoring unknown build argument: $arg" ;;
esac
done
trace $LINENO "start pwd=$PWD args=$*"
trace $LINENO "kernel=$(uname -a 2>/dev/null || true)"
trace $LINENO "user=$(id 2>/dev/null || true)"
trace $LINENO "shell=$BASH_VERSION pid=$$"
trace $LINENO "env DISPLAY=${DISPLAY:-<unset>} XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-<unset>}"
if have apt-get && [[ "$NO_INSTALL" != "1" ]]; then
trace $LINENO "apt dependency check/install START"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends \
ca-certificates build-essential g++ make pkg-config sqlite3 libsqlite3-dev \
python3 python3-tk openssh-client sshpass curl
trace $LINENO "apt dependency check/install SUCCESS"
else
warn "apt-get unavailable or --no-install set; skipping package install."
fi
trace $LINENO "tool-probe make=$(command -v make || true)"
trace $LINENO "tool-probe g++=$(command -v g++ || true)"
trace $LINENO "tool-probe sqlite3=$(command -v sqlite3 || true)"
trace $LINENO "tool-probe python3=$(command -v python3 || true)"
trace $LINENO "tool-probe python3-tk import=$(python3 -c 'import tkinter; print(tkinter.TkVersion)' 2>&1 || true)"
if ! have make; then echo "[LinSCP Build] PROCESS build FAILED! missing make"; exit 20; fi
if ! have g++; then echo "[LinSCP Build] PROCESS build FAILED! missing g++"; exit 21; fi
if [[ ! -f ./Makefile ]]; then echo "[LinSCP Build] PROCESS build FAILED! missing /work/Makefile"; exit 22; fi
trace $LINENO "make clean START"
make clean || true
trace $LINENO "make clean DONE"
trace $LINENO "make build-bin START jobs=${JOBS:-2}"
make -j"${JOBS:-2}" build-bin
trace $LINENO "make build-bin SUCCESS"
trace $LINENO "build-gui START"
if [[ ! -f ./linscp-gui ]]; then
echo "[LinSCP Build] PROCESS build FAILED! missing ./linscp-gui (Python launcher script)"
exit 23
fi
trace $LINENO "build-gui: shebang=$(head -n 1 ./linscp-gui)"
trace $LINENO "build-gui: line-count=$(wc -l < ./linscp-gui)"
if ! have python3; then
echo "[LinSCP Build] PROCESS build FAILED! python3 not on PATH; cannot validate ./linscp-gui"
exit 24
fi
trace $LINENO "build-gui: syntax check (python3 -m py_compile)"
python3 -m py_compile ./linscp-gui
trace $LINENO "build-gui: tkinter import probe"
python3 -c 'import tkinter; print("tk-version=" + str(tkinter.TkVersion))'
chmod +x ./linscp-gui
mkdir -p build
cp -f ./linscp-gui ./build/linscp-gui
chmod +x ./build/linscp-gui
trace $LINENO "build-gui SUCCESS staged=./build/linscp-gui"
trace $LINENO "post-build inventory:"
ls -la ./linscp ./linscp-gui ./build/linscp ./build/linscp-gui 2>&1 | sed 's/^/[LinSCP Build] /' || true
chmod +x ./linscp ./linscp-gui 2>/dev/null || true
if [[ "$NO_TEST" != "1" ]]; then
trace $LINENO "core-status START"
./linscp --core-status
trace $LINENO "core-status SUCCESS"
fi
trace $LINENO "PROCESS build SUCCESS! runnable=/work/linscp gui=/work/linscp-gui"
# Pick the executable to launch: prefer the GUI, fall back to CLI.
LAUNCH_BIN=""
if [[ -x ./linscp-gui ]]; then
LAUNCH_BIN="./linscp-gui"
trace $LINENO "launch-pick: linscp-gui is executable"
elif [[ -f ./linscp-gui ]]; then
trace $LINENO "launch-pick: linscp-gui exists but is NOT executable (stat below)"
stat ./linscp-gui 2>&1 | sed 's/^/[LinSCP Build] /' || true
elif [[ -x ./linscp ]]; then
LAUNCH_BIN="./linscp"
trace $LINENO "launch-pick: falling back to CLI ./linscp"
else
trace $LINENO "launch-pick: NEITHER linscp-gui nor linscp present/executable"
fi
if [[ "$NO_LAUNCH" == "1" ]]; then
trace $LINENO "--no-launch set; skipping launch"
INNER_REACHED_END=yes
exit 0
fi
if [[ -z "$LAUNCH_BIN" ]]; then
warn "No runnable binary found (linscp-gui / linscp)."
INNER_REACHED_END=yes
exit 0
fi
chmod +x "$LAUNCH_BIN" 2>/dev/null || true
trace $LINENO "Launching $LAUNCH_BIN ... (DISPLAY=${DISPLAY:-<unset>})"
if [[ -z "${DISPLAY:-}" ]] && [[ "$LAUNCH_BIN" == "./linscp-gui" ]]; then
warn "DISPLAY is unset; tk GUI cannot open a window inside this container."
warn "Skipping GUI launch. Run on host with X server, or pass --no-launch to suppress."
INNER_REACHED_END=yes
exit 0
fi
set +e
"$LAUNCH_BIN"
launch_rc=$?
set -e
trace $LINENO "launch exited rc=$launch_rc"
INNER_REACHED_END=yes
exit 0