-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbroadcast.sh
More file actions
executable file
·197 lines (178 loc) · 5.65 KB
/
broadcast.sh
File metadata and controls
executable file
·197 lines (178 loc) · 5.65 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
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
# Broadcast System Installation and Management Script
#
# This script provides functionality to install, upgrade, reboot, backup, and restore
# Broadcast, the email automation software.
# Usage: ./broadcast.sh {install|upgrade|reboot|backup|restore}
set -e
set -u
function getCurrentDir() {
local current_dir="${BASH_SOURCE%/*}"
if [[ ! -d "${current_dir}" ]]; then current_dir="$PWD"; fi
echo "${current_dir}"
}
function includeDependencies() {
source "${current_dir}/scripts/common.sh"
source "${current_dir}/scripts/install.sh"
source "${current_dir}/scripts/start.sh"
source "${current_dir}/scripts/stop.sh"
source "${current_dir}/scripts/restart.sh"
source "${current_dir}/scripts/backup.sh"
source "${current_dir}/scripts/restore.sh"
source "${current_dir}/scripts/upgrade.sh"
source "${current_dir}/scripts/downgrade.sh"
source "${current_dir}/scripts/monitor.sh"
source "${current_dir}/scripts/trigger.sh"
source "${current_dir}/scripts/update.sh"
source "${current_dir}/scripts/logs.sh"
}
function display_help() {
echo "Usage: $0 {install|update|upgrade|downgrade|restart|stop|start|backup|restore|help|monitor|trigger|change_installation_domain}"
echo
echo "Commands:"
echo " install Install Broadcast onto a fresh Ubuntu server"
echo " update Update Broadcast scripts"
echo " upgrade [version] Upgrade Broadcast images and restart the system"
echo " Optional version parameter (e.g., upgrade 1.2.3)"
echo " downgrade <version> Downgrade Broadcast to a specific version"
echo " Requires version parameter (e.g., downgrade 1.2.0)"
echo " restart Reboot Broadcast services"
echo " stop Stop Broadcast services"
echo " start Start Broadcast services"
echo " backup Backup Broadcast database and files to S3"
echo " backup_database Backup Broadcast primary database"
echo " restore Restore Broadcast primary database"
echo " help Display this help message"
echo " monitor Automated feedback of host metrics to the dashboard"
echo " trigger Automated check on triggers from Broadcast to the host"
echo " validate_license Validate the license for Broadcast"
echo " change_installation_domain Change the primary installation domain"
echo " generate_encryption_keys Generate Active Record encryption keys"
}
function set_safe_directory() {
echo "Setting /opt/broadcast as a safe directory for Git..."
git config --global --add safe.directory /opt/broadcast
echo "Safe directory set successfully."
}
function check_and_set_safe_directory() {
if ! git config --global --get safe.directory | grep -q "/opt/broadcast"; then
set_safe_directory
fi
}
function set_docker_image() {
local version="${1:-latest}"
local image_file="/opt/broadcast/.image"
local version_file="/opt/broadcast/.current_version"
# Architecture detection
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "arm64" ]; then
echo "DOCKER_IMAGE=gitea.hostedapp.org/broadcast/broadcast-arm:${version}" > "$image_file"
echo "TARGETARCH=arm64" >> "$image_file"
else
echo "DOCKER_IMAGE=gitea.hostedapp.org/broadcast/broadcast:${version}" > "$image_file"
fi
# Track current version deployment state
echo "${version}" > "$version_file"
echo "[$(date)] Set Docker image to version: ${version} (architecture: $(uname -m))"
}
main() {
current_dir=$(getCurrentDir)
includeDependencies
if [ $# -eq 0 ] || [ "$1" = "install" ]; then
display_logo
fi
check_root
check_installation_domain
check_license
# Check and set safe directory before processing any command
check_and_set_safe_directory
if [ $# -eq 0 ]; then
echo "Error: No argument provided"
display_help
exit
fi
case "$1" in
install)
# Only set docker image to latest for fresh installs
# Upgrade/downgrade commands set specific versions
set_docker_image "latest"
install
;;
upgrade)
if [ $# -gt 1 ]; then
# Pass version parameter if provided
upgrade "$2"
else
# Standard upgrade without version
upgrade
fi
;;
downgrade)
if [ $# -lt 2 ]; then
echo "Error: Target version is required for downgrade"
echo "Usage: $0 downgrade <version>"
exit 1
fi
downgrade "$2"
;;
_upgrade_continue)
# Internal command: called after scripts update to run with new code
_upgrade_continue "${2:-}"
;;
_downgrade_continue)
# Internal command: called after scripts update to run with new code
_downgrade_continue "${2:-}"
;;
update)
update
;;
restart)
restart
;;
stop)
stop
;;
start)
start
;;
backup)
backup
;;
backup_database)
backup_database
;;
restore)
restore "$2"
;;
monitor)
monitor
;;
trigger)
trigger
;;
validate_license)
validate_license
;;
change_installation_domain)
change_installation_domain
;;
generate_encryption_keys)
generate_encryption_keys
;;
logs)
if [ $# -lt 2 ]; then
echo "Usage: $0 logs <app|job|db>"
exit 1
fi
display_logs "$@"
;;
help)
display_help
;;
*)
echo "Usage: $0 {install|upgrade|restart|stop|start|backup|backup_database|restore|help|change_installation_domain}"
exit 1
;;
esac
}
# Call main function with all arguments
main "$@"