Skip to content

Commit d99a261

Browse files
committed
remade some lost changes
1 parent 6240d1d commit d99a261

File tree

5 files changed

+101
-68
lines changed

5 files changed

+101
-68
lines changed

install_modules.sh

100755100644
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ENABLED_FILE="$PROJECT_ROOT/config/enabled_modules.conf"
2929
# 3) Logging defaults
3030
#
3131
FORCE_LOG=0
32-
LOGFILE=""
32+
LOG_FILE=""
3333

3434
#
3535
# 4) Help text
@@ -56,7 +56,7 @@ EOF
5656
while [ $# -gt 0 ]; do
5757
case "$1" in
5858
-l|--log) FORCE_LOG=1 ;;
59-
-l=*|--log=*) FORCE_LOG=1; LOGFILE="${1#*=}" ;;
59+
-l=*|--log=*) FORCE_LOG=1; LOG_FILE="${1#*=}" ;;
6060
-h|--help) usage ;;
6161
--) shift; break ;;
6262
-*)
@@ -69,24 +69,24 @@ while [ $# -gt 0 ]; do
6969
done
7070

7171
#
72-
# 6) Logging init (your existing helper)
73-
#
74-
if [ -f "$PROJECT_ROOT/logs/logging.sh" ]; then
75-
LOG_HELPER="$PROJECT_ROOT/logs/logging.sh"
76-
elif [ -f "$PROJECT_ROOT/../logs/logging.sh" ]; then
77-
LOG_HELPER="$PROJECT_ROOT/../logs/logging.sh"
78-
else
79-
echo "❌ logging.sh not found in logs/ or ../logs/" >&2
80-
exit 1
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
8178
fi
79+
80+
# shellcheck source=logs/logging.sh
8281
. "$LOG_HELPER"
8382
init_logging "$0"
8483

84+
8585
#
8686
# 7) Determine module list
8787
#
8888
if [ "$#" -gt 0 ]; then
89-
MODULES="$@"
89+
MODULES="$*"
9090
else
9191
if [ ! -f "$ENABLED_FILE" ]; then
9292
echo "❌ No modules specified and $ENABLED_FILE not found" >&2

modules/github/setup.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# modules/github/setup.sh — GitHub deploy key & repo bootstrap (github module)
22

33
#!/bin/sh
4-
set -x # -e: exit on error; -x: trace commands
4+
#set -x # -e: exit on error; -x: trace commands
55

6-
# 1) Determine script & project paths\ nSCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6+
# 1) Determine script & project paths
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
78
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
89

910
# 2) Load secrets (LOCAL_DIR, GITHUB_REPO)

modules/github/test.sh

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,58 @@
44
# Usage: $(basename "$0") [--log[=FILE]] [--debug] [-h]
55
#
66

7-
# 1) Locate real path & module’s script dir
7+
##############################################################################
8+
# 1) Resolve paths and load logging helpers
9+
##############################################################################
810
case "$0" in
9-
*/*) SCRIPT_PATH="$0" ;;
10-
*) SCRIPT_PATH="$PWD/$0" ;;
11+
*/*) SCRIPT_PATH="$0";;
12+
*) SCRIPT_PATH="$PWD/$0";;
1113
esac
12-
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
13-
14-
# 2) Compute project root (two levels up) & export
15-
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
14+
SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd)"
15+
PROJECT_ROOT="$(cd -- "$SCRIPT_DIR/../.." && pwd)"
1616
export PROJECT_ROOT
1717

18-
# 3) Source logging helper & parse flags
18+
# shellcheck source=../../logs/logging.sh
1919
. "$PROJECT_ROOT/logs/logging.sh"
20+
21+
##############################################################################
22+
# 2) Parse flags and initialize logging
23+
##############################################################################
2024
parse_logging_flags "$@"
21-
eval "set -- $REMAINING_ARGS"
25+
set -- $REMAINING_ARGS
2226

