forked from bertvv/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·49 lines (37 loc) · 1.47 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
#!/bin/bash
#
# Author: Bert Van Vreckem <[email protected]>
#
# Install selected scripts in the user's ~/bin directory by creating symbolic
# links to the actual scripts. The links will have their extension removed.
#
# Thes scripts should be stored in a subdirectory src/. If you want a script to
# be installed, just make it executable, otherwise it will be skipped.
#
# installation destination directory
dst_dir=${HOME}/bin
# directory where this script is located (should contain
# subdirectory src/ containing the actual scripts
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# script directory
src_dir=${script_dir}/src
# scripts to be installed. If you want a script to be installed, make it
# executable
to_install=$(find ${src_dir} -type f \( -executable -and ! -iname ".*" \) -printf '%f\n')
for s in $(echo ${to_install}); do
# determine path to source and destination files
source_file=${src_dir}/${s}
destination_file=${dst_dir}/${s%.*} # remove extension from link
if [[ ! -f "${source_file}" ]]; then
# Source script not found
echo "Skipping nonexistent ${source_file}" >&2
else
# If the destination directory already contains a script
# that is not a link, it should not be overwritten
if [[ -f "${destination_file}" && ! -h "${destination_file}" ]]; then
echo "Skipping ${destination_file}: already exists, is a regular file" >&2
fi
# create the link
ln -vsf ${source_file} ${destination_file}
fi
done