Skip to content

Commit e43af12

Browse files
committed
Implement installer logic
1 parent baa6d2d commit e43af12

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

bin/install.sh

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ set -e
66
# halt when referencing any unbound variable
77
set -u
88

9+
10+
out() { printf %s\\n "$*" ; }
11+
err() { >&2 printf %s\\n "$*" ; }
12+
die() { >&2 printf %s\\n "$*" ; exit 1 ; }
13+
914
display_help () {
1015
cat <<EOM
1116
Usage: install.sh [OPTIONS]
@@ -18,6 +23,28 @@ Options:
1823
EOM
1924
}
2025

26+
install () {
27+
if [[ ! "$(force_install?)" ]] && [[ -e "$(dst_file)" ]]; then
28+
err "file already exists: ""$(dst_file)"
29+
fi
30+
31+
local src_file="$(dirname "${0}")"/num
32+
33+
if ! cp "${src_file}" "$(dst_file)"; then
34+
err "Unable to copy '${src_file}' to '$(dst_file)'"
35+
fi
36+
}
37+
38+
dst_file () {
39+
local dst_dir="${NUM_INSTALL_DIR:-/usr/local/bin}"
40+
mkdir -p "${dst_dir}"
41+
out "${NUM_INSTALL_DIR:-/usr/local/bin}"/num
42+
}
43+
44+
force_install? () {
45+
echo "${NUM_FORCE_INSTALL:-""}"
46+
}
47+
2148
parse_args () {
2249
if [[ $@ ]]; then
2350
case "${1}" in
@@ -35,8 +62,7 @@ parse_args () {
3562
exit 0
3663
;;
3764
*)
38-
echo "invalid option: "${1} >&2
39-
exit 1
65+
die "invalid option: ""${1}"
4066
;;
4167
esac
4268

@@ -47,4 +73,5 @@ parse_args () {
4773
# parse command line options
4874
parse_args $@
4975

50-
# TODO: implement installer
76+
# install num
77+
install

0 commit comments

Comments
 (0)