-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_globally.sh
executable file
·58 lines (41 loc) · 1.26 KB
/
install_globally.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
#!/bin/bash
# -*- coding: utf-8, tab-width: 2 -*-
function install_globally () {
export LANG{,UAGE}=en_US.UTF-8 # make error messages search engine-friendly
local REPO_DIR="$(readlink -m -- "$BASH_SOURCE"/..)"
cd -- "$REPO_DIR" || return $?
if [ "$1" == --skip-mv ]; then
shift
else
echo "Taking ownership:"
chown --recursive root:root . || return $?
local DN="$(basename -- "$REPO_DIR")"
local ULL="/usr/local/lib"
local ULD="$ULL/$DN"
echo -n "Move repo directory to $ULL: "
if [ "$REPO_DIR" -ef "$ULD" ]; then
echo 'skip: no action required.'
else
mv --target-directory="$ULL" -- "$REPO_DIR" || return $?
echo 'done.'
fi
echo
cd -- "$ULD" || return $?
fi
echo "Installing global CLI commands:"
local LINK= DEST=
while IFS= read -rs DEST; do
case "$DEST" in
[a-z]*' <- '[a-z]*.sh ) LINK="${DEST%% <- *}"; DEST="${DEST#* <- }";;
* ) continue;;
esac
echo -n ' '
LINK="/usr/local/bin/$LINK"
[ ! -L "$LINK" ] || rm -- "$LINK"
ln --verbose --symbolic --relative --no-target-directory \
-- "$DEST" "$LINK" || return $?
done <binlinks.cfg
echo
echo "Ok! Seems like all is well and $DN should be ready for use."
}
install_globally "$@"; exit $?