-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linked-install.sh
executable file
·105 lines (76 loc) · 2.2 KB
/
linked-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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
set -E -o functrace
## Optional, but recommended to find true directory this script resides in
__SOURCE__="${BASH_SOURCE[0]}"
while [[ -h "${__SOURCE__}" ]]; do
__SOURCE__="$(find "${__SOURCE__}" -type l -ls | sed -n 's@^.* -> \(.*\)@\1@p')"
done
__DIR__="$(cd -P "$(dirname "${__SOURCE__}")" && pwd)"
__DIR_NAME__="${__DIR__##*/}"
__NAME__="${__SOURCE__##*/}"
__PATH__="${__DIR__}/${__NAME__}"
__AUTHOR__='S0AndS0'
__DESCRIPTION__='Symbolically links Awk script(s) to PATH accessible location'
__license__(){
_year="$(date +'%Y')"
cat <<EOF
${__DESCRIPTION__}
Copyright (C) ${_year:-2020} ${__AUTHOR__:-"S0AndS0"}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
EOF
}
__usage__() {
local _message="${1}"
cat <<EOF
${__DESCRIPTION__}
--help -h
Prints this message and exists
--license -l
Prints license and exits
--verbose -v
Prints messages about skipped actions
EOF
(("${#_message}")) && {
printf >&2 '\n## Error: %s\n' "${_message}"
}
}
[[ -d "${HOME}/bin" ]] || {
printf >&2 'No ~/bin directory detected for user -> %s\n' "${USER}"
exit 1
}
(("${#@}")) && {
case "${@}" in
'-h'|'--help'|'help')
__usage__
exit 0
;;
'-l'|'--license'|'license')
__license__
exit 0
;;
'-v'|'--verbose'|'verbose')
_verbose=1
;;
*)
__usage__ "Unrecognized argument(s): ${@}"
exit 1
;;
esac
}
_script_source="${__DIR__}/calc.awk"
_script_destination="${HOME}/bin/calc.awk"
[[ -L "${_script_destination}" ]] || {
_link_options='s'
((_verbose)) && {
_link_options+='v'
}
ln -"${_link_options}" "${_script_source}" "${_script_destination}"
}