-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·191 lines (169 loc) · 5.47 KB
/
bootstrap.sh
File metadata and controls
executable file
·191 lines (169 loc) · 5.47 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# bootstrap your dotfiles
# TODO: make sure this script can be run multiple times without causing damage
SAVEDIR="$HOME/.dotfiles_orig"
SYMLINK_EXCLUDES="local | *.template | bootstrap.sh | TODO | *.md"
machine="UNKNOWN:$(uname -s)"
case "$machine" in
*:Linux*) machine=Linux ;;
*:Darwin*) machine=Mac ;;
*CYGWIN*) machine=Cygwin ;;
*MINGW*) machine=MinGw ;;
*) ;;
esac
# we are bootstrapping , let's not rely on which(1), it's not always there
find_on_path() {
for path in ${PATH//:/ } ; do
if test -x $path/$1; then
echo $path/$1
return 0
fi
done
return ""
}
get_input() {
prompt="$1"
echo -n "$prompt : " > /dev/tty
read ans
echo "$ans"
}
install_git() {
case $machine in
Linux)
sudo apt-get update -y
sudo apt-get install git
;;
Mac)
brew install git
;;
esac
}
# cache the sudo password credentials for later
sudo -k
sudo -v -p "$(printf "Elevated permissions are needed\n[sudo %%U] password for %%u@%%H: ")"
RM="$(find_on_path rm)"
GIT="$(find_on_path git)"
if [ ! -x "$GIT" ]; then
echo "git is not found."
case $machine in
Linux)
echo "run 'sudo apt-get install git' first"
;;
Mac)
echo 'run: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
echo 'then run: brew install git'
;;
esac
exit 1
fi
echo "This will bootstrap a new system environment, install necessary files and tools"
echo "and create symlinks to your dotfiles in the home directory of this user"
echo
echo "Any existing dotfiles will be saved in $SAVEDIR"
echo
echo -n "Enter Y to continue, or N to exit this script: "
read ans
case "$ans" in [yY]*) ;; *) exit 1 ;; esac
LOCALDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# templates
for infile in $LOCALDIR/*.template; do
[ ! -e "$infile" ] && continue
outfile=$(basename "$infile" ".template")
$RM -f "$outfile"
# TODO: read the username and email from the user
NAME=$(get_input "Enter your fullname (for git commits)" )
EMAIL=$(get_input "Enter your email (for git commits)" )
sed < "$infile" > "$outfile" \
-e 's/\${NAME}/'$NAME'/' \
-e 's/\${EMAIL}/'$EMAIL'/'
done
#make symlinks
[ ! -e "$SAVEDIR" ] && mkdir -p "$SAVEDIR"
for path in $LOCALDIR/*; do
filename=`basename "$path"`
case "$filename" in
*~|*.tmp|local|TODO|*.md|bootstrap.sh)
echo "Skipping excluded file or directory: $filename"
continue
;;
*)
dotfile="$HOME/.$filename"
if [ ! -L "$dotfile" ] ; then
mv "$dotfile" "$SAVEDIR"
ln -snf "$path" "$dotfile"
else
echo "skipping already linked file: $dotfile"
fi
;;
esac
done
## git completion
GITCOMPLETION="$HOME/.git-completion.bash"
GITCOMPLETION_URL="https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash"
if [[ ! -r "$GITCOMPLETION" ]] ; then
wget -q -O "$GITCOMPLETION" "$GITCOMPLETION_URL"
fi
## setup eslint
## setup vim modules
## TODO: verify vim and fix this
#
VIMBUNDLEDIR="$HOME/.vim/bundle"
[ ! -d "$VIMBUNDLEDIR" ] && mkdir "$VIMBUNDLEDIR"
git submodule init
git submodule update
## setup nvim
## TODO: I use nvchad now, so verify this nvim setup and correct any issues
##
if [[ ! -e $HOME/.config/nvim ]]; then
ln -snf $LOCALDIR/nvim $HOME/.config/nvim
fi
## TODO:
## The rest of this bootstrap.sh file is not strictly dotfile setup anymore
## but more akin to configuration of the environment.
## it MIGHT fall under dotfiles, but it might also fall under configuration
## and should maybe be done via ansible modules ?
## maybe have this bootstrap call out to ansible for a final installer/provisioner/updater, etc.
## TODO
## set up yasnippets for emacs
#
GITHUB="https://github.com/brianonn/yasnippet-snippets.git"
YASSNIPPETDIR="$HOME/.emacs.d/snippets"
$RM -fr $YASSNIPPETDIR
git clone $GITHUB $YASSNIPPETDIR
## on linux
if test $machine = Linux; then
if test -x /usr/bin/nemo ]] ; then
## set up local nemo actions
mkdir -p ~/.local/share/nemo/actions 2>/dev/null 1>&2
/bin/cp -pr --remove-destination local/share/nemo/actions/* ~/.local/share/nemo/actions/ 2>/dev/null 1>&2
fi
##
## TODO
## setup my xmonad tiling window manager.
## maybe not needed if it's part of $XDG_CONFIG_HOME that we install from a repo
##
# set up screenshot savedir
SCREENSHOTDIR="$HOME/Pictures/Screenshots"
/usr/bin/mkdir -p "$SCREENSHOTDIR" 2>/dev/null 1>&2
[ -x /usr/bin/gsettings ] && gsettings set org.gnome.gnome-screenshot auto-save-directory "$SCREENSHOTDIR" 2>/dev/null 1>&2
##
## set up FIDO U2F key support
## see also: https://developers.yubico.com/libfido2/
## TODO: is this still necessary in 2025?
##
UDEV_VERSION="$(sudo udevadm --version)"
if test $UDEV_VERSION -lt 188; then
GITHUB_RULES="0aaf34f5309ff8b3bf493bd4628ebdd178a41480/70-old-u2f.rules"
else
GITHUB_RULES="master/70-u2f.rules"
fi
RULEFILE=70-u2f.rules
wget -q -O/tmp/$RULEFILE "https://raw.githubusercontent.com/Yubico/libu2f-host/$GITHUB_RULES"
if test $? -eq 0; then
if test -s /tmp/$RULEFILE && test -d /etc/udev/rules.d/; then
sudo cp /tmp/$RULEFILE /etc/udev/rules.d/$RULEFILE
sudo chmod 644 /etc/udev/rules.d/$RULEFILE
sudo udevadm control --reload-rules
fi
fi
fi