Skip to content

Commit f9d23d8

Browse files
committed
updated setups to use new logging system. setups no longer support --log, use --debug insted
1 parent d99a261 commit f9d23d8

File tree

4 files changed

+171
-133
lines changed

4 files changed

+171
-133
lines changed

install_modules.sh

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
11
#!/bin/sh
22
#
33
# install_modules.sh — install specified modules, or all in config/enabled_modules.conf if none given
4-
# Usage: ./install_modules.sh [--log[=FILE]] [-h] [module1 module2 ...]
4+
# Usage: ./install_modules.sh [--debug[=FILE]] [-h] [module1 module2 ...]
55

6-
set -x
7-
8-
#
9-
# 1) Figure out where this script lives
10-
#
6+
##############################################################################
7+
# 1) Locate this script’s path
8+
##############################################################################
119
case "$0" in
1210
*/*) SCRIPT_PATH="$0" ;;
1311
*) SCRIPT_PATH="$(command -v -- "$0" 2>/dev/null || printf "%s" "$0")" ;;
1412
esac
1513
SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd)"
1614

17-
#
15+
##############################################################################
1816
# 2) Determine PROJECT_ROOT, MODULE_DIR, and enabled‑modules file
19-
#
17+
##############################################################################
2018
if [ "$(basename "$SCRIPT_DIR")" = "scripts" ]; then
2119
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
2220
else
2321
PROJECT_ROOT="$SCRIPT_DIR"
2422
fi
2523
MODULE_DIR="$PROJECT_ROOT/modules"
2624
ENABLED_FILE="$PROJECT_ROOT/config/enabled_modules.conf"
25+
export PROJECT_ROOT
2726

28-
#
29-
# 3) Logging defaults
30-
#
31-
FORCE_LOG=0
32-
LOG_FILE=""
33-
34-
#
35-
# 4) Help text
36-
#
27+
##############################################################################
28+
# 3) Help text
29+
##############################################################################
3730
usage() {
3831
cat <<EOF
39-
Usage: $0 [--log[=FILE]] [-h] [module1 module2 ...]
32+
Usage: $0 [--debug[=FILE]] [-h] [module1 module2 ...]
4033
41-
--log, -l Capture stdout, stderr & xtrace into:
42-
${PROJECT_ROOT}/logs/
43-
Or use --log=FILE for a custom path.
34+
--debug, -d Enable xtrace and capture all output (stdout/stderr/xtrace)
35+
into logs/ (or into FILE if you do --debug=FILE).
4436
4537
-h, --help Show this help and exit.
4638
@@ -50,71 +42,82 @@ EOF
5042
exit 0
5143
}
5244

53-
#
54-
# 5) Parse flags
55-
#
45+
# show help?
46+
case "$1" in
47+
-h|--help) usage ;;
48+
esac
49+
50+
##############################################################################
51+
# 4) Parse just --debug
52+
##############################################################################
53+
DEBUG_MODE=0
54+
DEBUG_LOGFILE=""
5655
while [ $# -gt 0 ]; do
5756
case "$1" in
58-
-l|--log) FORCE_LOG=1 ;;
59-
-l=*|--log=*) FORCE_LOG=1; LOG_FILE="${1#*=}" ;;
60-
-h|--help) usage ;;
61-
--) shift; break ;;
57+
-d|--debug)
58+
DEBUG_MODE=1
59+
shift
60+
;;
61+
-d=*|--debug=*)
62+
DEBUG_MODE=1
63+
DEBUG_LOGFILE="${1#*=}"
64+
shift
65+
;;
66+
--) shift; break ;;
6267
-*)
6368
echo "Unknown option: $1" >&2
6469
usage
6570
;;
6671
*) break ;;
6772
esac
68-
shift
6973
done
7074

71-
#
72-
# 6) Locate and source logging helper
73-
LOG_HELPER="$PROJECT_ROOT/logs/logging.sh"
74-
75-
if [ ! -f "$LOG_HELPER" ]; then
76-
echo "$LOG_HELPER not found. Aborting." >&2
77-
exit 1
75+
# build flag to pass to module scripts
76+
if [ "$DEBUG_MODE" -eq 1 ]; then
77+
if [ -n "$DEBUG_LOGFILE" ]; then
78+
DBG_FLAG="--debug=$DEBUG_LOGFILE"
79+
else
80+
DBG_FLAG="--debug"
81+
fi
7882
fi
7983

80-
# shellcheck source=logs/logging.sh
81-
. "$LOG_HELPER"
82-
init_logging "$0"
83-
84+
##############################################################################
85+
# 5) Initialize logging+xtrace if requested
86+
##############################################################################
87+
# shellcheck source=../logs/logging.sh
88+
. "$PROJECT_ROOT/logs/logging.sh"
89+
if [ "$DEBUG_MODE" -eq 1 ]; then
90+
set -x
91+
init_logging "$(basename "$0" .sh)"
92+
fi
8493

85-
#
86-
# 7) Determine module list
87-
#
94+
##############################################################################
95+
# 6) Determine module list
96+
##############################################################################
8897
if [ "$#" -gt 0 ]; then
8998
MODULES="$*"
9099
else
91-
if [ ! -f "$ENABLED_FILE" ]; then
100+
[ -f "$ENABLED_FILE" ] || {
92101
echo "❌ No modules specified and $ENABLED_FILE not found" >&2
93102
exit 1
94-
fi
103+
}
95104
MODULES="$(grep -Ev '^\s*(#|$)' "$ENABLED_FILE")"
96105
fi
97106

98-
#
99-
# 8) Always install base-system first (if present)
100-
#
107+
##############################################################################
108+
# 7) Install basesystem first (if present)
109+
##############################################################################
101110
echo "🔧 Installing prerequisite module: base-system"
102-
sh "$MODULE_DIR/base-system/setup.sh"
111+
sh "$MODULE_DIR/base-system/setup.sh" ${DBG_FLAG}
103112

104-
#
105-
# 9) Install the rest of the modules
106-
#
113+
##############################################################################
114+
# 8) Install the rest
115+
##############################################################################
107116
for mod in $MODULES; do
108117
[ "$mod" = "base-system" ] && continue
109-
110-
DIR="$MODULE_DIR/$mod"
111-
# pick the setup script (generic or fallback)
112-
SETUP="$DIR/setup.sh"
113-
114118
echo "👉 Installing module: $mod"
115-
sh "$SETUP"
119+
sh "$MODULE_DIR/$mod/setup.sh" ${DBG_FLAG}
116120
done
117121

118122
echo ""
119123
echo "✅ All requested modules installed."
120-

modules/base-system/setup.sh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,51 @@
11
#!/bin/sh
22
#
33
# setup.sh — General system configuration for OpenBSD Server (base‑system module)
4-
5-
set -x # -e: exit on any error; -x: trace commands
4+
# Usage: ./setup.sh [--debug[=FILE]] [-h]
65

76
# 1) Locate project root
87
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
98
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
9+
export PROJECT_ROOT
10+
11+
# 2) Load logging system and parse --debug
12+
# shellcheck source=../../logs/logging.sh
13+
. "$PROJECT_ROOT/logs/logging.sh"
14+
parse_logging_flags "$@"
15+
set -- $REMAINING_ARGS
1016

11-
# 2) Load secrets (INTERFACE, GIT_SERVER, NETMASK, GATEWAY, DNS1, DNS2)
17+
module_name="$(basename "$SCRIPT_DIR")"
18+
if [ "$DEBUG_MODE" -eq 1 ]; then
19+
set -x # enable xtrace
20+
init_logging "setup-$module_name"
21+
fi
22+
23+
# 3) Load secrets (INTERFACE, GIT_SERVER, NETMASK, GATEWAY, DNS1, DNS2)
1224
. "$PROJECT_ROOT/config/load_secrets.sh"
1325

14-
# 3) Write interface config
26+
# 4) Write interface config
1527
cat > "/etc/hostname.${INTERFACE}" <<-EOF
1628
inet ${GIT_SERVER} ${NETMASK}
1729
!route add default ${GATEWAY}
1830
EOF
1931

20-
# 4) Write resolv.conf
32+
# 5) Write resolv.conf
2133
cat > /etc/resolv.conf <<-EOF
2234
nameserver ${DNS1}
2335
nameserver ${DNS2}
2436
EOF
2537
chmod 644 /etc/resolv.conf
2638

27-
# 5) Bring up interface & default route
39+
# 6) Bring up interface & default route
2840
ifconfig "${INTERFACE}" inet "${GIT_SERVER}" netmask "${NETMASK}" up
2941
route add default "${GATEWAY}"
3042

31-
# 6) SSH hardening
43+
# 7) SSH hardening
3244
sed -i 's/^#*PermitRootLogin .*/PermitRootLogin no/' /etc/ssh/sshd_config
3345
sed -i 's/^#*PasswordAuthentication .*/PasswordAuthentication no/' /etc/ssh/sshd_config
3446
rcctl restart sshd
3547

