Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ vet:
check_license:
./scripts/check_license.sh

check_shell:
find . -type f -name "*.sh" -exec shellcheck {} +

sanity: vet fix lint fmt check_license

cover:
Expand Down Expand Up @@ -243,4 +246,4 @@ dump: $(addprefix gen/,$(addsuffix /genesis.dump, $(NETWORKS)))
install: build
scripts/dev_install.sh -p $(GOPATH1)/bin

.PHONY: default fmt vet lint check_license sanity cover prof deps build test fulltest shorttest clean cleango deploy node_exporter install %gen gen NONGO_BIN
.PHONY: default fmt vet lint check_license check_shell sanity cover prof deps build test fulltest shorttest clean cleango deploy node_exporter install %gen gen NONGO_BIN
2 changes: 1 addition & 1 deletion docker/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:16.04
ENV GOLANG_VERSION 1.12

RUN apt update && apt install -y git libboost-all-dev wget sqlite3 autoconf build-essential
RUN apt-get update && apt-get install -y git libboost-all-dev wget sqlite3 autoconf build-essential shellcheck
WORKDIR /root
RUN wget --quiet https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz && tar -xvf go${GOLANG_VERSION}.linux-amd64.tar.gz && mv go /usr/local
ENV GOROOT=/usr/local/go \
Expand Down
2 changes: 1 addition & 1 deletion docker/build/Dockerfile-deploy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM ubuntu:18.04
ENV GOLANG_VERSION 1.12

RUN apt update && apt install -y git libboost-all-dev wget sqlite3 autoconf jq bsdmainutils
RUN apt-get update && apt-get install -y git libboost-all-dev wget sqlite3 autoconf jq bsdmainutils shellcheck
WORKDIR /root
RUN wget --quiet https://dl.google.com/go/go${GOLANG_VERSION}.linux-amd64.tar.gz && tar -xvf go${GOLANG_VERSION}.linux-amd64.tar.gz && mv go /usr/local
ENV GOROOT=/usr/local/go \
Expand Down
2 changes: 1 addition & 1 deletion scripts/centos-build.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM centos:7
WORKDIR /root
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
RUN yum install -y autoconf awscli git gnupg2 nfs-utils python36 sqlite3 boost-devel expect jq libtool gcc-c++ libstdc++-devel libstdc++-static rpmdevtools createrepo rpm-sign bzip2
RUN yum install -y autoconf awscli git gnupg2 nfs-utils python36 sqlite3 boost-devel expect jq libtool gcc-c++ libstdc++-devel libstdc++-static rpmdevtools createrepo rpm-sign bzip2 shellcheck

ENTRYPOINT ["/bin/bash"]
104 changes: 41 additions & 63 deletions scripts/check_deps.sh
Original file line number Diff line number Diff line change
@@ -1,87 +1,65 @@
#!/usr/bin/env bash

# checkout_deps.sh - Quickly(!) checks the enlistment for any missing dependencies and attempts to resolve them.
# check_deps.sh - Quickly(!) checks the enlistment for any missing dependencies and attempts to resolve them.
# Reports if any dependencies are still missing after attempts to resolve.
#
# Syntax: checkout_deps.sh
# Syntax: check_deps.sh
#
# Outputs: status messages
#
# ExitCode: 0 = All dependencies resolved / present
#
# Usage: Use before building to ensure dependencies are present (should be nop except after dependencies change)
#
# Examples: scripts/checkout_deps.sh
# Examples: scripts/check_deps.sh

export GOPATH=$(go env GOPATH)
GOPATH1=$(echo $GOPATH | cut -d: -f1)
GREEN_FG=$(tput setaf 2)
RED_FG=$(tput setaf 1)
TEAL_FG=$(tput setaf 6)
YELLOW_FG=$(tput setaf 3)
END_FG_COLOR=$(tput sgr0)

ANY_MISSING=0
# golint doesn't work with 'dep ensure' so we manually install it
GOLINT_MISSING=0
STRINGER_MISSING=0
SWAGGER_MISSING=0
GOPATH=$(go env GOPATH)
export GOPATH
GO_BIN="$(echo "$GOPATH" | cut -d: -f1)/bin"
MISSING=0

