-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_symlinks.sh
executable file
·67 lines (58 loc) · 1.23 KB
/
create_symlinks.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
# Things to do:
# ask if symlinks for /home directories should be created
# ask if dots should be copied or symlinked
# check if apt is ok or pacman should be used
# install packages (list tbd)
# install zsh, change default shell
# install oh-my-zsh
#
ask_for_deletion () {
read -p "${1} is a ${2}, delete? [y/n] " -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -d $1 ]; then
rm -r $1
else
rm $1
fi
return 0
else
echo "Linking of ${1} skipped."
echo
return 1
fi
}
check_path () {
if [ -L $1 ]; then
dir_type="symlink"
elif [ -f $1 ]; then
dir_type="file"
elif [ -d $1 ]; then
dir_type="directory"
fi
if [ -n "$dir_type" ]; then
ask_for_deletion $1 $dir_type
local res=$?
return $res
fi
return 0
}
echo "Creating symlinks for shared home."
echo
base_path="/media/shared/common-home"
while [ ! -d "$base_path" ]; do
echo "Folder ${base_path} not found, enter base path."
read base_path
done
for file in "$@"
do
new_path="/home/${USER}/${file}"
if check_path $new_path; then
ln -s "${base_path}/${file}" $new_path
echo "Link for ${file} created."
echo
fi
done
read -p "Symlinks created, press any key to continue." -n 1
echo