Repository navigation
Expand file tree
/
Copy path01_networkSetup.sh
More file actions
executable file
·269 lines (242 loc) · 8.26 KB
/
Copy path01_networkSetup.sh
File metadata and controls
executable file
·269 lines (242 loc) · 8.26 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/bash
################################################################################
# Zelogx™ Multi-Project Secure Lab Setup
#
# © 2025 Zelogx. Zelogx™ and the Zelogx logo are trademarks
# of the Zelogx Project. All other marks are property of their respective owners.
#
# Filename: 01_networkSetup.sh
# Purpose: Phase 1 orchestrator - Network configuration and SDN setup
#
# Main functions/commands used:
# - 0103_clusterSetup.sh --restore: Revert cluster setup before rebuilding
# - 0102_setupNetwork.sh: Proxmox SDN and firewall configuration
# - 0103_clusterSetup.sh: Cluster (keepalived/VXLAN peers) setup via mslcm
# - prompt_router_setup / prompt_router_cleanup: Router guidance, shown once
# at the end (lib/router_prompt.sh)
#
# Dependencies:
# - 0102_setupNetwork.sh
# - 0103_clusterSetup.sh
# - .env generated by 00_configNetwork.sh
#
# Usage:
# ./01_networkSetup.sh [en|jp] [--restore]
#
# Notes:
# - Executes sub-scripts sequentially
# - Stops on first failure (die propagation)
# - Language parameter (en/jp) is passed to all sub-scripts
################################################################################
set -euo pipefail
# Determine script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
source "$SCRIPT_DIR/lib/common.sh"
source "$SCRIPT_DIR/lib/probe.sh"
print_usage() {
cat <<'USAGE'
Usage: ./01_networkSetup.sh [en|jp] [--restore]
en|jp Console language (default: en)
--restore Restore SDN/firewall to backup state and exit
USAGE
}
LANG_ARG="en"
RESTORE_ONLY=false
LANG_SET=false
while [[ $# -gt 0 ]]; do
case "$1" in
en|jp)
if [[ "$LANG_SET" == true ]]; then
echo "ERROR: Multiple language codes specified"
print_usage
exit 1
fi
LANG_ARG="$1"
LANG_SET=true
shift
;;
--restore)
RESTORE_ONLY=true
shift
;;
-h|--help)
print_usage
exit 0
;;
*)
echo "ERROR: Unknown argument: $1"
print_usage
exit 1
;;
esac
done
# Messages and router guidance (shown once at the end of this script)
source "$SCRIPT_DIR/lib/messages_${LANG_ARG}.sh"
source "$SCRIPT_DIR/lib/router_prompt.sh"
load_phase_uuid_or_exit "$LANG_ARG"
post_phase_probe_token "$LANG_ARG" "01_start"
setup_cmd=(./0102_setupNetwork.sh "$LANG_ARG")
if [[ "$RESTORE_ONLY" == true ]]; then
setup_cmd+=(--restore)
fi
cluster_cmd=(./0103_clusterSetup.sh "$LANG_ARG")
if [[ "$RESTORE_ONLY" == true ]]; then
cluster_cmd+=(--restore)
fi
cluster_restore_cmd=(./0103_clusterSetup.sh "$LANG_ARG" --restore)
if [[ "$RESTORE_ONLY" == true ]]; then
################################################################################
# Phase 1.1: Cluster Setup Restore (Restore first - reverse order)
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1.1: クラスタ設定リストア"
else
echo "Phase 1.1: Cluster Setup Restore"
fi
echo "=========================================="
echo ""
if ! "${cluster_cmd[@]}"; then
if [[ "$LANG_ARG" == "jp" ]]; then
echo ""
echo "エラー: クラスタ設定リストアが失敗しました"
else
echo ""
echo "ERROR: Cluster setup restore failed"
fi
exit 1
fi
################################################################################
# Phase 1.2: Setup Proxmox SDN and Firewall Restore (run after cluster restore)
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1.2: Proxmox SDN リストア"
else
echo "Phase 1.2: Proxmox SDN Restore"
fi
echo "=========================================="
echo ""
if ! "${setup_cmd[@]}"; then
if [[ "$LANG_ARG" == "jp" ]]; then
echo ""
echo "エラー: SDN リストアが失敗しました"
echo "詳細はログを確認してください: logs/"
else
echo ""
echo "ERROR: SDN restore failed"
echo "Check logs for details: logs/"
fi
exit 1
fi
################################################################################
# Phase 1 Restore Complete
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1 完了: ネットワーク設定をバックアップ状態に復元しました"
else
echo "Phase 1 Complete: Network Configuration Restored to Backup State"
fi
echo "=========================================="
prompt_router_cleanup
echo ""
exit 0
fi
################################################################################
# Phase 1.1: Cluster Setup Restore (pre-restore before normal setup)
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1.1: クラスタ設定リストア"
else
echo "Phase 1.1: Cluster Setup Restore"
fi
echo "=========================================="
echo ""
if ! "${cluster_restore_cmd[@]}"; then
if [[ "$LANG_ARG" == "jp" ]]; then
echo ""
echo "エラー: クラスタ設定リストアが失敗しました"
else
echo ""
echo "ERROR: Cluster setup restore failed"
fi
exit 1
fi
################################################################################
# Phase 1.2: Setup Proxmox SDN and Firewall
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1.2: Proxmox SDN セットアップ"
else
echo "Phase 1.2: Proxmox SDN Setup"
fi
echo "=========================================="
echo ""
if ! "${setup_cmd[@]}"; then
if [[ "$LANG_ARG" == "jp" ]]; then
echo ""
echo "エラー: SDN セットアップが失敗しました"
echo "詳細はログを確認してください: logs/"
else
echo ""
echo "ERROR: SDN setup failed"
echo "Check logs for details: logs/"
fi
exit 1
fi
################################################################################
# Phase 1.3: Cluster Setup
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1.3: クラスタセットアップ"
else
echo "Phase 1.3: Cluster Setup"
fi
echo "=========================================="
echo ""
if ! "${cluster_cmd[@]}"; then
if [[ "$LANG_ARG" == "jp" ]]; then
echo ""
echo "エラー: クラスタセットアップが失敗しました"
else
echo ""
echo "ERROR: Cluster setup failed"
fi
exit 1
fi
################################################################################
# Phase 1 Complete
################################################################################
echo ""
echo "=========================================="
if [[ "$LANG_ARG" == "jp" ]]; then
echo "フェーズ 1 完了: ネットワークセットアップ成功"
else
echo "Phase 1 Complete: Network Setup Successful"
fi
echo "=========================================="
# Router guidance: static route (PVE_IP, or the VIP in cluster mode) and port forwards
prompt_router_setup
echo ""
printf '%s' "${ROUTER_PROMPT_COLOR}"
if [[ "$LANG_ARG" == "jp" ]]; then
echo "次のステップ: 上記のルーター設定を行ってから、以下を実行してください:"
echo " ./02_vpnSetup.sh jp"
else
echo "Next step: after configuring your router as shown above, run:"
echo " ./02_vpnSetup.sh en"
fi
printf '%s' "${ROUTER_PROMPT_RESET}"
echo ""
exit 0