Skip to content

Commit

Permalink
Merge pull request #47 from gdgib/G2-415-OSXSupport
Browse files Browse the repository at this point in the history
G2-415 OSX Support
  • Loading branch information
gdgib authored Oct 11, 2019
2 parents 048d41e + 3a4ffeb commit 1f5cdf5
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 37 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ For more commands, please see the command line help by running `forklift --help`
To run [BATS](https://github.com/sstephenson/bats) on `tests.bats` one might run:

```
forklift run com.github sstephenson/bats v0.4.0 bin/bats tests.bats
forklift run com.github bats-core/bats-core v1.1.0 bin/bats tests.bats
```

This will import the [`sstephenson/bats`](https://github.com/sstephenson/bats) pallet from github if it has not already been imported.
This will import the [`bats-core/bats-core`](https://github.com/bats-core/bats-core) pallet from github if it has not already been imported.
Then it will run the `bin/bats` script in that pallet with the aruments `tests.bats`.
Note that version `v0.4.0` is the latest [release](https://github.com/sstephenson/bats/releases) at the time of this writing.
Note that version `v1.1.0` is the latest [release](https://github.com/bats-core/bats-core/releases) at the time of this writing.

## Example 2

Expand Down
31 changes: 31 additions & 0 deletions builtin/common/install.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function install_force () {
set +u
if [ -z ${INSTALL_TEST+x} ]; then
set -u
INSTALL_TEST=0
fi
set -u

if [[ "${INSTALL_TEST}" = "1" ]]; then
echo install ${PACKAGE}
else
${COMMON_DIR}/install ${PACKAGE}
fi
}

function install () {
PACKAGE=${1}

PACKAGE_FILE="${COMMON_DIR}/packages/${PACKAGE}"
if [ -x "${PACKAGE_FILE}" ]; then
COMMAND="$("${PACKAGE_FILE}" --command)"
else
COMMAND="${PACKAGE}"
fi

if (! which ${COMMAND} > /dev/null 2>&1) || ([[ "${INSTALL_NATIVE}" = "1" ]] && [[ $(which ${COMMAND}) = *"/cygdrive/"* ]]); then
PACKAGE="${PACKAGE}" install_force
elif [ -x "${PACKAGE_FILE}" ] && (! "${PACKAGE_FILE}" --test > /dev/null 2>&1); then
PACKAGE="${PACKAGE}" install_force
fi
}
39 changes: 39 additions & 0 deletions builtin/common/packages/git
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -eu -o pipefail

function help () {
echo "$(basename ${0}): Check whether the $(basename ${0}) package is properly installed"
echo
echo "Usage: $(basename ${0})"
echo -e "\tcommands:"
echo -e "\t\t--help: Display this command line help"
echo -e "\t\t--command: Print the command to be used as an argument to 'which'"
echo -e "\t\t--test: Test if the package is properly installed, fail if it needs to be installed"
echo
}

SELF_DIR=$(cd $(dirname ${0}) && pwd -P)
SELF=${SELF_DIR}/$(basename ${0})

ACTUAL_COMMAND="$(basename "${0}")"

if [[ $# -eq 1 ]]; then
COMMAND="${1}"
case ${COMMAND} in
-h|--help|help)
help
exit 0
;;
-c|--command)
echo "${ACTUAL_COMMAND}"
exit 0
;;
-t|--test)
"${ACTUAL_COMMAND}" --version
exit 0
;;
esac
fi

help
exit 1
39 changes: 39 additions & 0 deletions builtin/common/packages/maven
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -eu -o pipefail

function help () {
echo "$(basename ${0}): Check whether the $(basename ${0}) package is properly installed"
echo
echo "Usage: $(basename ${0})"
echo -e "\tcommands:"
echo -e "\t\t--help: Display this command line help"
echo -e "\t\t--command: Print the command to be used as an argument to 'which'"
echo -e "\t\t--test: Test if the package is properly installed, fail if it needs to be installed"
echo
}

SELF_DIR=$(cd $(dirname ${0}) && pwd -P)
SELF=${SELF_DIR}/$(basename ${0})

ACTUAL_COMMAND="mvn"

if [[ $# -eq 1 ]]; then
COMMAND="${1}"
case ${COMMAND} in
-h|--help|help)
help
exit 0
;;
-c|--command)
echo "${ACTUAL_COMMAND}"
exit 0
;;
-t|--test)
"${ACTUAL_COMMAND}" --version
exit 0
;;
esac
fi

help
exit 1
1 change: 1 addition & 0 deletions builtin/common/source.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ COMMON_DIR="${SRC_SELF_DIR}"
. ${SRC_SELF_DIR}/config.bash
. ${SRC_SELF_DIR}/consoleformat.bash
. ${SRC_SELF_DIR}/util.bash
. ${SRC_SELF_DIR}/install.bash
34 changes: 34 additions & 0 deletions builtin/common/test/install.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load ../install

@test "install_already" {
INSTALL_TEST=1 INSTALL_NATIVE=0 run install which
[ "$output" = "" ]
}

@test "install_now" {
INSTALL_TEST=1 INSTALL_NATIVE=0 run install foobar
[ "$output" = "install foobar" ]
INSTALL_TEST=1 INSTALL_NATIVE=1 run install foobar
[ "$output" = "install foobar" ]
}

@test "install_native" {
INSTALL_TEST=1 INSTALL_NATIVE=1 run install powershell
[ "$output" = "install powershell" ]
}

@test "install_scripted" {
INSTALL_TEST=1 INSTALL_NATIVE=1 run install git
[ "$output" = "" ]
}

@test "git_command" {
run ${BATS_TEST_DIRNAME}/../packages/git --command
[ "$status" -eq 0 ]
[ "$output" = "git" ]
}

@test "git_test" {
run ${BATS_TEST_DIRNAME}/../packages/git --test
[ "$status" -eq 0 ]
}
12 changes: 1 addition & 11 deletions builtin/jack/github/jack
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ function flscript () {
[[ ${CHDIR} -eq 0 ]] || popd > /dev/null 2>&1
}

function install () {
COMMAND=${1}
PACKAGE=${2}
if ! which ${COMMAND} > /dev/null 2>&1; then
${COMMON_DIR}/install ${PACKAGE}
elif [[ $(which ${COMMAND}) = *"/cygdrive/"* ]]; then
${COMMON_DIR}/install ${PACKAGE}
fi
}

args_min 1
COMMAND="${1}"

Expand Down Expand Up @@ -90,7 +80,7 @@ function verify () {
function import () {
if [ ! -d ${CACHE_DIR} ]; then
verify
install git git
INSTALL_NATIVE=1 install git

echo -e "${CFMT_INFO}Checking protocols for ${WAREHOUSE}${CFMT_NORMAL}" >&2
GHHOST=$(warehouse2host)
Expand Down
6 changes: 3 additions & 3 deletions builtin/jack/github/test/jack.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PALLETTEST_WAREHOUSE="${FL_WAREHOUSE}"
PALLETTEST_VERSION="pallet-test"

function jack () {
run ${BATS_TEST_DIRNAME}/../jack ${@}
run ${BATS_TEST_DIRNAME}/../jack ${@} 2> /dev/null
}

@test "no arguments" {
Expand All @@ -24,7 +24,7 @@ function jack () {
@test "path" {
jack path com.github ${BATS_WAREHOUSE} ${BATS_VERSION}
[ "$status" -eq 0 ]
[ "$(basename $output)" = "${BATS_VERSION}" ]
[ "$(basename "${lines[-1]}")" = "${BATS_VERSION}" ]
}

@test "update" {
Expand All @@ -35,7 +35,7 @@ function jack () {
@test "scripts" {
run echo $(${BATS_TEST_DIRNAME}/../jack path com.github ${PALLETTEST_WAREHOUSE} ${PALLETTEST_VERSION} 2>/dev/null)
[ "$status" -eq 0 ]
[ "$(basename $output)" = "${PALLETTEST_VERSION}" ]
[ "$(basename "${lines[-1]}")" = "${PALLETTEST_VERSION}" ]

run ~/.forklift/bin/forklift-test
[ "$status" -eq 0 ]
Expand Down
23 changes: 3 additions & 20 deletions builtin/jack/maven/jack
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ function flscript () {
fi
}

function install_any () {
COMMAND=${1}
PACKAGE=${2}
if ! which ${COMMAND} > /dev/null 2>&1; then
${COMMON_DIR}/install ${PACKAGE}
fi
}
function install_native () {
COMMAND=${1}
PACKAGE=${2}
if ! which ${COMMAND} > /dev/null 2>&1; then
${COMMON_DIR}/install ${PACKAGE}
elif [[ $(which ${COMMAND}) = *"/cygdrive/"* ]]; then
${COMMON_DIR}/install ${PACKAGE}
fi
}

args_min 1
COMMAND="${1}"

Expand Down Expand Up @@ -91,7 +74,7 @@ function verify () {
}
function import () {
verify
install_any mvn maven
INSTALL_NATIVE=0 install maven
path
if [ ! -e ${MVNPATH} ]; then
mvn dependency:get "-DgroupId=${MVNGROUP}" "-DartifactId=${MVNARTIFACT}" "-Dversion=${MVNVERSION}" >&2
Expand Down Expand Up @@ -119,12 +102,12 @@ case ${COMMAND} in
;;
run)
import
install_native unzip unzip
INSTALL_NATIVE=1 install unzip
MVNGROUP="${MVNGROUP}" MVNARTIFACT="${MVNARTIFACT}" MVNVERSION="${MVNVERSION}" CMDPRINT=0 MVNPATH=${MVNPATH} ${SELF_DIR}/mvn-run ${@}
;;
command)
import
install_native unzip unzip
INSTALL_NATIVE=1 install unzip
MVNGROUP="${MVNGROUP}" MVNARTIFACT="${MVNARTIFACT}" MVNVERSION="${MVNVERSION}" CMDPRINT=1 MVNPATH=${MVNPATH} ${SELF_DIR}/mvn-run ${@}
;;
update)
Expand Down
3 changes: 3 additions & 0 deletions builtin/package/OSX/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OSX

[`install`](install) automates the installation of OSX packages, generally using [homebrew](https://brew.sh/).
30 changes: 30 additions & 0 deletions builtin/package/OSX/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -eu -o pipefail

function help () {
echo "$(basename ${0}): Install packages on OSX"
echo
echo "Usage: $(basename ${0}) <package>*"
echo
}

SELF_DIR=$(cd $(dirname ${0}) && pwd -P)
SELF=${SELF_DIR}/$(basename ${0})

. ${SELF_DIR}/../../common/source.bash

# Note that there can be more than one package to install...
args_min 1

if ! which brew &> /dev/null; then
echo -e "${CFMT_INFO}Installing homebrew for the first time${CFMT_NORMAL}" >&2
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi

echo -e "${CFMT_INFO}Updating brew${CFMT_NORMAL}" >&2
brew update

echo -e "${CFMT_INFO}Installing ${@} using brew${CFMT_NORMAL}" >&2
brew install ${@}

echo -e "${CFMT_SUCCESS}Installed ${@}${CFMT_NORMAL}" >&2

0 comments on commit 1f5cdf5

Please sign in to comment.