36-
# 7) Root history settings
48+
# 8) Root history settings
3749
cat << 'EOF' >> /root/.profile
3850
export HISTFILE=/root/.ksh_history
3951
export HISTSIZE=5000
@@ -42,4 +54,3 @@ EOF
4254
. /root/.profile
4355

4456
echo "✅ base‑system: system configuration complete."
45-

modules/github/setup.sh

100755100644
Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,54 @@
1-
# modules/github/setup.sh — GitHub deploy key & repo bootstrap (github module)
2-
31
#!/bin/sh
4-
#set -x # -e: exit on error; -x: trace commands
2+
#
3+
# setup.sh — GitHub deploy key & repo bootstrap (github module)
4+
# Usage: ./setup.sh [--debug[=FILE]] [-h]
55

66
# 1) Determine script & project paths
77
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
88
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
9+
export PROJECT_ROOT
10+
11+
# 2) Load logging system and parse --debug
12+
# shellcheck source=../../logs/logging.sh
13+
. "$PROJECT_ROOT/logs/logging.sh"
14+
parse_logging_flags "$@"
15+
set -- $REMAINING_ARGS
16+
17+
module_name="$(basename "$SCRIPT_DIR")"
18+
if [ "$DEBUG_MODE" -eq 1 ]; then
19+
set -x # enable xtrace
20+
init_logging "setup-$module_name"
21+
fi
922

