-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathoncreate.sh
More file actions
49 lines (40 loc) · 1.15 KB
/
oncreate.sh
File metadata and controls
49 lines (40 loc) · 1.15 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
#!/usr/bin/env bash
set -e
FEATURE_DIR="/usr/local/share/jsburckhardt-devcontainer-features/copilot-persistence"
LOG_FILE="$FEATURE_DIR/log.txt"
log() {
echo "$1"
echo "$1" >> "$LOG_FILE"
}
# Fix permissions on the log file so the remote user can write to it
if command -v sudo > /dev/null; then
sudo chown -R "$(id -u):$(id -g)" "$LOG_FILE"
else
chown -R "$(id -u):$(id -g)" "$LOG_FILE"
fi
log "In OnCreate script"
# Skip if oncreate actions already ran
if [ -f "$FEATURE_DIR/markers/oncreate" ]; then
log "Feature 'copilot-persistence' oncreate actions already run, skipping"
exit 0
fi
fix_permissions() {
local dir="${1}"
if [ ! -w "${dir}" ]; then
echo "Fixing permissions of '${dir}'..."
sudo chown -R "$(id -u):$(id -g)" "${dir}"
echo "Done!"
else
echo "Permissions of '${dir}' are OK!"
fi
}
fix_permissions "/dc/copilot"
# Mark oncreate as done
log "Adding marker file to indicate oncreate actions have been run"
mkdir -p "$FEATURE_DIR/markers"
if command -v sudo > /dev/null; then
sudo touch "$FEATURE_DIR/markers/oncreate"
else
touch "$FEATURE_DIR/markers/oncreate"
fi
log "Done"