-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.bash
More file actions
executable file
·79 lines (66 loc) · 2.12 KB
/
install.bash
File metadata and controls
executable file
·79 lines (66 loc) · 2.12 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
#!/bin/bash
READLINK=$(which greadlink 2>/dev/null || which readlink)
CURRENT_SCRIPT=$BASH_SOURCE
if [[ -n $CURRENT_SCRIPT && -x "$READLINK" && $machine != 'Unknown' ]]; then
if [[ $machine == 'Linux' ]]; then
SCRIPT_PATH=$($READLINK -f "$CURRENT_SCRIPT")
elif [[ $machine == 'Mac' ]]; then
SCRIPT_PATH=$($READLINK "$CURRENT_SCRIPT")
fi
DOTFILES_DIR=$($READLINK -m $(dirname "$(dirname "$SCRIPT_PATH")"))
elif [ -d "$HOME/.dotfiles" ]; then
DOTFILES_DIR="$HOME/.dotfiles"
elif [ -d "$HOME/dotfiles" ]; then
DOTFILES_DIR="$HOME/dotfiles"
else
echo "Unable to find dotfiles, exiting."
return
fi
# link install files to ~
base_dir="install"
echo "Linking dotfiles from $base_dir to ~"
for file in $(ls -A $base_dir); do
# check if file already exists and its not a symlink
if [ -f ~/$file -a ! -h ~/$file ]; then
echo "Moving ~/$file to ~/$file.bak"
mv -v ~/$file{,.bak}
fi
echo "Creating symlink to $base_dir/$file in home directory."
ln -svf $DOTFILES_DIR/$base_dir/$file ~/$file
done
# link config directories to ~/.config
base_dir="config"
echo
echo "Linking config files from $base_dir to ~/.$base_dir"
for file in $(ls -A $base_dir); do
if [ -d ~/.$base_dir/$file -a ! -h ~/.$base_dir/$file ]; then
echo "Moving ~/.$base_dir/$file to ~/.$base_dir/$file.bak"
mv -v ~/.$base_dir/$file{,.bak}
fi
echo "Creating symlink to $base_dir/$file/ in ~/.$base_dir"
mkdir -p ~/.$base_dir
# -s: symbolic
# -v: verbose
# -f: force (delete if LINK_NAME already exists)
# -n: don't dereference LINK_NAME if it's a symlink to a directory
# -n is necessary to avoid recursively linking to config/git/git/git/...
ln -svfn $DOTFILES_DIR/$base_dir/$file ~/.$base_dir/$file
done
# source new bashrc
source ~/.bashrc
# run scripts in setup
base_dir="setup"
echo
echo "Running all executable scripts in $base_dir"
for file in $(ls -A $base_dir); do
echo
if [ -x $base_dir/$file ]
then
echo "Running ./$base_dir/$file"
./$base_dir/$file
else
echo "$base_dir/$file is not executable"
fi
done
unset base_dir
unset file