10-
# 2) Load secrets (LOCAL_DIR, GITHUB_REPO)
23+
# 3) Load secrets (LOCAL_DIR, GITHUB_REPO)
1124
. "$PROJECT_ROOT/config/load_secrets.sh"
1225

13-
# 3) Deploy-key path
26+
# 4) Deploy-key path
1427
DEPLOY_KEY="$PROJECT_ROOT/config/deploy_key"
1528

16-
# 4) Validate deploy key exists
29+
# 5) Validate deploy key exists
1730
[ -f "$DEPLOY_KEY" ] || { echo "ERROR: deploy_key not found at $DEPLOY_KEY" >&2; exit 1; }
1831

19-
# 5) Install key into root's SSH
32+
# 6) Install key into root's SSH
2033
mkdir -p /root/.ssh
2134
cp "$DEPLOY_KEY" /root/.ssh/id_ed25519
2235
chmod 600 /root/.ssh/id_ed25519
2336

24-
# 6) Add GitHub to known_hosts
37+
# 7) Add GitHub to known_hosts
2538
ssh-keyscan github.com >> /root/.ssh/known_hosts
2639

27-
# 7) Validate secrets for cloning
28-
: "LOCAL_DIR=$LOCAL_DIR" # ensure variable is set
40+
# 8) Validate secrets for cloning
41+
: "LOCAL_DIR=$LOCAL_DIR" # ensure variable is set
2942
: "GITHUB_REPO=$GITHUB_REPO" # ensure variable is set
3043

31-
[ -n "$LOCAL_DIR" ] || { echo "ERROR: LOCAL_DIR not set" >&2; exit 1; }
44+
[ -n "$LOCAL_DIR" ] || { echo "ERROR: LOCAL_DIR not set" >&2; exit 1; }
3245
[ -n "$GITHUB_REPO" ] || { echo "ERROR: GITHUB_REPO not set" >&2; exit 1; }
3346

34-
# 8) Clone or update the repo
47+
# 9) Clone or update the repo
3548
if [ ! -d "${LOCAL_DIR}/.git" ]; then
3649
git clone "$GITHUB_REPO" "$LOCAL_DIR"
3750
else
3851
git -C "$LOCAL_DIR" pull
3952
fi
4053

4154
echo "✅ github: GitHub configuration complete."
42-

0 commit comments

Comments
 (0)