@ -1,37 +1,111 @@
#!/usr/bin/env bash
#!/usr/bin/env bash
if ! type -f bpkg-realpath & >/dev/null; then
echo "error: bpkg-realpath not found, aborting"
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/realpath/realpath.sh
source " $( which bpkg-realpath) "
fi
if ! type -f bpkg-utils & >/dev/null; then
if ! type -f bpkg-utils & >/dev/null; then
echo "error: bpkg-utils not found, aborting"
echo "error: bpkg-utils not found, aborting"
exit 1
exit 1
else
# shellcheck disable=SC2230
# shellcheck source=lib/utils/utils.sh
source " $( which bpkg-utils) "
fi
fi
# shellcheck source=lib/utils/utils.sh
if ! type -f bpkg-getdeps & >/dev/null; then
source " $( which bpkg-utils) "
echo "error: bpkg-getdeps not found, aborting"
exit 1
# shellcheck source=lib/realpath/realpath.sh
else
bpkg_exec_or_exit bpkg-realpath &&
# shellcheck disable=SC2230
source " $( which bpkg-realpath) "
# shellcheck source=lib/getdeps/getdeps.sh
# shellcheck source=lib/getdeps/getdeps.sh
bpkg_exec_or_exit bpkg-getdeps &&
source " $( which bpkg-getdeps) "
source " $( which bpkg-getdeps) "
fi
bpkg_initrc
bpkg_initrc
let prevent_prune = 0
let prevent_prune = 0
let install_dev = 0
let force_actions = ${ BPKG_FORCE_ACTIONS :- 0 }
let force_actions = ${ BPKG_FORCE_ACTIONS :- 0 }
let needs_global = 0
let needs_global = 0
## output usage
## check parameter consistency
validate_parameters ( ) {
if [ [ ${# BPKG_GIT_REMOTES [@] } -ne ${# BPKG_REMOTES [@] } ] ] ; then
error " $( printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' " ${# BPKG_GIT_REMOTES [@] } " " ${# BPKG_REMOTES [@] } " ) "
return 1
fi
return 0
}
## outut usage
usage ( ) {
usage ( ) {
echo 'usage: bpkg-install [directory]'
echo 'usage: bpkg-install [directory]'
echo ' or: bpkg-install [-h|--help]'
echo ' or: bpkg-install [-h|--help]'
echo ' or: bpkg-install [-d|--dev]'
echo ' or: bpkg-install [-g|--global] [-f|--force] ...<package>'
echo ' or: bpkg-install [-g|--global] [-f|--force] ...<package>'
echo ' or: bpkg-install [-g|--global] [-f|--force] ...<user>/<package>'
echo ' or: bpkg-install [-g|--global] [-f|--force] ...<user>/<package>'
}
}
## format and output message
message ( ) {
if type -f bpkg-term > /dev/null 2>& 1; then
bpkg-term color " $1 "
fi
shift
echo -n " $1 "
shift
if type -f bpkg-term > /dev/null 2>& 1; then
bpkg-term reset
fi
printf ': '
if type -f bpkg-term > /dev/null 2>& 1; then
bpkg-term reset
bpkg-term bright
fi
printf "%s\n" " $@ "
if type -f bpkg-term > /dev/null 2>& 1; then
bpkg-term reset
fi
}
## output error
error ( ) {
message 'red' 'error' " $@ " >& 2
return 0
}
## output warning
warn ( ) {
message 'yellow' 'warn' " $@ " >& 2
return 0
}
## output info
info ( ) {
local title = 'info'
if ( ( " $# " > 1 ) ) ; then
title = " $1 "
shift
fi
message 'cyan' " $title " " $@ "
return 0
}
save_remote_file ( ) {
save_remote_file ( ) {
local auth_param dirname path url
local auth_param dirname path url
@ -118,11 +192,6 @@ bpkg_install () {
force_actions = 1
force_actions = 1
; ;
; ;
-d| --dev)
shift
install_dev = 1
; ;
--no-prune)
--no-prune)
shift
shift
prevent_prune = 1
prevent_prune = 1
@ -133,7 +202,7 @@ bpkg_install () {
pkgs += ( " $opt " )
pkgs += ( " $opt " )
shift
shift
else
else
bpkg_ error " Unknown option \` $opt ' "
error " Unknown option \` $opt ' "
return 1
return 1
fi
fi
; ;
; ;
@ -142,14 +211,9 @@ bpkg_install () {
export BPKG_FORCE_ACTIONS = $force_actions
export BPKG_FORCE_ACTIONS = $force_actions
BPKG_DEPS_EXEC = "bpkg_getdeps"
if ( ( 1 = = install_dev ) ) ; then
BPKG_DEPS_EXEC = " ${ BPKG_DEPS_EXEC } --dev "
fi
## ensure there is a package to install
## ensure there is a package to install
if ( ( ${# pkgs [@] } = = 0 ) ) ; then
if ( ( ${# pkgs [@] } = = 0 ) ) ; then
${ BPKG_DEPS_EXEC }
bpkg_getdeps
return $?
return $?
fi
fi
@ -157,7 +221,7 @@ bpkg_install () {
for pkg in " ${ pkgs [@] } " ; do
for pkg in " ${ pkgs [@] } " ; do
if test -d " $( bpkg_realpath " $pkg " 2>/dev/null) " ; then
if test -d " $( bpkg_realpath " $pkg " 2>/dev/null) " ; then
if ! ( cd " $pkg " && ${ BPKG_DEPS_EXEC } ) ; then
if ! ( cd " $pkg " && bpkg_getdeps ) ; then
return 1
return 1
fi
fi
@ -169,24 +233,19 @@ bpkg_install () {
local i = 0
local i = 0
for remote in " ${ BPKG_REMOTES [@] } " ; do
for remote in " ${ BPKG_REMOTES [@] } " ; do
local git_remote = ${ BPKG_GIT_REMOTES [ $i ] }
local git_remote = ${ BPKG_GIT_REMOTES [ $i ] }
if bpkg_install_from_remote " $pkg " " $remote " " $git_remote " $needs_global $install_dev ; then
if bpkg_install_from_remote " $pkg " " $remote " " $git_remote " $needs_global ; then
did_fail = 0
did_fail = 0
break
break
elif [ [ " $? " = = '2' ] ] ; then
elif [ [ " $? " = = '2' ] ] ; then
bpkg_ error 'fatal error occurred during install'
error 'fatal error occurred during install'
return 1
return 1
fi
fi
i = $(( i+1))
i = $(( i+1))
done
done
done
done
if ( ( ${# pkgs [@] } = = 0) ) ; then
bpkg_error 'no packages supplied'
return 1
fi
if ( ( did_fail = = 1 ) ) ; then
if ( ( did_fail = = 1 ) ) ; then
bpkg_ error 'package not found on any remote'
error 'package not found on any remote'
return 1
return 1
fi
fi
@ -203,7 +262,6 @@ bpkg_install_from_remote () {
local remote = $2
local remote = $2
local git_remote = $3
local git_remote = $3
local needs_global = $4
local needs_global = $4
local install_dev = $5
local url = ''
local url = ''
local uri = ''
local uri = ''
@ -238,7 +296,7 @@ bpkg_install_from_remote () {
name = " ${ pkg_parts [0] } "
name = " ${ pkg_parts [0] } "
version = " ${ pkg_parts [1] } "
version = " ${ pkg_parts [1] } "
else
else
bpkg_ error 'Error parsing package version'
error 'Error parsing package version'
return 1
return 1
fi
fi
@ -258,7 +316,7 @@ bpkg_install_from_remote () {
user = " ${ pkg_parts [0] } "
user = " ${ pkg_parts [0] } "
name = " ${ pkg_parts [1] } "
name = " ${ pkg_parts [1] } "
else
else
bpkg_ error 'Unable to determine package name'
error 'Unable to determine package name'
return 1
return 1
fi
fi
@ -269,7 +327,7 @@ bpkg_install_from_remote () {
## check to see if remote is raw with oauth (GHE)
## check to see if remote is raw with oauth (GHE)
if [ [ " ${ remote : 0 : 10 } " = = "raw-oauth|" ] ] ; then
if [ [ " ${ remote : 0 : 10 } " = = "raw-oauth|" ] ] ; then
bpkg_ info 'Using OAUTH basic with content requests'
info 'Using OAUTH basic with content requests'
OLDIFS = " $IFS "
OLDIFS = " $IFS "
IFS = "'|'"
IFS = "'|'"
local remote_parts = ( " $remote " )
local remote_parts = ( " $remote " )
@ -289,7 +347,7 @@ bpkg_install_from_remote () {
## clean up extra slashes in uri
## clean up extra slashes in uri
uri = ${ uri / \/ \/ // }
uri = ${ uri / \/ \/ // }
bpkg_ info " Install $uri from remote $remote [ $git_remote ] "
info " Install $uri from remote $remote [ $git_remote ] "
## Ensure remote is reachable
## Ensure remote is reachable
## If a remote is totally down, this will be considered a fatal
## If a remote is totally down, this will be considered a fatal
@ -297,7 +355,7 @@ bpkg_install_from_remote () {
## from the broken remote.
## from the broken remote.
{
{
if ! url_exists " $remote " " $auth_param " ; then
if ! url_exists " $remote " " $auth_param " ; then
bpkg_ error " Remote unreachable: $remote "
error " Remote unreachable: $remote "
return 2
return 2
fi
fi
}
}
@ -321,7 +379,7 @@ bpkg_install_from_remote () {
if ( ( 0 = = has_pkg_json ) ) ; then
if ( ( 0 = = has_pkg_json ) ) ; then
## check to see if there's a Makefile. If not, this is not a valid package
## check to see if there's a Makefile. If not, this is not a valid package
if ! url_exists " $url /Makefile? $nonce " " $auth_param " ; then
if ! url_exists " $url /Makefile? $nonce " " $auth_param " ; then
bpkg_ warn " Makefile not found, skipping remote: $url "
warn " Makefile not found, skipping remote: $url "
return 1
return 1
fi
fi
fi
fi
@ -386,14 +444,13 @@ bpkg_install_from_remote () {
if ( ( 1 = = needs_global ) ) ; then
if ( ( 1 = = needs_global ) ) ; then
if ( ( has_pkg_json > 0 ) ) ; then
if ( ( has_pkg_json > 0 ) ) ; then
## install bin if needed
## install bin if needed
build = " $( echo -n " $json " | bpkg-json -b -f= '"install"' ) "
build = " $( echo -n " $json " | bpkg-json -b | grep '\["install"\]' | awk '{$1=""; print $0 }' | tr -d '\"' ) "
build = ${ build # \" }
build = " $( echo -n " $build " | sed -e 's/^ *//' -e 's/ *$//' ) "
build = ${ build % \" }
fi
fi
if [ [ -z " $build " ] ] ; then
if [ [ -z " $build " ] ] ; then
bpkg_ warn 'Missing build script'
warn 'Missing build script'
bpkg_ warn 'Trying "make install"...'
warn 'Trying "make install"...'
build = 'make install'
build = 'make install'
fi
fi
@ -413,7 +470,7 @@ bpkg_install_from_remote () {
( ( ( 0 = = prevent_prune ) ) && rm -rf " $name - $version " )
( ( ( 0 = = prevent_prune ) ) && rm -rf " $name - $version " )
## shallow clone
## shallow clone
bpkg_ info " Cloning $repo_url to $( pwd ) / $name - $version "
info " Cloning $repo_url to $( pwd ) / $name - $version "
( test -d " $name - $version " || git clone " $repo_url " " $name - $version " 2>/dev/null) && (
( test -d " $name - $version " || git clone " $repo_url " " $name - $version " 2>/dev/null) && (
## move into directory
## move into directory
cd " $name - $version " && (
cd " $name - $version " && (
@ -425,7 +482,7 @@ bpkg_install_from_remote () {
)
)
## build
## build
bpkg_ info " Performing install: \` $build ' "
info " Performing install: \` $build ' "
mkdir -p " $PREFIX " /{ bin,lib}
mkdir -p " $PREFIX " /{ bin,lib}
build_output = $( eval " $build " )
build_output = $( eval " $build " )
echo " $build_output "
echo " $build_output "
@ -448,14 +505,8 @@ bpkg_install_from_remote () {
mkdir -p " $BPKG_PACKAGE_DEPS /bin "
mkdir -p " $BPKG_PACKAGE_DEPS /bin "
# install package dependencies
# install package dependencies
bpkg_info " Install dependencies for $name "
info " Install dependencies for $name "
( cd " $BPKG_PACKAGE_DEPS / $name " && bpkg_getdeps)
BPKG_DEPS_EXEC = "bpkg_getdeps"
if ( ( 1 = = install_dev ) ) ; then
BPKG_DEPS_EXEC = " ${ BPKG_DEPS_EXEC } --dev "
fi
( cd " $BPKG_PACKAGE_DEPS / $name " && ${ BPKG_DEPS_EXEC } )
## grab each script and place in deps directory
## grab each script and place in deps directory
for script in " ${ scripts [@] } " ; do
for script in " ${ scripts [@] } " ; do
@ -463,19 +514,19 @@ bpkg_install_from_remote () {
if [ [ " $script " ] ] ; then
if [ [ " $script " ] ] ; then
local scriptname = " $( echo " $script " | xargs basename ) "
local scriptname = " $( echo " $script " | xargs basename ) "
bpkg_ info "fetch" " $url / $script "
info "fetch" " $url / $script "
bpkg_ warn " BPKG_PACKAGE_DEPS is ' $BPKG_PACKAGE_DEPS ' "
warn " BPKG_PACKAGE_DEPS is ' $BPKG_PACKAGE_DEPS ' "
bpkg_ info "write" " $BPKG_PACKAGE_DEPS / $name / $script "
info "write" " $BPKG_PACKAGE_DEPS / $name / $script "
save_remote_file " $url / $script " " $BPKG_PACKAGE_DEPS / $name / $script " " $auth_param "
save_remote_file " $url / $script " " $BPKG_PACKAGE_DEPS / $name / $script " " $auth_param "
scriptname = " ${ scriptname %.* } "
scriptname = " ${ scriptname %.* } "
bpkg_ info " $scriptname to PATH " " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
info " $scriptname to PATH " " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
if ( ( force_actions = = 1 ) ) ; then
if ( ( force_actions = = 1 ) ) ; then
ln -sf " .. /$name / $script " " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
ln -sf " $BPKG_PACKAGE_DEPS /$name / $script " " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
else
else
if test -f " $BPKG_PACKAGE_DEPS /bin/ $scriptname " ; then
if test -f " $BPKG_PACKAGE_DEPS /bin/ $scriptname " ; then
bpkg_ warn " ' $BPKG_PACKAGE_DEPS /bin/ $scriptname ' already exists. Overwrite? (yN) "
warn " ' $BPKG_PACKAGE_DEPS /bin/ $scriptname ' already exists. Overwrite? (yN) "
read -r yn
read -r yn
case $yn in
case $yn in
Yy) rm -f " $BPKG_PACKAGE_DEPS /bin/ $scriptname " ; ;
Yy) rm -f " $BPKG_PACKAGE_DEPS /bin/ $scriptname " ; ;
@ -483,7 +534,7 @@ bpkg_install_from_remote () {
esac
esac
fi
fi
ln -s " .. /$name / $script " " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
ln -s " $BPKG_PACKAGE_DEPS /$name / $script " " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
fi
fi
chmod u+x " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
chmod u+x " $BPKG_PACKAGE_DEPS /bin/ $scriptname "
fi
fi
@ -495,9 +546,9 @@ bpkg_install_from_remote () {
for file in " ${ files [@] } " ; do
for file in " ${ files [@] } " ; do
(
(
if [ [ " $file " ] ] ; then
if [ [ " $file " ] ] ; then
bpkg_ info "fetch" " $url / $file "
info "fetch" " $url / $file "
bpkg_ warn " BPKG_PACKAGE_DEPS is ' $BPKG_PACKAGE_DEPS ' "
warn " BPKG_PACKAGE_DEPS is ' $BPKG_PACKAGE_DEPS ' "
bpkg_ info "write" " $BPKG_PACKAGE_DEPS / $name / $file "
info "write" " $BPKG_PACKAGE_DEPS / $name / $file "
save_remote_file " $url / $file " " $BPKG_PACKAGE_DEPS / $name / $file " " $auth_param "
save_remote_file " $url / $file " " $BPKG_PACKAGE_DEPS / $name / $file " " $auth_param "
fi
fi
)
)
@ -510,7 +561,7 @@ bpkg_install_from_remote () {
## Use as lib or perform install
## Use as lib or perform install
if [ [ ${ BASH_SOURCE [0] } != " $0 " ] ] ; then
if [ [ ${ BASH_SOURCE [0] } != " $0 " ] ] ; then
export -f bpkg_install
export -f bpkg_install
elif bpkg_ validate; then
elif validate_parameters ; then
bpkg_install " $@ "
bpkg_install " $@ "
exit $?
exit $?
else
else