-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·76 lines (64 loc) · 2.83 KB
/
entrypoint.sh
File metadata and controls
executable file
·76 lines (64 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Configuration ---
# Use environment variables passed to the container, with sensible defaults.
GIT_PROVIDER=${GIT_PROVIDER:-"github.com"}
GIT_REPO=${GIT_REPO:-"AnySoftKeyboard/AnySoftKeyboard"}
GIT_BRANCH=${GIT_BRANCH:-"main"}
# The user is defined in the Dockerfile ARG, but we need it here too.
# We'll pass it as an environment variable to the container.
ACTUAL_USER=${ACTUAL_USER:-"menny"}
WORKSPACE_DIR="/opt/workspace"
# Extract the repository name to use as the folder name
REPO_NAME=$(basename "${GIT_REPO}")
CLONE_DIR="${WORKSPACE_DIR}/${REPO_NAME}"
# --- 1. Clone Git Repository ---
echo "Cloning repository '${GIT_REPO}' from branch '${GIT_BRANCH}'..."
# Clone the repository into a specific subdirectory within the workspace
git clone --branch "${GIT_BRANCH}" "https://${GIT_PROVIDER}/${GIT_REPO}" "${CLONE_DIR}"
# The user should be in the clone folder right after login
echo "cd $CLONE_DIR" >> "/home/${ACTUAL_USER}/.zshrc"
# --- 2. Set Permissions ---
# Function to fix ownership and permissions for a directory
fix_dir_permissions() {
local dir_path=$1
echo "Fixing permissions for ${dir_path}..."
chown -R ${ACTUAL_USER}:${ACTUAL_USER} "${dir_path}"
find "${dir_path}" -type d -exec chmod 700 {} +
find "${dir_path}" -type f -exec chmod 600 {} +
}
# Function to fix ownership for a file
fix_file_owner() {
local file_path=$1
echo "Fixing ownership for ${file_path}..."
chown ${ACTUAL_USER}:${ACTUAL_USER} "${file_path}"
}
echo "Setting permissions for user '${ACTUAL_USER}' on '${CLONE_DIR}'..."
# Give the user ownership of the newly cloned repository folder
chown -R ${ACTUAL_USER}:${ACTUAL_USER} "${CLONE_DIR}"
# Fix permissions for mounted directories and files
fix_dir_permissions "/home/${ACTUAL_USER}/.ssh"
fix_dir_permissions "/home/${ACTUAL_USER}/.gnupg"
fix_dir_permissions "/home/${ACTUAL_USER}/.gemini"
fix_dir_permissions "/home/${ACTUAL_USER}/shared_srv"
fix_file_owner "/home/${ACTUAL_USER}/.gitconfig"
# --- 3. Set User Password ---
# Check if the ACTUAL_PASSWORD environment variable is provided
if [ -n "$ACTUAL_PASSWORD" ]; then
echo "Setting password for user '${ACTUAL_USER}'..."
# Use chpasswd to set the password from the environment variable
echo "${ACTUAL_USER}:${ACTUAL_PASSWORD}" | chpasswd
echo "Password has been set."
else
# Warn the user if the password is not set
echo "ERROR: No 'ACTUAL_PASSWORD' environment variable found."
echo "User '${ACTUAL_USER}' will not have a password set, and password-based SSH may fail."
exit 1
fi
# --- 4. Start SSH Server ---
echo "Starting SSH server..."
# Use `exec` to replace the shell process with the sshd process.
# This ensures it runs as the main process (PID 1) in the container.
# The -D flag keeps it in the foreground.
exec /usr/sbin/sshd -D