Skip to content

Commit

Permalink
Merge branch 'master' into feat/support-gradle-root-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
xizhao authored Mar 20, 2018
2 parents 1030bd6 + 91944c9 commit 60818b4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions builders/gradle.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (builder *GradleBuilder) DiscoverModules(dir string) ([]module.Config, erro
// Search for subprojects using Gradle task list instead of grepping for build.gradle
var moduleConfigurations []module.Config
// NOTE: this leaves out the root ("") dependencies task. To include, replace with `(\w+:)?dependencies -`
// TODO: check for root dependencies task if not found otherwise
taskListRe := regexp.MustCompile(`\w+:dependencies -`)
for _, line := range strings.Split(string(taskListOutput), "\n") {
trimmed := strings.TrimSpace(line)
Expand Down
2 changes: 1 addition & 1 deletion cmd/fossa/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func doInit(conf *config.CLIConfig, overwrite bool, includeAll bool) error {
// Filter suspicious modules
var filteredModuleConfigs []module.Config
for _, c := range conf.Modules {
if matched, err := regexp.MatchString("(docs?/|test|example|vendor/|node_modules/|.srclib-cache/|spec/|Godeps/|.git/|bower_components/)", c.Path); err != nil || matched != true {
if matched, err := regexp.MatchString("(docs?/|test|example|vendor/|node_modules/|.srclib-cache/|spec/|Godeps/|.git/|bower_components/|third_party/)", c.Path); err != nil || matched != true {
filteredModuleConfigs = append(filteredModuleConfigs, c)
} else {
initLogger.Warningf("Filtering out suspicious module: %s (%s)", c.Name, c.Path)
Expand Down
1 change: 1 addition & 0 deletions cmd/fossa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

// main.{version,commit,goversion} are set by linker flags in Makefile and goreleaser
// TODO: These may empty if built using `go get`
var version string
var commit string
var goversion string
Expand Down
46 changes: 29 additions & 17 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,61 @@
TMP_DIR="/tmp/install-fossa-cli"

function cleanup {
echo rm -rf $TMP_DIR > /dev/null
rm -rf $TMP_DIR > /dev/null
}
trap cleanup EXIT

function fail {
cleanup
msg=$1
echo "============"
echo "Error: $msg" 1>&2
exit 1
}

# This function will ask for root privileges before executing a command
# The goal is to allow the user to run this script as a normal user and
# to be asked for authorizations as needed
function askRoot {
echo "The following command needs administrator privileges:"
echo
echo -e "\\t$*"
echo
# The -k flag forces sudo to re-ask the user for their authorization
sudo -k "$@"
}

function install {
# Settings
USER="fossas"
REPO="fossa-cli"
BIN="fossa"
# TODO: automatically get latest version from GitHub Releases API
VERSION="0.4.4"
RELEASE="v$VERSION"
MOVE="true"
INSECURE="false"
OUT_DIR="/usr/local/bin"
GH="https://github.com"
GH_API="https://api.github.com"

# `bash` check
[ ! "$BASH_VERSION" ] && fail "Please use bash instead"
[ ! -d $OUT_DIR ] && fail "output directory missing: $OUT_DIR"

# Check for non-POSIX dependencies
GET=""
if which curl > /dev/null; then
if command -v curl > /dev/null; then
GET="curl"
if [[ $INSECURE = "true" ]]; then GET="$GET --insecure"; fi
GET="$GET --fail -# -L"
elif which wget > /dev/null; then
elif command -v wget > /dev/null; then
GET="wget"
if [[ $INSECURE = "true" ]]; then GET="$GET --no-check-certificate"; fi
GET="$GET -qO-"
else
fail "neither wget nor curl are installed"
fi
which tar > /dev/null || fail "tar is not installed"
which gzip > /dev/null || fail "gzip is not installed"
command -v tar > /dev/null || fail "tar is not installed"
command -v gzip > /dev/null || fail "gzip is not installed"

# Detect OS
case `uname -s` in
case $(uname -s) in
Darwin) OS="darwin";;
Linux) OS="linux";;
*) fail "unknown os: $(uname -s)";;
Expand All @@ -81,13 +90,16 @@ function install {
*) fail "No asset for platform ${OS}-${ARCH}";;
esac


# Enter temporary directory
echo "Installing $USER/$REPO $RELEASE..."
mkdir -p $TMP_DIR
cd $TMP_DIR
cd $TMP_DIR || fail "changing directory to $TMP_DIR failed"

# Download and validate release
bash -c "$GET $GH_API/repos/$USER/$REPO/releases/latest" > latest || fail "downloading latest release metadata failed"
RELEASE=$(grep tag_name latest | cut -d'"' -f4)
VERSION=${RELEASE#v} # remove prefix "v"

echo "Installing $USER/$REPO $RELEASE..."
RELEASE_URL="$GH/$USER/$REPO/releases/download/$RELEASE"
bash -c "$GET $RELEASE_URL/${REPO}_${VERSION}_${OS}_${ARCH}.tar.gz" > release.tar.gz || fail "downloading release failed"
bash -c "$GET $RELEASE_URL/${REPO}_${VERSION}_checksums.txt" > checksums.txt || fail "downloading checksums failed"
Expand All @@ -98,10 +110,10 @@ function install {

# Move binary into output directory
chmod +x $BIN || fail "chmod +x failed"
mv $BIN $OUT_DIR/$BIN || fail "mv failed"
echo "Installed at $OUT_DIR/$BIN"

cleanup
# Admin privileges are required to run this command
askRoot mv $BIN $OUT_DIR/$BIN || fail "mv failed"
echo "Installed at $OUT_DIR/$BIN"
}

install

0 comments on commit 60818b4

Please sign in to comment.