function check_deps() {
ANY_MISSING=0
GOLINT_MISSING=0
missing_dep() {
echo "$YELLOW_FG[WARNING]$END_FG_COLOR Mising dependency \`$TEAL_FG${1}$END_FG_COLOR\`."
MISSING=1
}

if [ ! -f "${GOPATH1}/bin/golint" ]; then
GOLINT_MISSING=1
ANY_MISSING=1
echo "... golint missing"
fi
GO_DEPS=(
"$GO_BIN/golint"
"$GO_BIN/stringer"
"$GO_BIN/swagger"
)

if [ ! -f "${GOPATH1}/bin/stringer" ]; then
STRINGER_MISSING=1
ANY_MISSING=1
echo "... stringer missing"
fi
check_deps() {
for path in ${GO_DEPS[*]}
do
if [ ! -f "$path" ]
then
# Parameter expansion is faster than invoking another process.
# https://www.linuxjournal.com/content/bash-parameter-expansion
missing_dep "${path##*/}"
fi
done

if [ ! -f "${GOPATH1}/bin/swagger" ]; then
SWAGGER_MISSING=1
ANY_MISSING=1
echo "... swagger missing"
# Don't print `shellcheck`s location.
if ! which shellcheck > /dev/null
then
missing_dep shellcheck
fi

return ${ANY_MISSING}
}

check_deps
if [ $? -eq 0 ]; then
echo Required dependencies already installed.
exit 0
fi

if [ ${GOLINT_MISSING} -ne 0 ]; then
read -p "Install golint (using go get) (y/N): " OK
if [ "$OK" = "y" ]; then
echo "Installing golint..."
GO111MODULE=off go get -u golang.org/x/lint/golint
fi
fi

if [ ${STRINGER_MISSING} -ne 0 ]; then
read -p "Install stringer (using go get) (y/N): " OK
if [ "$OK" = "y" ]; then
echo "Installing stringer..."
GO111MODULE=off go get -u golang.org/x/tools/cmd/stringer
fi
fi

if [ ${SWAGGER_MISSING} -ne 0 ]; then
read -p "Install swagger (using go get) (y/N): " OK
if [ "$OK" = "y" ]; then
echo "Installing swagger..."
GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger
fi
fi

check_deps
if [ $? -eq 0 ]; then
echo Required dependencies have been installed
exit 0
if [ $MISSING -eq 0 ]
then
echo "$GREEN_FG[$0]$END_FG_COLOR Required dependencies installed."
else
echo Required dependencies still missing. Build will probably fail.
exit 0
echo -e "$RED_FG[$0]$END_FG_COLOR Required dependencies missing. Run \`${TEAL_FG}./scripts/configure-dev.sh$END_FG_COLOR\` to install."
exit 1
fi

3 changes: 2 additions & 1 deletion scripts/configure_dev-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -ex

function install_go_module {
local OUTPUT
OUTPUT=$(GO111MODULE=off go get -u $1 2>&1)
OUTPUT=$(GO111MODULE=off go get -u "$1" 2>&1)
if [ "${OUTPUT}" != "" ]; then
echo "error: executing \"go get -u $1\" failed : ${OUTPUT}"
exit 1
Expand All @@ -14,3 +14,4 @@ function install_go_module {
install_go_module golang.org/x/lint/golint
install_go_module golang.org/x/tools/cmd/stringer
install_go_module github.com/go-swagger/go-swagger/cmd/swagger

11 changes: 7 additions & 4 deletions scripts/configure_dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

OS=$(${SCRIPTPATH}/ostype.sh)
OS=$("$SCRIPTPATH"/ostype.sh)

function install_or_upgrade {
if brew ls --versions "$1" >/dev/null; then
Expand All @@ -14,13 +14,14 @@ function install_or_upgrade {
}

if [ "${OS}" = "linux" ]; then
if [ -z "$(dpkg -l sudo 2>/dev/null | grep ^ii)" ] ; then
if ! which sudo > /dev/null
then
apt-get update
apt-get -y install sudo
fi

sudo apt-get update
sudo apt-get -y install libboost-all-dev expect jq autoconf
sudo apt-get install -y libboost-all-dev expect jq autoconf shellcheck
elif [ "${OS}" = "darwin" ]; then
brew update
brew tap homebrew/cask
Expand All @@ -30,6 +31,8 @@ elif [ "${OS}" = "darwin" ]; then
install_or_upgrade libtool
install_or_upgrade autoconf
install_or_upgrade automake
install_or_upgrade shellcheck
fi

${SCRIPTPATH}/configure_dev-deps.sh
"$SCRIPTPATH"/configure_dev-deps.sh