-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·98 lines (82 loc) · 2.44 KB
/
install.sh
File metadata and controls
executable file
·98 lines (82 loc) · 2.44 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
#!/bin/bash
#
# bash-ftw installer
# author: Jonathan Tsai <hello@jontsai.com>
#
KERNEL=`uname -s`
##################################################
echo 'Installing bash-ftw...'
echo ''
##################################################
DIRECTORIES='bin code var tmp .ssh'
echo 'Creating directories...'
for DIR in $DIRECTORIES
do
echo $HOME/$DIR
mkdir -v -p $HOME/$DIR
done
echo ''
##################################################
echo "Installing scripts into $HOME/bin..."
cp -v bin/* $HOME/bin
echo ''
##################################################
echo "Setting up SSH..."
# Observe directory permissions for SSH carefully!
chmod 700 $HOME/.ssh
touch $HOME/.ssh/authorized_keys
chmod 600 $HOME/.ssh/authorized_keys
echo ''
##################################################
echo "Installing dotfiles (.bashrc*)..."
if [ $KERNEL == 'Darwin' ] && [ -f $HOME/.bash_profile ]
then
BASHRC_FILE=$HOME/.bash_profile
elif [ -f $HOME/.bash_aliases ]
then
BASHRC_FILE=$HOME/.bash_aliases
elif [ -f $HOME/.bashrc ]
then
BASHRC_FILE=$HOME/.bashrc
else
BASHRC_FILE=''
fi
if [[ $BASHRC_FILE ]]
then
cp -v dotfiles/.bashrc.ftw $HOME/
cp -v dotfiles/.git-completion.bash $HOME/
INCLUDE_BASHRC_SOURCE="[[ -s \"\$HOME/.bashrc.ftw\" ]] && source \$HOME/.bashrc.ftw"
# Check if line exists anywhere in the file
if grep -qF "$INCLUDE_BASHRC_SOURCE" "$BASHRC_FILE"; then
# Line exists - check if it's at the end
LAST_LINE=$(tail -n 1 "$BASHRC_FILE")
if [ "$LAST_LINE" == "$INCLUDE_BASHRC_SOURCE" ]; then
echo "bash-ftw is already at the end of $BASHRC_FILE"
else
echo "Moving bash-ftw to end of $BASHRC_FILE"
# Remove existing line(s) and re-add at end
grep -vF "$INCLUDE_BASHRC_SOURCE" "$BASHRC_FILE" > "${BASHRC_FILE}.tmp"
mv "${BASHRC_FILE}.tmp" "$BASHRC_FILE"
echo "$INCLUDE_BASHRC_SOURCE" >> "$BASHRC_FILE"
fi
else
echo "Adding bash-ftw include to $BASHRC_FILE"
echo "$INCLUDE_BASHRC_SOURCE" >> "$BASHRC_FILE"
fi
if [ $KERNEL == 'Darwin' ]
then
echo .bash-ftw.mac
cp -v dotfiles/.bashrc.ftw.mac $HOME/
fi
if [ $KERNEL == 'Linux' ]
then
echo .bash-ftw.linux
cp -v dotfiles/.bashrc.ftw.linux $HOME/
fi
else
echo 'Not installing .bashrc.ftw'
fi
echo ''
##################################################
echo 'Finished installing bash-ftw!'
echo ''