-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·72 lines (57 loc) · 1.48 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
#!/bin/bash
#
# This script creates symlinks from the home directory to any
# desired dotfiles in the repository
# Variables
###########
# Old dotfiles will be stored in...
olddir=dotfiles_old
# Repository
dir=~/Développement/dotfiles
# This script's name
scriptname=install.sh
# Main program
##############
# Change to the dotfiles directory
echo "Changing to the $dir directory"
cd $dir
echo "...done"
# Create backup dir
echo "Creating $olddir for backup of any existing dotfiles in repository (not versionned)"
mkdir -p $olddir
echo "...done"
# Compute files to be symlinked
if [ $# -gt 0 ]; then
files="$@"
else
# If no arguments, ask the user to copy all files
echo ""
msg="Do you really want to install all dotfiles from the repository? (y/n) "
read -p "$msg" answer
while [[ "$answer" != "y" && "$answer" != "n" ]]; do
read -p "$msg" answer
done
if [[ "$answer" = "n" ]]; then
echo "Ok. Please indicate which file to copy."
exit 0
else
files=$(ls | grep -v $scriptname | grep -v $olddir)
fi
fi
# Move any existing dotfiles in homedir to dotfiles_old directory,
# then create symlinks
for file in $files; do
echo ""
# Only if there is a new configuration
if [ ! -f "$dir/$file" ]; then
echo "The dotfile $file doesn't exist in the repository!"
else
if [ -f "~/.$file" ]; then
echo "Moving '.$file' from ~ to '$dir/$olddir'"
mv ~/.$file $dir/$olddir/$file
fi
echo "Creating symlink to $file in home directory."
ln -s $dir/$file ~/.$file
fi
done
echo ""