-
Notifications
You must be signed in to change notification settings - Fork 0
/
symlink_lib_file.inc.sh
executable file
·53 lines (46 loc) · 1.72 KB
/
symlink_lib_file.inc.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
#!/bin/bash
# This script creates symbolic links to shared library files from writable locations like /usr/local/lib.
# This script is included in all shared library files, which in turn are included by most main programs.
# This script is only executed during library file "installation" process (described in library files).
#================================
# SYMLINK BACK TO LIBRARY FILE FROM user_dir
#================================
# add symlinks to user locations.
function add_symlink(){
local user_dir="$1"
# create a lib10k/ subdirectory
lib_link_dir="${user_dir}/lib10k"
if [[ $user_dir =~ '/usr/local/lib' ]] # root owned directory
then
sudo mkdir -p "$lib_link_dir" >/dev/null 2>&1
else
mkdir -p "$lib_link_dir" >/dev/null 2>&1
fi
# create symlink to library file
lib_link="${lib_link_dir}/${lib_script_basename}"
if [ ! -h "$lib_link" ] # file exists and is a symbolic link (not)
then
echo "Creating symbolic link:"
echo "TARGET : $lib_script_path"
echo "LINK : $lib_link" && echo
if [[ $user_dir =~ '/usr/local/lib' ]] # root owned directory
then
sudo ln -s "$lib_script_path" "$lib_link" >/dev/null 2>&1
else
ln -s "$lib_script_path" "$lib_link" >/dev/null 2>&1
fi
else
echo "The symbolic link [$lib_link] already exists OK" && echo
fi
}
# if runtime basename matches shared-bash-functions.sh || shared-bash-constants.inc.sh
# then we must be creating symbolic links to library files in a local git repository.
# TODO: Put library script filenames into an array
if [[ $lib_script_basename =~ 'shared-bash-functions.inc.sh' ]] || \
[[ $lib_script_basename =~ 'shared-bash-constants.inc.sh' ]]
then
for user_dir in "${HOME}/.local/share" '/usr/local/lib'
do
add_symlink "$user_dir"
done
fi