A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 52 lines 1.8 kB view raw
1#!/bin/sh 2set -e 3 4# Default values 5PUID=${PUID:-1000} 6PGID=${PGID:-1000} 7USER_NAME=${USER_NAME:-siyuan} 8GROUP_NAME=${GROUP_NAME:-siyuan} 9WORKSPACE_DIR="/siyuan/workspace" 10 11# Get or create group 12group_name="${GROUP_NAME}" 13if getent group "${PGID}" > /dev/null 2>&1; then 14 group_name=$(getent group "${PGID}" | cut -d: -f1) 15 echo "Using existing group: ${group_name} (${PGID})" 16else 17 echo "Creating group ${group_name} (${PGID})" 18 addgroup --gid "${PGID}" "${group_name}" 19fi 20 21# Get or create user 22user_name="${USER_NAME}" 23if getent passwd "${PUID}" > /dev/null 2>&1; then 24 user_name=$(getent passwd "${PUID}" | cut -d: -f1) 25 echo "Using existing user ${user_name} (PUID: ${PUID}, PGID: ${PGID})" 26else 27 echo "Creating user ${user_name} (PUID: ${PUID}, PGID: ${PGID})" 28 adduser --uid "${PUID}" --ingroup "${group_name}" --disabled-password --gecos "" "${user_name}" 29fi 30 31# Parse command line arguments for --workspace option or SIYUAN_WORKSPACE_PATH env variable 32# Store other arguments in ARGS for later use 33if [[ -n "${SIYUAN_WORKSPACE_PATH}" ]]; then 34 WORKSPACE_DIR="${SIYUAN_WORKSPACE_PATH}" 35fi 36ARGS="" 37while [[ "$#" -gt 0 ]]; do 38 case $1 in 39 --workspace=*) WORKSPACE_DIR="${1#*=}"; shift ;; 40 *) ARGS="$ARGS $1"; shift ;; 41 esac 42done 43 44# Change ownership of relevant directories, including the workspace directory 45echo "Adjusting ownership of /opt/siyuan, /home/siyuan/, and ${WORKSPACE_DIR}" 46chown -R "${PUID}:${PGID}" /opt/siyuan 47chown -R "${PUID}:${PGID}" /home/siyuan/ 48chown -R "${PUID}:${PGID}" "${WORKSPACE_DIR}" 49 50# Switch to the newly created user and start the main process with all arguments 51echo "Starting Siyuan with UID:${PUID} and GID:${PGID} in workspace ${WORKSPACE_DIR}" 52exec su-exec "${PUID}:${PGID}" /opt/siyuan/kernel --workspace="${WORKSPACE_DIR}" ${ARGS}