-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall
executable file
·76 lines (67 loc) · 1.84 KB
/
install
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
#!/bin/bash
source_dir=~/dotfiles # dotfiles directory
backup_dir=~/.dotfiles_old # backup directory for old dotfiles
home_links=$source_dir/home_links # list of things to link from dotfiles to ~
logAndRun() {
local cmd="$*"
echo $cmd
$cmd
if [[ $? != 0 ]]
then
echo "ERROR: command failed"
echo "please rectify and re-run"
exit 1
fi
}
move_if_exists() {
local file=$1
local target_dir=$2
if [[ -e $file ]]
then
logAndRun mv $file $target_dir
fi
}
backup_if_exists() {
local file=$1
if [[ -e $file ]]
then
logAndRun mv $file ${file}.bak
fi
}
logAndRun mkdir -p $backup_dir
logAndRun cd $source_dir
while read file sourceFile
do
if [[ ! -L ~/$file ]] # if not already a link
then
backup_if_exists $backup_dir/$file
move_if_exists mv ~/$file $backup_dir
[[ -z $sourceFile ]] && sourceFile=$file
logAndRun ln -sf $source_dir/$sourceFile ~/$file
else
echo "$file ok"
fi
done < $home_links
# .gitconfig is special, need to edit it with original user/email
if [[ -f ~/.gitconfig ]]
then
git_name=`git config --global --get user.name`
git_email=`git config --global --get user.email`
cp .gitconfig $backup_dir
cp .gitconfig ~
echo "setting .gitconfig name and email"
git config --global user.name $git_name
git config --global user.email $git_email
if [[ -z $git_name || -z $git_email ]]
then
echo "Warning: git user or email looks blank."
echo "Check ~/.gitconfig"
fi
git config --global alias.alias "config --get-regexp ^alias\."
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.lol "log --oneline --decorate --graph"
fi
mkdir -p ~/.aws/cli
backup_if_exists ~/.aws/cli/alias
ln -s $source_dir/aws.alias ~/.aws/cli/alias