23-
# 4) Turn on xtrace if debugging, else initialize our own log
24-
if [ "$DEBUG_MODE" -eq 1 ] || [ "$FORCE_LOG" -eq 1 ]; then
25-
set -x
26-
NEED_FINALIZE=0
27+
if { [ "$FORCE_LOG" -eq 1 ] || [ "$DEBUG_MODE" -eq 1 ]; } && [ -z "$LOGGING_INITIALIZED" ]; then
28+
module=$(basename "$SCRIPT_DIR")
29+
init_logging "${module}-$(basename "$0")"
2730
else
28-
init_logging "test-$(basename "$SCRIPT_DIR")"
29-
NEED_FINALIZE=1
31+
init_logging "$0"
3032
fi
33+
trap finalize_logging EXIT
34+
[ "$DEBUG_MODE" -eq 1 ] && set -x
3135

32-
# 5) Handle help
36+
##############################################################################
37+
# 3) Show help
38+
##############################################################################
3339
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
3440
echo "Usage: $0 [--log[=FILE]] [--debug] [-h]"
35-
[ "$NEED_FINALIZE" -eq 1 ] && finalize_logging
3641
exit 0
3742
fi
3843

39-
# 6) Load secrets
44+
##############################################################################
45+
# 4) Load secrets
46+
##############################################################################
47+
# shellcheck source=../../config/load_secrets.sh
4048
. "$PROJECT_ROOT/config/load_secrets.sh"
4149

42-
# 7) Default fallbacks (if secrets aren’t set)
50+
##############################################################################
51+
# 5) Default fallbacks (if secrets aren’t set)
52+
##############################################################################
4353
LOCAL_DIR="${LOCAL_DIR:-/root/openbsd-server}"
4454
GITHUB_REPO="${GITHUB_REPO:-git@github.com:deadhedd/openbsd-server.git}"
4555

