-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautobuild
More file actions
97 lines (77 loc) · 2.76 KB
/
Copy pathautobuild
File metadata and controls
97 lines (77 loc) · 2.76 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
#!/usr/bin/env bash
# autobuild client
# Copyright (C) 2024 rail5
# Free software (GNU Affero GPL v3)
temporary_storage_directory="$(mktemp --tmpdir -d autobuild.file.XXXXXXXXXXXX)"
temporary_log_file=$(mktemp --tmpdir autobuild.log.XXXXXXXXXXXX)
autobuild_storage_directory="/var/autobuild"
# shellcheck disable=SC2124
passed_options="${@@Q}"
trap 'graceful_exit' INT
trap 'graceful_exit' TERM
trap 'graceful_exit' HUP
function get_daemon_pid() {
head -n 1 "$temporary_log_file" | awk '{print $2}'
}
function get_job_id() {
sed -n '2{p;q;}' "$temporary_log_file" | awk '{print $2}'
}
function graceful_exit() {
if [[ -f "$temporary_log_file" ]]; then
pid_to_kill=$(get_daemon_pid)
socat -t 86400 - UNIX-CONNECT:/var/run/autobuild.socket >/dev/null 2>&1 <<<"-k $pid_to_kill" # Send kill command to daemon
tail --pid="$pid_to_kill" -f /dev/null 2>/dev/null
rm -f "/tmp/autobuild.kill.$pid_to_kill" 2>/dev/null
rm -f "$temporary_log_file" 2>/dev/null
fi
if [[ -d "$temporary_storage_directory" ]]; then
rm -rf "${temporary_storage_directory:?}"
fi
exit 0
}
# getopt
TEMP=$(getopt -o bo:p:s --long bell,output:,package:,setup \
-q -- "$@")
eval set -- "$TEMP"
ring_bell=false
output_directory=$(pwd)
while true; do
case "$1" in
-b | --bell )
ring_bell=true; shift ;;
-o | --output )
output_directory=$(realpath "$2")
shift 2 ;;
-p | --package )
# Make sure the autobuild daemon can *read* any files we might give it for the package
if [[ -f "$2" && "$2" == *".tar.gz" ]]; then
file_basename="$(basename "$(realpath "$2")")"
temporary_file_path="$temporary_storage_directory/$file_basename"
cp "$(realpath "$2")" "$temporary_file_path"
chmod -R 755 "$temporary_storage_directory/"
passed_options="${passed_options/$2/"$temporary_file_path"}"
fi
shift 2 ;;
-s | --setup )
if [[ "$(whoami)" != root ]]; then
echo "-s must be run as root"
echo "Try again with 'sudo'"
graceful_exit
fi
sudo -u _autobuild autobuild-setup
graceful_exit ;;
-- ) shift; break ;;
* ) break ;;
esac
done
# Run the autobuild daemon to build the packages, write the responses to the terminal window and to the temporary log file
socat -t 86400 - UNIX-CONNECT:/var/run/autobuild.socket <<<"$passed_options" | tee "$temporary_log_file"
# Pull the built packages from /var/autobuild/builds and save them in the output directory
cp -r "$autobuild_storage_directory/builds/$(get_job_id)/"* "$output_directory/" 2>/dev/null
# Ask the autobuild daemon to delete the builds from /var/autobuild/builds so we don't waste space
socat - UNIX-CONNECT:/var/run/autobuild.socket <<<"-r $(get_job_id)" >/dev/null
# Ring the bell if the user asked for it
if [[ $ring_bell == true ]]; then
paplay /usr/share/autobuild/bell.ogg
fi
graceful_exit