You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bpkg/README.md

375 lines
13 KiB
Markdown

# bpkg [![Build Status](https://travis-ci.org/bpkg/bpkg.svg?branch=master)](https://travis-ci.org/bpkg/bpkg) [![Backers on Open Collective](https://opencollective.com/bpkg/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/bpkg/sponsors/badge.svg)](#sponsors)
10 years ago
_JavaScript has npm, Ruby has Gems, Python has pip and now Shell has bpkg!_
`bpkg` is a lightweight bash package manager. It takes care of fetching the shell scripts, installing them appropriately, setting the execution permission and more.
10 years ago
You can install shell scripts globally (on `${PREFIX:-/usr/local/bin}`) or use them on a _per-project basis_ (on `${BPKG_DEPS:-./deps/}`), as a lazy-man "copy and paste".
<!-- BEGIN-MARKDOWN-TOC -->
* [Install](#install)
* [0. Dependencies](#0-dependencies)
* [1. Install script](#1-install-script)
* [2. clib](#2-clib)
* [3. Source Code](#3-source-code)
* [Usage](#usage)
* [Installing packages](#installing-packages)
* [Packages With Dependencies](#packages-with-dependencies)
* [Running packages with `bpkg`](#running-packages-with-bpkg)
* [Retrieving package info](#retrieving-package-info)
* [Package details](#package-details)
* [bpkg.json](#bpkgjson)
* [name](#name)
* [version (optional)](#version-optional)
* [description](#description)
* [global](#global)
* [install](#install-1)
* [scripts](#scripts)
* [files (optional)](#files-optional)
* [dependencies (optional)](#dependencies-optional)
* [dependencies-dev (optional)](#dependencies-dev-optional)
* [commands (optional)](#commands-optional)
* [commands-description (optional)](#commands-description-optional)
* [Packaging best practices](#packaging-best-practices)
* [Package exports](#package-exports)
* [Sponsors](#sponsors)
* [Contributors](#contributors)
* [Backers](#backers)
* [License](#license)
<!-- END-MARKDOWN-TOC -->
## Install
You can install `bpkg` from three distinct ways:
### 0. Dependencies
* [curl](http://curl.haxx.se/)
* [coreutils](https://www.gnu.org/software/coreutils/)
### 1. Install script
Our install script is the simplest way. It takes care of everything for you, placing `bpkg` and related scripts on `/usr/local/bin`.
You can install `bpkg` with the [`get.bpkg.sh`](https://get.bpkg.sh) endpoint:
```sh
curl -Lo - get.bpkg.sh | bash
```
Or optionally paste the following on your shell and you're good to go:
10 years ago
```sh
curl -Lo- "https://raw.githubusercontent.com/bpkg/bpkg/master/setup.sh" | bash
10 years ago
```
or by tag/version
```sh
curl -Lo- "https://raw.githubusercontent.com/bpkg/bpkg/1.0.15/setup.sh" | bash
```
### 2. clib
[clib][clib] is a package manager for C projects. If you already have it, installing `bpkg` is a simple matter of:
10 years ago
```sh
clib install bpkg/bpkg
10 years ago
```
### 3. Source Code
To directly install `bpkg` from its source code you have to clone its repository and run the `setup.sh` script:
```sh
git clone https://github.com/bpkg/bpkg.git
cd bpkg
./setup.sh # Will install bpkg in $HOME/.local/bin
sudo ./setup.sh # Will install bpkg in /usr/local/bin.
PREFIX=/my/custom/directory ./setup.sh # Will install bpkg in a custom directory.
```
## Usage
You use `bpkg` by simply sending commands, pretty much like `npm` or `pip`.
### Installing packages
10 years ago
Packages can either be global (on `${PREFIX:-/usr/local/bin}` if installed as root or
`${PREFIX:-$HOME/.local/bin}` otherwize) or local (under `${BPKG_DEPS:-./deps}`).
10 years ago
For example, here's a **global install for the current user** of the [term package][term]:
10 years ago
```sh
bpkg install term -g
term
10 years ago
```
And the same package as a **local install**:
10 years ago
```sh
bpkg install term
./deps/term/term.sh
10 years ago
```
After a local install the `term.sh` script is copied as `term` to the `deps/bin` directory, you can add this directory to the `PATH` with
```sh
export PATH=$PATH:/path_to_bkpg/deps/bin
```
10 years ago
As a bonus, you can specify a **specific version**:
10 years ago
```sh
bpkg install jwerle/suggest.sh@0.0.1 -g
10 years ago
```
**Note:** to do that the packages **must be tagged releases** on the repository.
10 years ago
You can also *install packages without a `bpkg.json` (or `package.json`)*.
As long as there is a `Makefile` in the repository it will try to invoke `make install` as long as the `-g` or `--global` flags are set when invoking `bpkg install`.
For example you could install [git-standup](https://github.com/stephenmathieson/git-standup) with an omitted `bpkg.json` (or `package.json`) because of the `Makefile` and the `install` target found in it.
```sh
bpkg install stephenmathieson/git-standup -g
warn: bpkg.json doesn`t exist
warn: package.json doesn`t exist
warn: Trying `make install'...
info: install: `make install'
cp -f git-standup /usr/local/bin
```
### Packages With Dependencies
You can install a packages dependencies with the `bpkg getdeps` command. These will recursively install in `deps/` sub-folders to resolve all dependencies.
_Note: There is no protection against circular dependencies, so be careful!_
### Running packages with `bpkg`
You can run a package script with `bpkg run` which will install your
package globally and execute it as a command
### Retrieving package info
After installing a package, you can obtain info from it using `bpkg`.
10 years ago
Supposing you're on the root of a package directory, the following commands show that package metadata:
10 years ago
```sh
# Asking for single information
bpkg package name
10 years ago
"bpkg"
bpkg package version
10 years ago
"0.0.5"
# Dumping all the metadata
bpkg package
10 years ago
["name"] "bpkg"
["version"] "0.0.5"
["description"] "Lightweight bash package manager"
["global"] true
["install"] "make install"
```
## Package details
Here we lay down some info on the structure of a package.
## bpkg.json
10 years ago
Every package must have a file called `bpkg.json` (for backward-compatibility
`package.json` can also be used); it specifies package metadata on the [JSON format][json].
Here's an example of a well-formed `bpkg.json`:
```json
{
"name": "term",
"version": "0.0.1",
"description": "Terminal utility functions",
"scripts": [ "term.sh" ],
"install": "make install"
}
```
All fields are mandatory except when noted.
Here's a detailed explanation on all fields:
10 years ago
### name
The `name` attribute is required as it is used to tell `bpkg` where to put it in the `deps/` directory in you project.
10 years ago
```json
"name": "my-script"
```
### version (optional)
10 years ago
The `version` attribute is not required but can be useful. It should correspond to the version that is associated with the installed package.
10 years ago
```json
"version": "0.0.1"
```
### description
A human readable description of what the package offers for functionality.
10 years ago
```json
"description": "This script makes monkeys jump out of your keyboard"
```
### global
Indicates that the package is only intended to be install as a script. This allows the omission of the `-g` or `--global` flag during installation.
10 years ago
```json
"global": "true"
```
### install
Shell script used to invoke in the install script. This is required if the `global` attribute is set to `true` or if the `-g` or `--global` flags are provided.
10 years ago
```json
"install": "make install"
```
### scripts
This is an array of scripts that will be installed into a project.
```json
"scripts": ["script.sh"]
```
### files (optional)
This is an array of non-script files that will be installed into a project.
```json
"files": ["bar.txt", "foo.txt"]
```
### dependencies (optional)
This is a hash of dependencies. The keys are the package names, and the values are the version specifiers. If you want the latest code use `'master'` in the version specifier. Otherwise, use a tagged release identifier. This works the same as `bpkg install`'s package/version specifiers.
```json
"dependencies": {
"term": "0.0.1"
}
```
### dependencies-dev (optional)
This is a hash of dependencies only needed during development. Like the `dependencies` array, the keys are the package names, and the values are the version specifiers; `'master'` or a tagged release can be used as the identifier. These development dependencies are installed by adding the `-d` or `--dev` flags to the `bpkg install` command.
```json
"dependencies-dev": {
"term": "0.0.1"
}
```
### commands (optional)
This is a hash of commands. The keys are the names of the commands and the values are the commands to execute in a shell. The commands can be called from the command line with `bpkg run` followed by the command name.
```json
"commands": {
"say-hello": "echo \"Hello $1\""
}
```
The commands are run with `eval`, which runs the command as if on the command line. Commands can contain environment variables, and supports [shell features] (including *[special parameters]* and *[shell expansions]*). Passed parameters (on the command line after the command name) can be accessed in the command by using `$@` or `$1`.
```bash
$ bpkg run say-hello "Bash Package Manager"
Hello Bash Package Manager
```
### commands-description (optional)
This is a hash of descriptions for configured commands. The keys are the names of the commands and the values are the descriptions for the specified commands. The command descriptions can be listed on the command line by providing the `-l` or `--list` flags after the `bpkg run` command.
```json
"commands-description": {
"say-hello": "Output hello to provided name (ex: bpkg run say-hello John)"
}
```
## Packaging best practices
10 years ago
These are guidelines that we strongly encourage developers to follow.
10 years ago
### Package exports
It's nice to have a bash package that can be used in the terminal and also be invoked as a command line function. To achieve this the exporting of your functionality *should* follow this pattern:
10 years ago
```sh
if [[ ${BASH_SOURCE[0]} != "$0" ]]; then
10 years ago
export -f my_script
else
my_script "${@}"
exit $?
fi
```
This allows a user to `source` your script or invoke as a script.
10 years ago
```sh
# Running as a script
./my_script.sh some args --blah
# Sourcing the script
source my_script.sh
my_script some more args --blah
```
10 years ago
10 years ago
## Sponsors
10 years ago
**bpkg** wouldn't be where it is today without the help of its authors, contributors, and sponsors:
* [@socketsupply](https://github.com/socketsupply) ([socketsupply.co](https://socketsupply.co))
* [@little-core-labs](https://github.com/little-core-labs)
10 years ago
* [@littlstar](https://github.com/littlstar) ([littlstar.com](https://littlstar.com))
* [@spotify](https://github.com/spotify) ([spotify.com](https://spotify.com))
10 years ago
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/bpkg#sponsor)]
<a href="https://opencollective.com/bpkg/sponsor/0/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/1/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/2/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/3/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/4/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/5/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/6/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/7/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/8/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/bpkg/sponsor/9/website" target="_blank"><img src="https://opencollective.com/bpkg/sponsor/9/avatar.svg"></a>
### Contributors
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="graphs/contributors"><img src="https://opencollective.com/bpkg/contributors.svg?width=890&button=false" /></a>
### Backers
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/bpkg#backer)]
<a href="https://opencollective.com/bpkg#backers" target="_blank"><img src="https://opencollective.com/bpkg/backers.svg?width=890"></a>
## License
`bpkg` is released under the **MIT license**.
See file `LICENSE` for a more detailed description of its terms.
[clib]: https://github.com/clibs/clib
[term]: https://github.com/bpkg/term
[json]: http://json.org/example
[shell features]: https://www.gnu.org/software/bash/manual/html_node/Basic-Shell-Features.html
[special parameters]: https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
[shell expansions]: https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html