forked from dagon666/napi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·122 lines (97 loc) · 2.12 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash
# force indendation settings
# vim: ts=4 shiftwidth=4 expandtab
BIN_dir='/usr/bin'
SHARED_dir='/usr/share'
declare -ar bin_files=( 'subotage.sh' 'napi.sh' )
declare -ar shared_files=( 'napi_common.sh' )
#
# replace the common path in given file
#
replace_path() {
local file="$1"
local path="$2"
local token='NAPI_COMMON_PATH'
local replacement="${token}=\"$path\""
# that's because busybox sed doesn't support suffixes
cp "$file" "${file}.orig"
sed -i "s|${token}=|${replacement}|" "$file"
}
#
# check if given directory exists and is writable
#
is_writable() {
local rv=255
local path="$1"
[ -d "$path" ] && [ -w "$path" ] && rv=0
return $rv
}
#
# verify destination dir
#
check_dirs() {
declare -a dirs=( "$BIN_dir" "$SHARED_dir" )
local d=''
for d in "${dirs[@]}"; do
if ! is_writable "$d"; then
echo "katalog [$d] niedostepny do zapisu - okresl inny"
usage
exit -1
fi
done
}
#
# print help
#
usage() {
echo
echo "install.sh [<opcje>]"
echo "opcje:"
echo
echo -e "\t --bindir - kat. w ktorym zostana zainst. pliki wykonywalne (dom. $BIN_dir)"
echo -e "\t --shareddir - kat. w ktorym zostana zainst. biblioteki (dom. $SHARED_dir)"
echo
}
# print help if when requested explicitly
[ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ] &&
usage &&
exit -1
while [ $# -gt 0 ]; do
case "$1" in
"-h" | "--help" )
usage
exit -1
;;
"--bindir" )
shift
[ -z "$1" ] &&
echo "BLAD: Podaj katalog do ktorego zainstalowac pliki wykonywalne" &&
exit -1
BIN_dir="$1"
;;
"--shareddir" )
shift
[ -z "$1" ] &&
echo "BLAD: Podaj katalog do ktorego zainstalowac biblioteki" &&
exit -1
SHARED_dir="$1"
;;
esac
shift
done
echo "BIN_dir : [$BIN_dir]"
echo "SHARED_dir : [$SHARED_dir]"
# check dirs
check_dirs
# install shared first
mkdir -p "$SHARED_dir/napi"
for f in "${shared_files[@]}"; do
cp -v "$f" "$SHARED_dir/napi"
done
# install executables now
for f in "${bin_files[@]}"; do
replace_path "$f" "$SHARED_dir/napi"
cp -v "$f" "$BIN_dir"
# restore original files if we've got backups
[ -e "${f}.orig" ] && mv "${f}.orig" "$f"
done