2
0
mirror of https://github.com/bpkg/bpkg synced 2024-11-09 19:10:24 +00:00
bpkg/README.md

241 lines
5.9 KiB
Markdown
Raw Normal View History

# bpkg
2014-05-22 19:52:28 +00:00
_JavaScript has npm, Ruby has Gems, Python has pip and now Shell has bpkg!_
2014-05-25 06:31:04 +00:00
`bpkg` is a lightweight bash package manager. It takes care of fetching the shell scripts, installing them appropriately, setting the execution permission and more.
2014-05-25 20:00:52 +00:00
You can install shell scripts globally (on `/usr/local/bin`) or use them on a _per-project basis_ (on `./deps/`), as a lazy-man "copy and paste".
## Install
You can install `bpkg` from three distinct ways:
2015-02-21 20:14:53 +00:00
### 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`.
Paste the following on your shell and you're good to go:
2014-05-25 20:00:52 +00:00
```sh
$ curl -Lo- http://get.bpkg.io| bash
2014-05-25 20:00:52 +00:00
```
### 2. clib
[clib][clib] is a package manager for C projects. If you already have it, installing `bpkg` is a simple matter of:
2014-05-25 20:00:52 +00:00
```sh
$ clib install bpkg/bpkg
```
### 3. Source Code
To directly install `bpkg` from it's source code you have to clone it's repository and install with `make`:
2014-05-25 06:31:04 +00:00
```sh
2014-05-25 20:00:52 +00:00
$ git clone https://github.com/bpkg/bpkg.git
$ cd bpkg
2014-05-25 06:31:04 +00:00
$ make install
```
2015-02-21 14:35:36 +00:00
Or in a directory with user write permission, like `$HOME/opt/bin`
```sh
$ git clone https://github.com/bpkg/bpkg.git
$ cd bpkg
$ PREFIX=$HOME/opt make install
```
## Usage
You use `bpkg` by simply sending commands, pretty much like `npm` or `pip`.
### Installing packages
2014-05-25 20:00:52 +00:00
Packages can either be global (on `/usr/local/bin`) or local (under `./deps`).
2014-05-25 20:00:52 +00:00
For example, here's a **global install** of the [term package][term]:
2014-05-25 20:00:52 +00:00
```sh
$ bpkg install term -g
$ term
2014-05-25 20:00:52 +00:00
```
And the same package as a **local install**:
2014-05-25 20:00:52 +00:00
```sh
$ bpkg install term
$ ./deps/term/term.sh
2014-05-25 20:00:52 +00:00
```
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
```
2014-05-25 20:00:52 +00:00
As a bonus, you can specify a **specific version**:
2014-05-25 20:00:52 +00:00
```sh
$ bpkg install jwerle/suggest.sh@0.0.1 -g
```
**Note:** to do that the packages **must be tagged releases** on the repository.
2014-05-25 20:00:52 +00:00
You can also *installing packages without a `package.json`*.
As long as there is a `Makefile` in the repository it will try to invoke `make install` so long as the `-g` or `--global` flags are set when invoking `bpkg install`.
2014-05-27 23:31:43 +00:00
For example you could install [git-standup](https://github.com/stephenmathieson/git-standup) with an omitted `package.json` because of the `Makefile` and the `install` target found in it.
2014-05-27 23:31:43 +00:00
```sh
$ bpkg install stephenmathieson/git-standup -g
info: Using latest (master)
warn: Package doesn't exist
warn: Mssing build script
warn: Trying `make install'...
info: install: `make install'
cp -f git-standup /usr/local/bin
```
### Retrieving package info
After installing a package, you can obtain info from it using `bpkg`.
2014-05-25 20:00:52 +00:00
Supposing you're on the root of a package directory, the following commands show that package metadata:
2014-05-25 20:00:52 +00:00
```sh
# Asking for single information
2014-05-25 20:00:52 +00:00
$ bpkg package name
"bpkg"
$ bpkg package version
"0.0.5"
# Dumping all the metadata
2014-05-25 20:00:52 +00:00
$ bpkg package
["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.
2014-05-25 20:00:52 +00:00
## package.json
Every package must have a file called `package.json`; it specifies package metadata on the [JSON format][json].
Here's an example of a well-formed `package.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:
2014-05-25 20:00:52 +00:00
### name
The `name` attribute is required as it is used to tell `bpkg` where to put it in the `deps/` directory in you project.
2014-05-25 20:00:52 +00:00
```json
"name": "my-script"
```
### version (optional)
2014-05-25 20:00:52 +00:00
The `version` attribute is not required but can be useful. It should correspond to the version that is associated with the installed package.
2014-05-25 20:00:52 +00:00
```json
"version": "0.0.1"
```
### description
A human readable description of what the package offers for functionality.
2014-05-25 20:00:52 +00:00
```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 ommition of the `-g` or `--global` flag during installation.
2014-05-25 20:00:52 +00:00
```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.
2014-05-25 20:00:52 +00:00
```json
"install": "make install"
```
### scripts
This is an array of scripts that will be installed into a project.
```json
"scripts": ["script.sh"]
```
## Packaging best practices
2014-05-25 20:00:52 +00:00
These are guidelines that we strongly encourage developers to follow.
2014-05-25 20:00:52 +00:00
### 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:
2014-05-25 20:00:52 +00:00
```sh
if [[ ${BASH_SOURCE[0]} != $0 ]]; then
export -f my_script
else
my_script "${@}"
exit $?
fi
```
This allows a user to `source` your script or invoke as a script.
2014-05-25 06:31:04 +00:00
2014-05-25 20:00:52 +00:00
```sh
# Running as a script
2014-05-25 20:00:52 +00:00
$ ./my_script.sh some args --blah
# Sourcing the script
2014-05-25 20:00:52 +00:00
$ source my_script.sh
$ my_script some more args --blah
2014-05-25 06:31:04 +00:00
```
2014-05-25 20:00:52 +00:00
2014-11-29 11:29:07 +00:00
## Sponsors
2014-11-29 14:43:53 +00:00
**bpkg** wouldn't be where it is today without the help of its authors, contributors, and sponsors:
2014-11-29 14:44:38 +00:00
* [@littlstar](https://github.com/littlstar) ([littlstar.com](https://littlstar.com))
* [@spotify](https://github.com/spotify) ([spotify.com](https://spotify.com))
2014-11-29 11:29:07 +00:00
## License
`bpkg` is released under the **MIT license**.
See file `LICENSE` for a more detailed description of it's terms.
[clib]: https://github.com/clibs/clib
[term]: https://github.com/bpkg/term
[json]: http://json.org/example