forked from aziz/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·67 lines (56 loc) · 1.85 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
#!/bin/bash
echo " _ _ __ _ _ "
echo " | | | | / _(_) | "
echo " __| | ___ | |_| |_ _| | ___ ___ "
echo " / _\` |/ _ \| __| _| | |/ _ \/ __| "
echo " | (_| | (_) | |_| | | | | __/\__ \ "
echo "(_)__,_|\___/ \__|_| |_|_|\___||___/ "
echo "______________________________________________"
echo
echo "Installing dotfiles into user's home directory"
echo
backup_dir=".backup_old_dot_files"
for name in *; do
target="$HOME/.$name"
if [[ $name != 'install.sh' && $name != 'README.md' && $name != 'gitconfig' && $name != 'TODO.md' ]]; then
if [ -e $target ]; then
if [ ! -L $target ]; then
echo "backing up .$name in $HOME/$backup_dir/ directory"
if [ ! -d "$HOME/$backup_dir" ]; then
mkdir -p "$HOME/$backup_dir"
fi
cp "$target" "$HOME/$backup_dir/.$name"
rm -rf "$target"
else
rm -rf "$target"
fi
fi
echo "Creating .$name"
ln -s "$PWD/$name" "$target"
fi
done
# Handling gitconfig
function generate_gitconfig() {
read -p "Your Name: " name
read -p "Your Email: " email
read -p "Github Username: " gh_username
cat gitconfig | sed 's/${name}/'"$name"'/' | sed 's/${email}/'"$email"'/' | sed 's/${gh_username}/'"$gh_username"'/' > "$HOME/.gitconfig"
}
function backup_gitconfig() {
if [ ! -d "$HOME/$backup_dir" ]; then
mkdir -p "$HOME/$backup_dir"
fi
cp "$HOME/.gitconfig" "$HOME/$backup_dir/.gitconfig";
}
echo "Creating .gitconfig"
if [ -e "$HOME/.gitconfig" ]; then
read -p "overwirte .gitconfig? [y=Yes; n=No; b=Backup then Overwrite]" yn
case $yn in
[Yy]* ) rm -rf "$HOME/.gitconfig";generate_gitconfig;;
[Nn]* ) echo ".gitconfig ignored";;
[Bb]* ) backup_gitconfig; rm -rf "$HOME/.gitconfig";generate_gitconfig;;
* ) echo ".gitconfig ignored";;
esac
else
generate_gitconfig
fi