-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfiles.sh
More file actions
executable file
·68 lines (55 loc) · 1.58 KB
/
dotfiles.sh
File metadata and controls
executable file
·68 lines (55 loc) · 1.58 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
#!/bin/bash
backUpDir=~/oldDotFiles
scriptPath=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo "";
# Check if folders where specified
if (( $# != 0 ))
then
# User specified specific folders to load dotfiles from
echo "Searching for user defined folders..."
folders=$@
for folder in $folders; do
if [ ! -d "$scriptPath/$folder" ];
then
echo " $folder does not exist. Stopping."
exit 128
else
echo " Found $folder..."
fi
done
echo "All folders found"
else
# User didn't specify folders, so we just get all of them
echo "Using all folders..."
folders=$(find $scriptPath/* -type d -printf "%f\n")
fi
echo ""
if [ ! -e $backUpDir ];
then
echo "Creating backup folder $backUpDir..."
mkdir $backUpDir
else
if [ ! -d "$backUpDir" ];
then
echo "$backUpDir is not a directory."
echo "Either change the value of the \$backUpDir variable in this script, or remove the file $backUpDir"
exit 126
else
echo "Using the existing back up folder $backUpDir"
fi
fi
echo "Creating backups and syslinks"
for folder in $folders; do
echo " $folder:"
for file in $(find $scriptPath/$folder -type f -printf "%f\n"); do
if [ -f ~/.$file ];
then
mv ~/.$file $backUpDir
echo " $file backed up to $backUpDir"
else
echo " $file does not yet exist, no backup needed"
fi
echo " Adding symlink to $file in ~/"
ln -s $scriptPath/$folder/$file ~/.$file
done
done