46-
# 8) Test helpers
56+
##############################################################################
57+
# 6) Test helpers
58+
##############################################################################
4759
run_test() {
4860
desc="$2"
4961
if eval "$1" >/dev/null 2>&1; then
@@ -54,7 +66,9 @@ run_test() {
5466
fi
5567
}
5668

57-
# 9) Define & run tests
69+
##############################################################################
70+
# 7) Define & run tests
71+
##############################################################################
5872
run_tests() {
5973
echo "1..7"
6074
run_test "[ -d /root/.ssh ]" "root .ssh directory exists"
@@ -68,8 +82,11 @@ run_tests() {
6882

6983
run_tests
7084

71-
# 10) Finalize logging if we created our own
72-
[ "$NEED_FINALIZE" -eq 1 ] && finalize_logging
73-
74-
# 11) Exit with failure status if any test failed
75-
exit $([ "$TEST_FAILED" -ne 0 ] && echo 1 || echo 0)
85+
##############################################################################
86+
# 8) Exit with status
87+
##############################################################################
88+
if [ "$TEST_FAILED" -ne 0 ]; then
89+
exit 1
90+
else
91+
exit 0
92+
fi

modules/obsidian-git-host/test.sh

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,61 @@
44
# Usage: $(basename "$0") [--log[=FILE]] [--debug] [-h]
55
#
66

7-
# 1) Locate real path & module’s script dir
7+
##############################################################################
8+
# 1) Resolve paths and load logging helpers
9+
##############################################################################
810
case "$0" in
9-
*/*) SCRIPT_PATH="$0" ;;
10-
*) SCRIPT_PATH="$PWD/$0" ;;
11+
*/*) SCRIPT_PATH="$0";;
12+
*) SCRIPT_PATH="$PWD/$0";;
1113
esac
12-
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
13-
14-
# 2) Compute project root (two levels up) & export
15-
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
14+
SCRIPT_DIR="$(cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd)"
15+
PROJECT_ROOT="$(cd -- "$SCRIPT_DIR/../.." && pwd)"
1616
export PROJECT_ROOT
1717

18-
# 3) Source logging helper & parse flags
1918
. "$PROJECT_ROOT/logs/logging.sh"
19+
20+
##############################################################################
21+
# 2) Parse flags and initialize logging
22+
##############################################################################
2023
parse_logging_flags "$@"
21-
eval "set -- $REMAINING_ARGS"
24+
set -- $REMAINING_ARGS
2225

23-
# 4) Turn on xtrace if debugging, else initialize our own log
24-
if [ "$DEBUG_MODE" -eq 1 ] || [ "$FORCE_LOG" -eq 1 ]; then
25-
set -x
26-
NEED_FINALIZE=0
26+
if { [ "$FORCE_LOG" -eq 1 ] || [ "$DEBUG_MODE" -eq 1 ]; } && [ -z "$LOGGING_INITIALIZED" ]; then
27+
module=$(basename "$SCRIPT_DIR")
28+
init_logging "${module}-$(basename "$0")"
2729
else
28-
init_logging "test-$(basename "$SCRIPT_DIR")"
29-
NEED_FINALIZE=1
30+
init_logging "$0"
3031
fi
32+
trap finalize_logging EXIT
33+
[ "$DEBUG_MODE" -eq 1 ] && set -x
3134

32-
# 5) Handle help
35+
##############################################################################
36+
# 3) Show help
37+
##############################################################################
3338
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
3439
echo "Usage: $0 [--log[=FILE]] [--debug] [-h]"
35-
[ "$NEED_FINALIZE" -eq 1 ] && finalize_logging
3640
exit 0
3741
fi
3842

39-
# 6) Load secrets
43+
##############################################################################
44+
# 4) Load secrets & validate
45+
##############################################################################
4046
. "$PROJECT_ROOT/config/load_secrets.sh"
4147
: "${OBS_USER:?OBS_USER must be set in secrets}"
4248
: "${GIT_USER:?GIT_USER must be set in secrets}"
4349
: "${VAULT:?VAULT must be set in secrets}"
4450
: "${GIT_SERVER:?GIT_SERVER must be set in secrets}"
4551

46-
# 7) Compute paths
52+
##############################################################################
53+
# 5) Compute paths
54+
##############################################################################
4755
OBS_HOME="/home/${OBS_USER}"
4856
BARE_REPO="/home/${GIT_USER}/vaults/${VAULT}.git"
4957
WORK_TREE="${OBS_HOME}/vaults/${VAULT}"
5058

51-
# 8) Test helpers
59+
##############################################################################
60+
# 6) Test helpers
61+
##############################################################################
5262
run_test() {
5363
desc="$2"
5464
if eval "$1" >/dev/null 2>&1; then
@@ -72,7 +82,9 @@ check_entry() {
7282
"safe.directory for $3: $2"
7383
}
7484

75-
# 9) Define & run tests
85+
##############################################################################
86+
# 7) Define & run tests
87+
##############################################################################
7688
run_tests() {
7789
echo "1..45"
7890

@@ -95,7 +107,7 @@ run_tests() {
95107
# Bare repo ownership & perms
96108
run_test "stat -f '%Su:%Sg' ${BARE_REPO} | grep -q '^${GIT_USER}:vault\$'" \
97109
"ownership of '${BARE_REPO}' is '${GIT_USER}:vault'"
98-
run_test "! find ${BARE_REPO} \( -not -user ${GIT_USER} -or -not -group vault \) -print | grep -q ." \
110+
run_test "! find ${BARE_REPO} \\( -not -user ${GIT_USER} -or -not -group vault \\) -print | grep -q ." \
99111
"all files under '${BARE_REPO}' are owned by ${GIT_USER}:vault"
100112
run_test "! find ${BARE_REPO} -not -perm -g=r -print | grep -q ." "all entries under '${BARE_REPO}' are group-readable"
101113
run_test "! find ${BARE_REPO} -not -perm -g=w -print | grep -q ." "all entries under '${BARE_REPO}' are group-writable"
@@ -166,8 +178,11 @@ run_tests() {
166178

167179
run_tests
168180

169-
# 10) Finalize logging if we created our own
170-
[ "$NEED_FINALIZE" -eq 1 ] && finalize_logging
171-
172-
# 11) Exit with failure status if any test failed
173-
exit $([ "$TEST_FAILED" -ne 0 ] && echo 1 || echo 0)
181+
##############################################################################
182+
# 8) Exit with status
183+
##############################################################################
184+
if [ "$TEST_FAILED" -ne 0 ]; then
185+
exit 1
186+
else
187+
exit 0
188+
fi

test_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fi
4141

4242
# 4) Determine which modules to test
4343
if [ "$#" -gt 0 ]; then
44-
MODULES="$@"
44+
MODULES="$*"
4545
if [ "$DEBUG_MODE" -eq 1 ]; then
4646
echo "DEBUG(test_all): modules from args -> $MODULES" >&3
4747
fi

0 commit comments

Comments
 (0)