K-Workspace / start.sh
Kimera-KDev's picture
Upload 2 files
caaf5db verified
Raw History Blame Contribute Delete
929 Bytes
#!/usr/bin/env bash
set -euo pipefail
# Read credentials from Hugging Face Secrets.
# Supports either USERNAME/PASSWORD or username/password.
USERNAME="${USERNAME:-${username:-}}"
PASSWORD="${PASSWORD:-${password:-}}"
ROOT_PASSWORD="${ROOT_PASSWORD:-${root_password:-$PASSWORD}}"
if [[ -z "$USERNAME" || -z "$PASSWORD" ]]; then
echo "ERROR: Missing USERNAME or PASSWORD secret."
echo "Set them in your Hugging Face Space -> Settings -> Repository secrets."
exit 1
fi
# Ensure login user exists and can use sudo.
if ! id -u "$USERNAME" >/dev/null 2>&1; then
useradd -m -s /bin/bash "$USERNAME"
fi
usermod -aG sudo "$USERNAME"
echo "${USERNAME}:${PASSWORD}" | chpasswd
echo "root:${ROOT_PASSWORD}" | chpasswd
# Start a web terminal protected with basic auth as the non-root user.
# You can escalate with sudo, or switch to root using: su -
exec ttyd -p 7860 -c "${USERNAME}:${PASSWORD}" sudo -u "$USERNAME" -H bash -l