|
| 1 | +#!/bin/sh |
| 2 | +set -e |
| 3 | + |
| 4 | +FEATURE_DIR="/usr/local/share/jsburckhardt-devcontainer-features/copilot-persistence" |
| 5 | +LIFECYCLE_SCRIPTS_DIR="$FEATURE_DIR/scripts" |
| 6 | +LOG_FILE="$FEATURE_DIR/log.txt" |
| 7 | + |
| 8 | +mkdir -p "${FEATURE_DIR}" |
| 9 | +echo "" > "$LOG_FILE" |
| 10 | + |
| 11 | +log() { |
| 12 | + echo "$1" |
| 13 | + echo "$1" >> "$LOG_FILE" |
| 14 | +} |
| 15 | + |
| 16 | +log "Activating feature 'copilot-persistence'" |
| 17 | +log "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}" |
| 18 | + |
| 19 | +# Skip if already installed |
| 20 | +if [ -f "$FEATURE_DIR/markers/install" ]; then |
| 21 | + log "Feature 'copilot-persistence' already installed, skipping" |
| 22 | + exit 0 |
| 23 | +fi |
| 24 | + |
| 25 | +# Back up existing .copilot folder if present |
| 26 | +got_old_copilot_folder=false |
| 27 | +if [ -e "$_REMOTE_USER_HOME/.copilot" ]; then |
| 28 | + log "Moving existing .copilot folder to .copilot-old" |
| 29 | + mv "$_REMOTE_USER_HOME/.copilot" "$_REMOTE_USER_HOME/.copilot-old" |
| 30 | + got_old_copilot_folder=true |
| 31 | +else |
| 32 | + log "No existing .copilot folder found at '$_REMOTE_USER_HOME/.copilot'" |
| 33 | +fi |
| 34 | + |
| 35 | +# Create symlink from ~/.copilot to the mounted volume |
| 36 | +ln -s /dc/copilot/ "$_REMOTE_USER_HOME/.copilot" |
| 37 | +chown -R "${_REMOTE_USER}:${_REMOTE_USER}" "$_REMOTE_USER_HOME/.copilot" |
| 38 | + |
| 39 | +# Copy lifecycle scripts |
| 40 | +if [ -f oncreate.sh ]; then |
| 41 | + mkdir -p "${LIFECYCLE_SCRIPTS_DIR}" |
| 42 | + cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" |
| 43 | + chmod +x "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" |
| 44 | +fi |
| 45 | + |
| 46 | +# Mark as installed |
| 47 | +log "Adding marker file to indicate persistence is installed" |
| 48 | +mkdir -p "$FEATURE_DIR/markers" |
| 49 | +touch "$FEATURE_DIR/markers/install" |
0 commit comments