77 lines
2.7 KiB
Bash
77 lines
2.7 KiB
Bash
#!/bin/bash
|
||
set -e
|
||
|
||
# Init script to copy configuration files to the correct locations
|
||
# This handles the discrepancy between where K8s mounts configs
|
||
# and where the socktop package expects them (HOME directory)
|
||
|
||
echo "==================================="
|
||
echo "Initializing socktop webterm config"
|
||
echo "==================================="
|
||
|
||
# Determine the actual HOME directory for the socktop user
|
||
SOCKTOP_HOME=$(eval echo ~socktop)
|
||
echo "Socktop HOME: ${SOCKTOP_HOME}"
|
||
|
||
# Create necessary directories in the actual HOME
|
||
mkdir -p "${SOCKTOP_HOME}/.config/socktop/certs"
|
||
mkdir -p "${SOCKTOP_HOME}/.config/alacritty"
|
||
|
||
# Copy files from mounted locations to actual HOME if they exist
|
||
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"
|
||
echo " ✓ Copied profiles.json"
|
||
else
|
||
echo " ⚠ profiles.json not found at mount point"
|
||
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"
|
||
echo " ✓ Copied alacritty.toml"
|
||
else
|
||
echo " ⚠ alacritty.toml not found at mount point"
|
||
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"
|
||
echo " ✓ Copied catppuccin-frappe.toml"
|
||
else
|
||
echo " ⚠ catppuccin-frappe.toml not found at mount point"
|
||
fi
|
||
|
||
# Copy certificates if they exist
|
||
if [ -d "/home/socktop/.config/socktop/certs" ]; then
|
||
for cert in /home/socktop/.config/socktop/certs/*.pem; do
|
||
if [ -f "$cert" ]; then
|
||
cp "$cert" "${SOCKTOP_HOME}/.config/socktop/certs/"
|
||
echo " ✓ Copied $(basename "$cert")"
|
||
fi
|
||
done
|
||
else
|
||
echo " ℹ No certificates directory found (optional)"
|
||
fi
|
||
|
||
# Set proper ownership
|
||
chown -R socktop:socktop "${SOCKTOP_HOME}/.config"
|
||
|
||
# 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"
|
||
echo " ✓ Updated certificate paths"
|
||
fi
|
||
|
||
echo "==================================="
|
||
echo "Configuration initialization complete"
|
||
echo "==================================="
|
||
echo "Switching to socktop user..."
|
||
|
||
# Switch to socktop user and execute the main command
|
||
exec runuser -u socktop -- "$@"
|