-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_lib.sh
50 lines (45 loc) · 1.44 KB
/
install_lib.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
# Common function for installing a file, with checks to see if it exists etc
#dotfiles_install(link_target, link_name)
dotfiles_install(){
local link_name=$2
local link_target=$1
local link_type
if [ -f "$link_target" ]; then
link_type="file"
elif [ -d "$link_target" ]; then
link_type="dir"
else
echo "dotfiles_install(): The link target '$link_target' does not seem to exist"
return 1
fi
local full_link_target=$(readlink -f -n $link_target)
# the place we want to install the link exists. Check if we have already installed it
if [ -h "$link_name" ]; then
if [ "$(readlink -f -n $link_name)" = "$full_link_target" ]; then
# link_name already exists, but it points to link_target, so we are good
return 0
fi
case $(readlink -f -n $link_name) in
${DOTFILES_DIR}* )
# update a symlink from an old install
rm ${link_name}
ln -s "$link_target" "$link_name"
return 0
;;
esac
echo "ERROR: could not install $(readlink -f -n $link_target) to $link_name."
echo -e "\t$link_name already exists"
return 1
elif [ -h "$link_name" ]; then
# link_name exists, and either isnt a symlink, or doesnt point to link_target
echo "ERROR: could not install $(readlink -f -n $link_target) to $link_name."
echo -e "\t$link_name already exists"
return 2
fi
ln -s "$link_target" "$link_name"
if [ $? -ne 0 ]; then
echo "ERROR: could not install $(readlink -f -n $link_target) to $link_name."
return 3
fi
return 0
}