Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ The installer uses one of two target prefixes:
/usr/local/bin
/usr/local/lib
/usr/local/libexec
/usr/local/share/man

# Locally (your user only)
$HOME/.local/bin
$HOME/.local/lib
$HOME/.local/libexec
$HOME/.local/share/man
```

Make sure the matching `bin` path is on your `PATH`.
If you install local man pages, make sure `$HOME/.local/share/man` is on your
`MANPATH`.

Global install needs root/sudo.

Expand Down Expand Up @@ -107,6 +111,7 @@ project/
<tool>.bash
internal/
libexec/ # subcommand executables
man/ # optional man pages, for example man/man1/<tool>.1
```

To help create the project structure and other script templates checkout [bashlib-create](https://github.com/JMinyard1335/bashlib-create)
Expand Down Expand Up @@ -142,4 +147,3 @@ The tests are fail-first and stop at the first failure.

If you want to contribute, check [CONTRIBUTING.md](CONTRIBUTING.md) for setup, guidelines, and checklist.


6 changes: 5 additions & 1 deletion docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Finally, install it with itself:

Use the `--global` flag if you want to install it globally on the system (this requires root).

Projects can include optional man pages in a `man/` directory. Local installs copy
those pages into `$HOME/.local/share/man`; global installs copy them into
`/usr/local/share/man`. If local man pages do not appear in `man <tool>`, add the
local man directory to `MANPATH`.

All commands:

```bash
Expand Down Expand Up @@ -149,4 +154,3 @@ fi
While you could just call something like `installer install $var` in your script, it is faster to source.
Sourcing the project will give you access to the following API in your code.
see [here](API.md) for the full API.

34 changes: 31 additions & 3 deletions lib/internal/bashlib_install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ bashlib_install_from_source() {
_bashlib_move_to_bin "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1
_bashlib_move_to_lib "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1
_bashlib_move_to_libexec "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1
_bashlib_move_to_man "$source_dir" "$install_dir" "$tool_name" "$debug" || status=1

return "$status"
}
Expand Down Expand Up @@ -273,7 +274,7 @@ _bashlib_move_to_bin() {
mkdir -p -- "$bin_path" || return 1

if [[ -f "$tool_script_path" ]]; then
install -m 755 -t "$bin_path" -- "$tool_script_path" || return 1
install -m 755 -- "$tool_script_path" "${bin_path}/${tool_name}" || return 1
return 0
fi

Expand Down Expand Up @@ -356,8 +357,35 @@ _bashlib_move_to_libexec() {
}

_bashlib_move_to_man() {
echo -e "\e[1;33m[Warn]:\e[0m Not implemented man pages will not be installed with the project."
echo " please see the projects github page for more info and updates."
local tool_path="" install_path="" tool_name="" debug=""
local dest=""

if [[ "$#" -lt 3 || "$#" -gt 4 ]]; then
echo "_bashlib_move_to_man: Invalid argument count." >&2
return 1
fi

tool_path="$1"
install_path="$2"
tool_name="$3"
debug="${4:-0}"

_bashlib_check_install_path "$install_path" || return 1

if [[ ! -d "$tool_path" ]]; then
echo "_bashlib_move_to_man: Unable to find tool source dir: $tool_path" >&2
return 1
fi

if [[ ! -d "${tool_path}/man" ]]; then
[[ "$debug" -ge 2 ]] && echo "[debug]: No man/ directory for ${tool_name}"
return 0
fi

dest="${install_path}/share/man"
mkdir -p -- "$dest" || return 1

cp -r -- "${tool_path}/man/." "$dest" || return 1
return 0
}
## END HELPER FUNCTIONS ------------------------------------------------------------------
28 changes: 27 additions & 1 deletion test/test_lib_install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ setup_test_env() {

mkdir -p "$SRC_ROOT/lib"
mkdir -p "$SRC_ROOT/libexec"
mkdir -p "$SRC_ROOT/man/man1"

cat > "$SRC_ROOT/tool.toml" <<EOF
[project]
Expand All @@ -39,6 +40,12 @@ EOF
cat > "$SRC_ROOT/libexec/mytool-subcmd" <<'EOF'
#!/usr/bin/env bash
echo "hello from libexec"
EOF

cat > "$SRC_ROOT/man/man1/mytool.1" <<'EOF'
.TH MYTOOL 1
.SH NAME
mytool \- test tool
EOF

chmod +x "$SRC_ROOT/mytool"
Expand All @@ -53,6 +60,7 @@ cleanup_test_env() {
rm -f "$HOME/.local/bin/mytool"
rm -rf "$HOME/.local/lib/mytool"
rm -rf "$HOME/.local/libexec/mytool"
rm -f "$HOME/.local/share/man/man1/mytool.1"
}

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -112,6 +120,23 @@ test_move_to_libexec() {
echo -e "\e[1;32m[TEST]:\e[0m move_to_libexec passed"
}

test_move_to_man() {
local status=""

echo "Testing move to man..."
cleanup_test_env
setup_test_env

_bashlib_move_to_man "$SRC_ROOT" "$HOME/.local" "mytool" 0 > /dev/null 2>&1
status="$?"

assert_true "$status" "move_to_man should succeed, got $status"
assert_installed_file "$HOME/.local/share/man/man1/mytool.1" "man page should be copied"

cleanup_test_env
echo -e "\e[1;32m[TEST]:\e[0m move_to_man passed"
}

test_move_to_bin() {
local status=""

Expand Down Expand Up @@ -148,6 +173,7 @@ test_install_from_source() {
assert_installed_file "$HOME/.local/lib/mytool/tool.toml" "installed tool metadata missing"
assert_installed_dir "$HOME/.local/libexec/mytool" "installed libexec dir missing"
assert_installed_file "$HOME/.local/libexec/mytool/mytool-subcmd" "installed libexec file missing"
assert_installed_file "$HOME/.local/share/man/man1/mytool.1" "installed man page missing"

cleanup_test_env
echo -e "\e[1;32m[TEST]:\e[0m install_from_source passed"
Expand Down Expand Up @@ -192,6 +218,7 @@ test_lib_install_main() {

test_move_to_lib
test_move_to_libexec
test_move_to_man
test_move_to_bin
test_install_bad_install_path
test_install_from_source
Expand All @@ -203,4 +230,3 @@ test_lib_install_main() {
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
test_lib_install_main "$@"
fi