-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathoncreate.sh
More file actions
103 lines (86 loc) · 3.25 KB
/
oncreate.sh
File metadata and controls
103 lines (86 loc) · 3.25 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
set -e
FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/azure-cli-persistence"
LOG_FILE="$FEATURE_DIR/log.txt"
log() {
echo "$1"
echo "$1" >> "$LOG_FILE"
}
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"
FEATURE_DIR="/usr/local/share/stuartleeks-devcontainer-features/azure-cli-persistence"
LOG_FILE="$FEATURE_DIR/log.txt"
log() {
echo "$1"
echo "$1" >> "$LOG_FILE"
}
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"
fix_permissions() {
local dir
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/azure"
# Fix up the cliextensions folder in case the user had an old .azure folder
# that had extensions installed in it (e.g. using the azure-cli feature and specifying extensions to install)
if [ -d "$HOME/.azure-old" ]; then
got_old_azure_folder=true
else
got_old_azure_folder=false
fi
old_cliextensions_folder="$HOME/.azure-old/cliextensions"
new_cliextensions_folder="$HOME/.azure/cliextensions"
new_cliextensions_folder_parent="$HOME/.azure"
if [ "$got_old_azure_folder" = true ]; then
if [ -d "$old_cliextensions_folder" ]; then
log "cliextensions folder found in old .azure folder"
if [ -d "$new_cliextensions_folder" ]; then
if [ -L "$new_cliextensions_folder" ]; then
symlink_target=$(readlink "$new_cliextensions_folder")
if [ "$symlink_target" = "$old_cliextensions_folder" ]; then
log "cliextensions folder ('$new_cliextensions_folder') already symlinked to '$old_cliextensions_folder' - no action needed"
else
log "cliextensions folder ('$new_cliextensions_folder') is a symlink, but points to a different location ('$symlink_target')"
exit 1
fi
else
log "cliextensions folder ('$new_cliextensions_folder') already exists in but is not a symlink"
exit 1
fi
else
log "cliextensions folder ('$new_cliextensions_folder') does not exist - creating symlink to '$old_cliextensions_folder'"
if command -v sudo > /dev/null; then
sudo ln -s "$old_cliextensions_folder" "$new_cliextensions_folder_parent"
else
ln -s "$old_cliextensions_folder" "$new_cliextensions_folder_parent"
fi
fi
fi
else
# If we haven't got an old .azure folder with a cliextensions folder in it, check if the new cliextensions folder is a symlink to the old one
# And if so, remove the symlink
# This can happen if the user has installed the azure-cli feature and specified extensions to install
# and then later removed the extensions.
if [ -L "$new_cliextensions_folder" ]; then
symlink_target=$(readlink "$new_cliextensions_folder")
if [ "$symlink_target" = "$old_cliextensions_folder" ]; then
log "cliextensions folder ('$new_cliextensions_folder') is a symlink to '$old_cliextensions_folder' - removing symlink"
rm "$new_cliextensions_folder"
fi
fi
fi