-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.sh
executable file
·104 lines (93 loc) · 2.63 KB
/
install.sh
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
#!/bin/bash
echo "$0: TERM-TOOLS INSTALLER"
echo ""
if [ ! "$BASH_VERSION" ]; then
echo "Error: installer must be run from bash"
exit 1
fi
# allow for remote installation
if [ ! -t 0 ]; then
echo "$0 run from non-terminal -- installing in default ~/term-tools location"
if [[ ! -d ~/term-tools ]]; then
echo "Cloning into term-tools"
sudo apt-get install -y git
git clone https://github.com/seanbell/term-tools ~/term-tools
cd ~/term-tools
bash install.sh
exit
fi
fi
# find term-tools
export TERM_TOOLS_DIR="$(builtin cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
echo "TERM_TOOLS_DIR=$TERM_TOOLS_DIR"
cd $TERM_TOOLS_DIR
# if -f, make sure it is intended
for f in $@; do
if [ "$f" == "-f" ]; then
echo "Note: -f was provided as an argument, which may overwrite any existing configuration"
read -r -p "Are you sure? [y/N] " response
case $response in
[yY][eE][sS]|[yY])
:
;;
*)
exit 1
;;
esac
else
echo "Error: unknown argument: $f"
exit 1
fi
done
# trap errors
function print_err() {
echo "ERROR: install incomplete"
}
trap print_err ERR
set -e
echo "Update submodules..."
git pull origin master
git submodule init
git submodule update --init --recursive
# run through the installers
for f in $(ls -1 installers/*.sh); do
inst="y"
read -r -p "Install config for $(basename $f .sh)? [Y/n] " response
if [ -z "$response" ] || [[ $response =~ ^[Yy]$ ]] ; then
if bash $f $@; then
echo "SUCCESS: $f"
else
echo "ERROR: $f"
exit 1
fi
else
echo "SKIPPING: $f"
fi
done
for f in ~/.zshrc ~/.bashrc; do
if [[ -s $f ]]; then
# Choice of single/double quotes is intentional below to escape some variables but not others
echo "Patching $f..."
if [[ $(grep -c "source \"$TERM_TOOLS_DIR/config/shrc.sh\"" $f) == "0" ]]; then
echo '' >> $f
echo '# TERM-TOOLS' >> $f
echo "# (patched by $TERM_TOOLS_DIR/install.sh on $(date))" >> $f
echo "[[ -s \"$TERM_TOOLS_DIR/config/shrc.sh\" ]] && source \"$TERM_TOOLS_DIR/config/shrc.sh\"" >> $f
fi
if [[ $(grep -c 'source "$TERM_TOOLS_DIR/config/shrc-tmux.sh"' $f) == "0" ]]; then
echo '# Start all new shells inside tmux (if installed). It must be the last command in this file.' >> $f
echo '[[ -s "$TERM_TOOLS_DIR/config/shrc-tmux.sh" ]] && source "$TERM_TOOLS_DIR/config/shrc-tmux.sh"' >> $f
fi
fi
done
set +x
echo ""
echo " == INSTALL COMPLETE =="
echo ""
echo "To overwrite existing config, rerun with -f (this will delete any existing configuration)"
echo ""
echo "To make zsh the default shell, run:"
echo " sudo chsh $USER -s /bin/zsh"
echo "and then restart the terminal (or re-login for Ubuntu)"
echo ""
echo " ======================"