permission issue hotfix
Some checks failed
Build and Deploy to K3s / test (push) Successful in 2m6s
Build and Deploy to K3s / lint (push) Successful in 1m33s
Build and Deploy to K3s / build-and-push (push) Successful in 53s
Build and Deploy to K3s / deploy (push) Failing after 8s

This commit is contained in:
jasonwitty 2025-11-30 03:49:09 -08:00
parent e0535a033b
commit 39e0f55fc4

View File

@ -12,17 +12,41 @@ echo "==================================="
# Determine the actual HOME directory for the socktop user
SOCKTOP_HOME=$(eval echo ~socktop)
echo "Socktop HOME: ${SOCKTOP_HOME}"
echo "Current user: $(whoami) (UID: $(id -u))"
# Check if we're running as root
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, will set permissions"
# Create necessary directories in the actual HOME
echo "Running as root, will create directories and set permissions"
# Ensure socktop user's home directory exists and has correct ownership
if [ ! -d "${SOCKTOP_HOME}" ]; then
echo "Creating ${SOCKTOP_HOME}..."
mkdir -p "${SOCKTOP_HOME}"
chown socktop:socktop "${SOCKTOP_HOME}"
fi
# Ensure the directory is writable by socktop user
chown socktop:socktop "${SOCKTOP_HOME}"
# Create necessary directories as root, then fix ownership
echo "Creating config directories..."
mkdir -p "${SOCKTOP_HOME}/.config/socktop/certs"
mkdir -p "${SOCKTOP_HOME}/.config/alacritty"
chown -R socktop:socktop "${SOCKTOP_HOME}/.config"
echo " ✓ Created directories with correct ownership"
else
echo "Running as non-root user ($(id -u)), creating directories without root"
echo "Running as non-root user ($(id -u)), creating directories"
# Try to create directories - will work if HOME is writable
mkdir -p "${SOCKTOP_HOME}/.config/socktop/certs" 2>/dev/null || echo " ⚠ Could not create directories (may already exist)"
mkdir -p "${SOCKTOP_HOME}/.config/socktop/certs" 2>/dev/null || {
echo " ⚠ Could not create directories - checking if they already exist..."
if [ -d "${SOCKTOP_HOME}/.config/socktop/certs" ]; then
echo " ✓ Directories already exist"
else
echo " ✗ Failed to create directories and they don't exist"
exit 1
fi
}
mkdir -p "${SOCKTOP_HOME}/.config/alacritty" 2>/dev/null || true
fi
@ -31,7 +55,14 @@ echo "Copying configuration files..."
# Copy profiles.json
if [ -f "/home/socktop/.config/socktop/profiles.json" ]; then
cp /home/socktop/.config/socktop/profiles.json "${SOCKTOP_HOME}/.config/socktop/profiles.json"
if [ "$(id -u)" -eq 0 ]; then
# Copy as root, then fix ownership
cp -f /home/socktop/.config/socktop/profiles.json "${SOCKTOP_HOME}/.config/socktop/profiles.json"
chown socktop:socktop "${SOCKTOP_HOME}/.config/socktop/profiles.json"
chmod 644 "${SOCKTOP_HOME}/.config/socktop/profiles.json"
else
cp -f /home/socktop/.config/socktop/profiles.json "${SOCKTOP_HOME}/.config/socktop/profiles.json"
fi
echo " ✓ Copied profiles.json"
else
echo " ⚠ profiles.json not found at mount point"
@ -39,7 +70,13 @@ fi
# Copy alacritty.toml
if [ -f "/home/socktop/.config/alacritty/alacritty.toml" ]; then
cp /home/socktop/.config/alacritty/alacritty.toml "${SOCKTOP_HOME}/.config/alacritty/alacritty.toml"
if [ "$(id -u)" -eq 0 ]; then
cp -f /home/socktop/.config/alacritty/alacritty.toml "${SOCKTOP_HOME}/.config/alacritty/alacritty.toml"
chown socktop:socktop "${SOCKTOP_HOME}/.config/alacritty/alacritty.toml"
chmod 644 "${SOCKTOP_HOME}/.config/alacritty/alacritty.toml"
else
cp -f /home/socktop/.config/alacritty/alacritty.toml "${SOCKTOP_HOME}/.config/alacritty/alacritty.toml"
fi
echo " ✓ Copied alacritty.toml"
else
echo " ⚠ alacritty.toml not found at mount point"
@ -47,7 +84,13 @@ fi
# Copy catppuccin-frappe.toml
if [ -f "/home/socktop/.config/alacritty/catppuccin-frappe.toml" ]; then
cp /home/socktop/.config/alacritty/catppuccin-frappe.toml "${SOCKTOP_HOME}/.config/alacritty/catppuccin-frappe.toml"
if [ "$(id -u)" -eq 0 ]; then
cp -f /home/socktop/.config/alacritty/catppuccin-frappe.toml "${SOCKTOP_HOME}/.config/alacritty/catppuccin-frappe.toml"
chown socktop:socktop "${SOCKTOP_HOME}/.config/alacritty/catppuccin-frappe.toml"
chmod 644 "${SOCKTOP_HOME}/.config/alacritty/catppuccin-frappe.toml"
else
cp -f /home/socktop/.config/alacritty/catppuccin-frappe.toml "${SOCKTOP_HOME}/.config/alacritty/catppuccin-frappe.toml"
fi
echo " ✓ Copied catppuccin-frappe.toml"
else
echo " ⚠ catppuccin-frappe.toml not found at mount point"
@ -55,9 +98,16 @@ fi
# Copy certificates if they exist
if [ -d "/home/socktop/.config/socktop/certs" ]; then
echo "Copying certificates..."
for cert in /home/socktop/.config/socktop/certs/*.pem; do
if [ -f "$cert" ]; then
cp "$cert" "${SOCKTOP_HOME}/.config/socktop/certs/"
if [ "$(id -u)" -eq 0 ]; then
cp -f "$cert" "${SOCKTOP_HOME}/.config/socktop/certs/"
chown socktop:socktop "${SOCKTOP_HOME}/.config/socktop/certs/$(basename "$cert")"
chmod 644 "${SOCKTOP_HOME}/.config/socktop/certs/$(basename "$cert")"
else
cp -f "$cert" "${SOCKTOP_HOME}/.config/socktop/certs/"
fi
echo " ✓ Copied $(basename "$cert")"
fi
done
@ -65,26 +115,28 @@ else
echo " No certificates directory found (optional)"
fi
# Set proper ownership (only if running as root)
if [ "$(id -u)" -eq 0 ]; then
chown -R socktop:socktop "${SOCKTOP_HOME}/.config"
echo " ✓ Set ownership to socktop:socktop"
fi
# Fix paths in profiles.json if it exists
if [ -f "${SOCKTOP_HOME}/.config/socktop/profiles.json" ]; then
echo "Rewriting paths in profiles.json..."
# Replace /home/socktop with actual HOME directory and ensure certs/ subdirectory
sed -i "s|/home/socktop/.config/socktop/rpi-|${SOCKTOP_HOME}/.config/socktop/certs/rpi-|g" "${SOCKTOP_HOME}/.config/socktop/profiles.json"
if [ "$(id -u)" -eq 0 ]; then
chown socktop:socktop "${SOCKTOP_HOME}/.config/socktop/profiles.json"
fi
echo " ✓ Updated certificate paths"
fi
# Verify final permissions
echo "Verifying permissions..."
ls -la "${SOCKTOP_HOME}/.config/" 2>&1 || echo " ⚠ Could not list config directory"
echo "==================================="
echo "Configuration initialization complete"
echo "==================================="
# Switch to socktop user only if running as root
if [ "$(id -u)" -eq 0 ]; then
echo "Switching to socktop user..."
echo "Switching to socktop user and executing: $@"
exec runuser -u socktop -- "$@"
else
echo "Already running as non-root user ($(whoami)), continuing..."