-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpersonalize
More file actions
executable file
·138 lines (106 loc) · 4.97 KB
/
personalize
File metadata and controls
executable file
·138 lines (106 loc) · 4.97 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
set -eu
shopt -s nullglob
###############################################################################
# #
# This script will run every time your environment is built. #
# A dotfiles repo may be help in managing your tooling and personalization. #
# #
# More info: https://enterprise.coder.com/docs/dotfiles #
# #
# /!\ This file will be automatically recreated if it is deleted! /!\ #
# #
###############################################################################
##### BEGIN: Dotfiles clone behavior.
function configure_dotfiles () {
# `DOTFILES_REPO` will be automatically provided during your environment's build.
if [[ ! -v DOTFILES_REPO ]]; then
printf "This Coder account has not configured Dotfiles or a personalize script.
\nAll files and applications outside of your home directory will be lost if the environment is rebuilt or turned off due to inactivity.
\nWe recommend configuring a Dotfiles repo or personalize script to ensure your preferences are applied every time your environment turns on.
\nCoder Enterprise Documentation on Dotfiles: https://enterprise.coder.com/docs/dotfiles
\n on personalize: https://enterprise.coder.com/docs/the-~personalize-script\n"
return 0
fi
echo "Dotfiles repo configured at $DOTFILES_REPO"
if [[ ! -x "$(command -v git)" ]]; then
echo "Git not found, skipping dotfiles configuration..."
return 0
fi
DOTFILES_CLONE_PATH=$HOME/dotfiles
DOTFILES_INSTALL_SCRIPT_PATH=$DOTFILES_CLONE_PATH/install.sh
LAST_DOTFILES_CLONE_URI_PATH=$HOME/.last_dotfiles_clone_uri
# Cloning of the dotfiles repo occurs in a non-interactive script,
# thus unverified hosts must be permitted without user confirmation.
# Temporarily disables remote host key validation to avoid permanently saving an unverified key.
NO_SSH_VALIDATION="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
if [[ -f $LAST_DOTFILES_CLONE_URI_PATH ]]; then
LAST_URI=$(< "$LAST_DOTFILES_CLONE_URI_PATH")
if [[ ("$DOTFILES_REPO" != "$LAST_URI") && -d $DOTFILES_CLONE_PATH ]]; then
DATE_SUFFIX=$(date +"%s")
BACKUP_DOTFILES_CLONE_PATH="${DOTFILES_CLONE_PATH}_backup_${DATE_SUFFIX}"
echo "Dotfiles repo was has changed from $LAST_URI"
echo "Moving $DOTFILES_CLONE_PATH to $BACKUP_DOTFILES_CLONE_PATH"
mv "$DOTFILES_CLONE_PATH" "$BACKUP_DOTFILES_CLONE_PATH"
fi
fi
if [[ ! -d $DOTFILES_CLONE_PATH ]]; then
echo "Cloning repo $DOTFILES_REPO into $DOTFILES_CLONE_PATH"
GIT_SSH_COMMAND=$NO_SSH_VALIDATION git clone "$DOTFILES_REPO" "$DOTFILES_CLONE_PATH"
echo "$DOTFILES_REPO" > "$LAST_DOTFILES_CLONE_URI_PATH"
fi
cd "$DOTFILES_CLONE_PATH"
GIT_SSH_COMMAND=$NO_SSH_VALIDATION git pull --ff-only
echo
if [[ -x "$DOTFILES_INSTALL_SCRIPT_PATH" ]]; then
echo "Executing installation script found in $DOTFILES_INSTALL_SCRIPT_PATH"
"$DOTFILES_INSTALL_SCRIPT_PATH"
else
echo "Installation script $DOTFILES_CLONE_PATH not found or not executable"
echo "Symlinking all files and directories starting with '.' into $HOME"
for dotfile in "$DOTFILES_CLONE_PATH/".*; do
# Skip `..` and '.'
[[ $dotfile =~ \.{1,2}$ ]] && continue
# Skip Git related
[[ $dotfile =~ \.git$ ]] && continue
[[ $dotfile =~ \.gitignore$ ]] && continue
[[ $dotfile =~ \.gitattributes$ ]] && continue
echo "Symlinking $dotfile"
ln -sf "$dotfile" "$HOME"
done
fi
cd "$HOME"
}
configure_dotfiles
##### END: Dotfiles clone behavior.
###############################################################################
# #
# Add shell commands below if this environment has a unique personalization. #
# #
###############################################################################
echo "build project / install dependencies for repo"
REPO_1_PATH=$HOME/coder-react
NPM_INSTALL_COMMAND="npm install"
NPM_START_COMMAND="npm start"
YARN_INSTALL_COMMAND="yarn"
YARN_START_COMMAND="yarn start"
if [ -d $REPO_1_PATH ]; then
echo "Directory for coder-react Node.js/React repo exists."
cd $REPO_1_PATH
echo "do build / install dependencies with NPM"
$NPM_INSTALL_COMMAND
#echo "start React app"
#$NPM_START_COMMAND
fi
echo "install fish shell"
FISH_BINARY=/usr/bin/fish
FISH_PATH=/usr/bin
if [ ! -f $FISH_BINARY ] ; then
sudo apt-get update
sudo apt-get install -y fish
echo "installing fish in $FISH_PATH"
else
echo "fish already installed"
fi
#echo "changing shell"
#chsh -s /usr/bin/fish $USER