forked from finn/tinyboard
fix function ordering, permission check chains, and known_hosts check timing in setup-spoke.sh
This commit is contained in:
@@ -15,6 +15,23 @@ YELLOW='\033[1;33m'
|
|||||||
CYAN='\033[0;36m'
|
CYAN='\033[0;36m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
|
info() { echo -e "${GREEN}[+]${NC} $*"; }
|
||||||
|
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
|
||||||
|
die() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
|
||||||
|
header() { echo -e "\n${CYAN}══════════════════════════════════════════${NC}"; echo -e "${CYAN} $*${NC}"; echo -e "${CYAN}══════════════════════════════════════════${NC}"; }
|
||||||
|
|
||||||
|
check_deps() {
|
||||||
|
local missing=()
|
||||||
|
for cmd in "$@"; do
|
||||||
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
||||||
|
missing+=("$cmd")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ ${#missing[@]} -gt 0 ]; then
|
||||||
|
die "Missing required dependencies: ${missing[*]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
retry_or_abort() {
|
retry_or_abort() {
|
||||||
local test_cmd="$1"
|
local test_cmd="$1"
|
||||||
local fail_msg="$2"
|
local fail_msg="$2"
|
||||||
@@ -59,24 +76,6 @@ check_permissions() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
info() { echo -e "${GREEN}[+]${NC} $*"; }
|
|
||||||
check_deps() {
|
|
||||||
local missing=()
|
|
||||||
for cmd in "$@"; do
|
|
||||||
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
||||||
missing+=("$cmd")
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
if [ ${#missing[@]} -gt 0 ]; then
|
|
||||||
die "Missing required dependencies: ${missing[*]}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
|
|
||||||
die() { echo -e "${RED}[ERROR]${NC} $*" >&2; exit 1; }
|
|
||||||
header() { echo -e "\n${CYAN}══════════════════════════════════════════${NC}"; echo -e "${CYAN} $*${NC}"; echo -e "${CYAN}══════════════════════════════════════════${NC}"; }
|
|
||||||
|
|
||||||
[ "$(id -u)" -eq 0 ] || die "Run as root"
|
[ "$(id -u)" -eq 0 ] || die "Run as root"
|
||||||
|
|
||||||
check_deps ip ssh ssh-keygen ssh-keyscan systemctl hostnamectl
|
check_deps ip ssh ssh-keygen ssh-keyscan systemctl hostnamectl
|
||||||
@@ -266,14 +265,16 @@ fi
|
|||||||
|
|
||||||
info "Checking SSH key permissions..."
|
info "Checking SSH key permissions..."
|
||||||
check_permissions "$KEY_PATH" "spoke SSH private key"
|
check_permissions "$KEY_PATH" "spoke SSH private key"
|
||||||
[ -f "$KEY_PATH.pub" ] && check_permissions "$KEY_PATH.pub" "spoke SSH public key" || true
|
if [ -f "$KEY_PATH.pub" ]; then
|
||||||
check_permissions "$SSH_DIR/known_hosts" "known_hosts" || true
|
check_permissions "$KEY_PATH.pub" "spoke SSH public key"
|
||||||
|
fi
|
||||||
|
|
||||||
info "Scanning hub host key..."
|
info "Scanning hub host key..."
|
||||||
sudo -u "$SPOKE_USER" touch "$SSH_DIR/known_hosts"
|
sudo -u "$SPOKE_USER" touch "$SSH_DIR/known_hosts"
|
||||||
chown "$SPOKE_USER":"$SPOKE_USER" "$SSH_DIR/known_hosts"
|
chown "$SPOKE_USER":"$SPOKE_USER" "$SSH_DIR/known_hosts"
|
||||||
chmod 600 "$SSH_DIR/known_hosts"
|
chmod 600 "$SSH_DIR/known_hosts"
|
||||||
sudo -u "$SPOKE_USER" ssh-keyscan -H "$HUB_HOST" >> "$SSH_DIR/known_hosts" 2>/dev/null
|
sudo -u "$SPOKE_USER" ssh-keyscan -H "$HUB_HOST" >> "$SSH_DIR/known_hosts" 2>/dev/null
|
||||||
|
check_permissions "$SSH_DIR/known_hosts" "known_hosts"
|
||||||
|
|
||||||
header "Testing SSH Connection"
|
header "Testing SSH Connection"
|
||||||
info "Testing connection to $HUB_HOST..."
|
info "Testing connection to $HUB_HOST..."
|
||||||
|
|||||||
Reference in New Issue
Block a user