-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·129 lines (96 loc) · 4.04 KB
/
build
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
#!/usr/bin/env bash
# Make sure the current directory is the location of this script to simplify matters
cd "$(dirname $(readlink -f $0))";
################
### Settings ###
################
# The name of this project
project_name="Freeside Webhooks";
# The path to the lantern build engine git submodule
lantern_path="./lantern-build-engine";
###
# Custom Settings
###
# Put any custom settings here.
latest_release_json_url="https://api.github.com/repos/adnanh/webhook/releases/latest";
webhook_platform="linux";
webhook_arch="amd64";
###############################################################################
# Check out the lantern git submodule if needed
if [ ! -f "${lantern_path}/lantern.sh" ]; then git submodule update --init "${lantern_path}"; fi
source "${lantern_path}/lantern.sh";
if [[ "$#" -lt 1 ]]; then
echo -e "${FBLE}${project_name}${RS} build script";
echo -e " by Freeside";
echo -e "${LC}Powered by the lantern build engine, v${version}${RS}";
echo -e "";
echo -e "${CSECTION}Usage${RS}";
echo -e " ./build ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ${CTOKEN}{action}${RS} ...";
echo -e "";
echo -e "${CSECTION}Available actions${RS}";
echo -e " ${CACTION}setup${RS} - Perform initial setup";
echo -e " ${CACTION}update${RS} - Update webhook to the latest version";
echo -e "";
exit 1;
fi
###############################################################################
function task_setup {
task_begin "Checking environment";
check_command git true;
check_command curl true;
check_command jq true;
check_command rsyslogd true;
task_end $?;
task_begin "Initialising submodules";
git submodule update --init;
task_end $?;
task_begin "Checking environment file";
[ -f ".webhook-environment" ];
task_end $? "Error: Failed to find webhook environment file. Copy '.webhook-environment-example' to '.webhook-environment' and replace the specified values.";
task_begin "Installing rsyslog configuration";
execute sudo cp "./webhook-rsyslog.conf" "/etc/rsyslog.d/webhook.conf";
exit_code="$?";
execute sudo systemctl restart rsyslog.service;
task_end "${exit_code}" "Error: Failed to install rsyslog configuration file";
task_begin "Installing systemd service";
execute sudo cp "./webhook.service" "/etc/systemd/system/";
exit_code="$?";
execute sudo systemctl daemon-reload;
execute sudo systemctl enable webhook.service;
task_end "${exit_code}";
tasks_run update;
}
function task_update {
stage_begin "Downloading latest version of webhook";
task_begin "Creating temporary directory";
temp_dir="$(mktemp -d --suffix "-webhook-temp")";
task_end $? "Error: Failed to create temporary directory";
task_begin "Finding assets list";
assets_url="$(curl -sS "${latest_release_json_url}" | jq --raw-output ".assets_url")";
task_end $? "Error: Failed to find assets list";
task_begin "Finding platform-specific download url";
download_url="$(curl -sS "${assets_url}" | jq --raw-output ".[] | select(.name | contains(\"${webhook_platform}-${webhook_arch}\")) | .browser_download_url")";
task_end $? "Error: Failed to find download url";
task_begin "Downloading webhook archive";
execute curl -LsS -o "${temp_dir}/webhook.tar.gz" "${download_url}";
task_end $? "Error: Failed to download webhook archive";
task_begin "Extracting downloaded archive";
execute tar -xzf "${temp_dir}/webhook.tar.gz" -C "${temp_dir}";
execute rm "${temp_dir}/webhook.tar.gz";
task_end $? "Error: Failed to extract downloaded archive";
task_begin "Finding and moving webhook binary";
webhook_filepath="$(find "${temp_dir}" -type f -name "webhook" | head -n1)";
execute mv "${webhook_filepath}" "$(pwd)";
exit_code="$?";
execute rm -r "${temp_dir}";
task_end "${exit_code}" "Error: Failed to find and move webhook binary";
task_begin "Setting permissions";
chmod 0555 "./webhook";
task_end $?;
stage_end $?;
task_begin "Restarting webhook";
execute sudo systemctl restart webhook.service;
task_end $?;
}
###############################################################################
tasks_run $@;