-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·192 lines (169 loc) · 5.16 KB
/
deploy.sh
File metadata and controls
executable file
·192 lines (169 loc) · 5.16 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
192
#! /bin/sh
set -eu
cd `dirname $0`
backupdir=backup/`date +'%Y%m%d%H%M%S'`
# Portable "echo -n"
echo_n() {
echo $ECHO_N "$@"$ECHO_C
}
ECHO_C=
ECHO_N=
case `echo -n x` in
-n*)
case `echo 'x\c'` in
*c*)
;;
*)
ECHO_C='\c'
;;
esac
;;
*)
ECHO_N='-n'
;;
esac
# Wraps "wget $1" and optionally "chmod $2 ...".
download() {
echo "downloading `basename "$1"...`"
if type curl >/dev/null 2>&1; then
curl -O -L "$1"
elif type wget >/dev/null 2>&1; then
wget -O `basename "$1"` "$1"
else
echo "error: curl or wget required" >&2
return 1
fi
if [ $# -ge 2 ]; then
chmod "$2" "$(basename "$1")"
fi
}
# Check the OS.
osname=`uname -s`
if [ `expr substr "$osname" 1 5` = Linux ]; then
if uname -v | grep -q 'Microsoft'; then
osname=linux_on_windows # WSL1
elif uname -r | grep -q 'microsoft'; then
osname=linux_on_windows # WSL2
else
osname=linux
fi
elif [ `expr substr "$osname" 1 6` = CYGWIN ]; then
osname=cygwin
elif [ "$osname" = Darwin ]; then
osname=osx
else
osname=unknown_os
fi
# Lists dot files.
list_dotfiles() {
for file in .*; do
case $file in
.|..|.git|.gitignore|.gitmodules|*.swp|.nfs*)
continue
;;
.config)
(
cd $file
for subfile in *; do
case $subfile in
.|..|.git|.gitignore|.gitmodules|*.swp|.nfs*)
continue
;;
esac
echo $file/$subfile
done
)
continue
;;
esac
echo $file
done
}
# Check submodules.
if [ -d .git ] && [ -f .gitmodules ]; then
if type git >/dev/null 2>&1; then
git submodule update --init
else
echo "info: initializing/updating submodules requires git"
fi
fi
# Confirmation.
cat << END
This script will (over)write dot files:
`list_dotfiles`
bin/
END
echo_n 'Okay? (y/n) : '
read answer
if [ "x$answer" != "xy" ] && [ "x$answer" != "xY" ]; then
echo 'Exit. No writing.'
exit
fi
# Copy dot files.
backup=false
for file in `list_dotfiles`; do
if [ -e "$HOME/$file" ] || [ -h "$HOME/$file" ]; then
# readlink is not in POSIX, but expected to work both on Linux and OS X.
if [ -h "$HOME/$file" ] && [ `readlink "$HOME/$file"` = `pwd`/"$file" ]; then
echo "skip: $file exists"
continue
fi
mkdir -p "$backupdir"
echo "info: backup $file"
mv "$HOME/$file" "$backupdir"
backup=:
fi
echo "info: link $file"
case "$file" in
.config/*)
mkdir -p "$HOME/.config"
;;
esac
ln -s `pwd`/"$file" "$HOME/$file"
done
# Download utilities.
mkdir -p "$HOME/bin"
(
cd "$HOME/bin"
download https://gist.githubusercontent.com/hSATAC/1095100/raw/256color.pl +x
download https://gist.githubusercontent.com/tueda/3e1b2bec8545c48737c7/raw/formprof.py +x
download https://gist.githubusercontent.com/tueda/6718638/raw/path-manip.bash
download https://gist.githubusercontent.com/tueda/6744aadd5b423c838b44/raw/git-wc +x
download https://gist.githubusercontent.com/tueda/7777291/raw/tarb +x
download https://gist.githubusercontent.com/tueda/8146d9a44b5b1ec18fee/raw/ndiff +x
download https://gist.githubusercontent.com/tueda/bed3f1f5f5ba437b3d1ca4777822faaf/raw/git-phantom +x
download https://gist.githubusercontent.com/tueda/caeb67bd8d5e3b0697f8fd6e8b8a79ae/raw/disk-blame +x
download https://gist.githubusercontent.com/tueda/ce103cd8f5288c1bd1b4ce37e56ef84c/raw/git-latest +x
download https://gist.githubusercontent.com/tueda/d411b7ddc4167c5bb209040b637d5e2d/raw/git-graph +x
download https://gist.githubusercontent.com/tueda/f4b13084345cb6576688066d92198a2c/raw/git-recommit +x
download https://raw.githubusercontent.com/git/git/3dbfe2b8ae94cbdae5f3d32581aedaa5510fdc87/contrib/diff-highlight/diff-highlight +x
download https://raw.githubusercontent.com/tueda/formset/master/formset.py +x
download https://raw.githubusercontent.com/tueda/git-onedrive/main/git-onedrive +x
if [ $osname = linux ]; then
download https://gist.githubusercontent.com/tueda/9529c8d3c06252386c3e9c4ca521f391/raw/open-linux +x
mv open-linux open
fi
if [ $osname = linux_on_windows ]; then
download https://gist.githubusercontent.com/tueda/eed84b738613761f1146de95ca0817d7/raw/open-wsl +x
mv open-wsl open
download https://gist.githubusercontent.com/tueda/dda525296a4a35f857d698af971cd704/raw/dup-wsl +x
mv dup-wsl dup
download https://gist.githubusercontent.com/tueda/16d646cb3650b9b65c87e75462096024/raw/unzone +x
fi
if [ $osname = cygwin ]; then
download https://gist.githubusercontent.com/tueda/fc8c3eba9606479308d88b6e38c9aeca/raw/open-cygwin +x
mv open-cygwin open
download https://gist.githubusercontent.com/tueda/2be1caa5c8051c2d0ab06cec394d5ed1/raw/dup-cygwin +x
mv dup-cygwin dup
fi
# download https://gist.githubusercontent.com/tueda/9253579/raw/copyd.sh
# download https://gist.githubusercontent.com/tueda/139acbc4d354633d42c5c2f022d650ae/raw/git-lsearch
# chmod +x git-lsearch
# download http://particle.uni-wuppertal.de/harlander/software/sortref/sortref
# chmod +x sortref
)
echo "info: Succeeded."
if $backup; then
echo "info: backup files are in `pwd`/$backupdir"
fi
# vim: ft=sh et ts=8 sts=2 sw=2