Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: cleanup command usage #85

Merged
merged 10 commits into from
Feb 4, 2021
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!.gitattributes
!.editorconfig
!.taplo.toml
!.gitkeep

# semver management
!.releaserc*
Expand Down
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG IMAGE=debian
ARG VERSION=latest
FROM ${IMAGE}:${VERSION}

ARG PROMPT_SHELL=bash

WORKDIR /repo
COPY . .

RUN ./hack/pre.sh prompt
USER prompt

RUN set -ex; \
./install.sh ${PROMPT_SHELL}; \
./hack/clean.sh --force;

WORKDIR /home/prompt
ENTRYPOINT [ "$SHELL" ]
CMD [ "-l" ]
4 changes: 2 additions & 2 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ __am_prompt_update()
print-warn \
"prompt: latest version already installed: ${PROMPT_SHA}" \
" - run update-prompt with the --force flag to reinstall ${CLR_CLEAR}"
return 0
return
fi
fi

if [ -n "${PROMPT_DRY_RUN:-}" ]; then
print-warn" \
prompt: a new version of prompt is available: ${PROMPT_SHA}" \
" - run the update-prompt command line tool to upgrade${CLR_CLEAR}"
return 0
return
fi

PROMPT_INSTALL_URI="https://github.com/automotiveMastermind/prompt/archive/$PROMPT_COMMIT_REF.tar.gz"
Expand Down
5 changes: 5 additions & 0 deletions hack/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /usr/bin/env sh

# find all executables not in hidden folders and lint them
find . -not -path './.*/*' -type f -perm +ugo+x -print0 \
| xargs -0 shellcheck -e SC1090,SC1091,SC1071
17 changes: 17 additions & 0 deletions hack/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#! /usr/bin/env sh

set -e

if [ -n "${1:-}" ] && [ -d /repo ]; then
sudo rm -rf /repo
fi

if command -v apt-get 1>/dev/null 2>&1; then
sudo apt-get autoremove -y
sudo rm -rf /var/lib/apt/lists/*
sudo rm -rf /var/cache/apt
fi

if command -v dnf 1>/dev/null 2>&1; then
dnf clean all
fi
77 changes: 77 additions & 0 deletions hack/containers/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! /usr/bin/env sh

set -e

GITHUB_SHA=${GITHUB_SHA:-$(git rev-parse HEAD)}
GITHUB_REF=${GITHUB_REF:=$(git rev-parse --abbrev-ref HEAD)}
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-"automotivemastermind"}

IMAGE="debian"
VERSION="latest"
OS=
PLATFORMS=

while :; do
case $1 in
-o|--os)
OS="$2 $OS"
shift
;;
-p|--platform)
PLATFORMS="$2 $PLATFORMS"
shift
;;
-i|--image)
IMAGE=$2
shift
;;
-v|--version)
VERSION=$2
shift
;;
--debug)
set -x
;;
?*)
printf "\n%s\n" "error: unknown argument: $1"
exit 1
;;
*)
break
;;
esac
shift
done

if [ -z "${OS:-}" ]; then
OS="linux"
fi

if [ -z "${PLATFORMS:-}" ]; then
PLATFORMS="amd64 arm64"
fi

for os in $OS; do
for platform in $PLATFORMS; do
if [ "$VERSION" = "latest" ]; then
tag="$IMAGE-$platform"
else
tag="$IMAGE-$VERSION-$platform"
fi

printf "\nBUILDING:\n PLATFORM : %s/%s\n IMAGE : %s:%s\n TAG : %s\n\n" \
"$os" "$platform" "$IMAGE" "$VERSION" "$tag"

# build the image
docker buildx build --pull --load \
--platform="$os/$platform" \
--build-arg IMAGE="$IMAGE" \
--build-arg VERSION="$VERSION" \
--label=org.opencontainers.image.name=prompt \
--label=org.opencontainers.image.revision="$GITHUB_SHA" \
--label=org.opencontainers.image.version="$GITHUB_REF" \
--label=org.opencontainers.image.source="https://github.com/$GITHUB_REPOSITORY" \
--tag "ghcr.io/$GITHUB_REPOSITORY/prompt:${tag}" \
"${PWD}"
done
done
2 changes: 1 addition & 1 deletion hack/containers/lint.sh → hack/containers/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ docker run \
--name "$CONTAINER_NAME" \
--rm \
--tty \
"$IMAGE" './hack/lint.sh'
"$IMAGE" './hack/check.sh'
24 changes: 0 additions & 24 deletions hack/containers/e2e.apt.sh

This file was deleted.

24 changes: 0 additions & 24 deletions hack/containers/e2e.yum.sh

This file was deleted.

6 changes: 0 additions & 6 deletions hack/e2e.apt.sh

This file was deleted.

3 changes: 3 additions & 0 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -e

# install prerequisites
./hack/prerequisites.sh

# install and test bash
./hack/install.sh bash
./hack/test.sh bash
Expand Down
6 changes: 0 additions & 6 deletions hack/e2e.yum.sh

This file was deleted.

4 changes: 2 additions & 2 deletions hack/lint.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env sh

# find all executables not in hidden folders and lint them
find . -not -path './.*/*' -type f -perm +ugo+x -print0 \
| xargs -0 shellcheck -e SC1090,SC1091,SC1071
find . -name 'Dockerfile*' -type f -print0 \
| xargs -0 hadolint
13 changes: 0 additions & 13 deletions hack/pre.apt.sh

This file was deleted.

26 changes: 26 additions & 0 deletions hack/pre.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env sh

set -e

USERNAME=${1:-build}

if command -v apt-get 1>/dev/null 2>&1; then
apt-get update
apt-get --no-install-recommends install -y \
sudo curl unzip
rm -rf /var/lib/apt/lists/*
rm -rf /var/cache/apt
fi

if command -v dnf 1>/dev/null 2>&1; then
dnf update -y
dnf install -y \
sudo curl unzip
dnf clean all
fi

useradd --uid 1000 --user-group --system --create-home --no-log-init --groups tty --shell /bin/sh "${USERNAME}"
printf "%s\n" "$USERNAME ALL=(ALL) NOPASSWD:ALL" >>/etc/sudoers

chown -R "${USERNAME}":"${USERNAME}" /home/"${USERNAME}"
chmod u=rwx,g=rx,o= /home/"${USERNAME}"
17 changes: 0 additions & 17 deletions hack/pre.yum.sh

This file was deleted.

16 changes: 8 additions & 8 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ __am_prompt_install() {
fi

print-success "creating $AM_PROMPT"
mkdir -p "$AM_PROMPT/user" 1>/dev/null 2>&1
mkdir -p "$AM_PROMPT/user/bin" 1>/dev/null 2>&1

print-success "installing promptMastermind to $AM_PROMPT"
cp -Rf "$SCRIPT_DIR/src/bash" "$AM_PROMPT" 1>/dev/null
Expand All @@ -61,22 +61,24 @@ __am_prompt_install() {

if [ ! -f "$USER_ITEM_PATH" ]; then
print-success "initializing user profile: $USER_ITEM_NAME at $USER_ITEM_PATH"
cp "$USER_ITEM" "$USER_ITEM_PATH"
cp -r "$USER_ITEM" "$USER_ITEM_PATH"
fi
done

# detect platform
if [ -f /etc/os-release ]; then
. /etc/os-release
UNAMES="$ID ${ID_LIKE:-unknown} linux"
else
UNAMES=$(uname | tr '[:upper:]' '[:lower:]')
fi

UNAME=
until [ "$UNAME" = "$UNAMES" ]; do
UNAME=${UNAMES%%' '*}
UNAMES=${UNAMES#*' '}
# detect wsl
if [ -n "${WSL_DISTRO_NAME:-}" ]; then
UNAMES="wsl $UNAMES"
fi

for UNAME in $UNAMES; do
UNAME_PATH="$AM_PROMPT/sh/install/$UNAME.sh"

if [ ! -f "$UNAME_PATH" ]; then
Expand All @@ -85,8 +87,6 @@ __am_prompt_install() {

print-success "installing platform prerequisites ($UNAME)"
. "$UNAME_PATH"

break
done

if [ ! -d "$AM_PROMPT/zsh/completions" ]; then
Expand Down
12 changes: 12 additions & 0 deletions src/bash/install/centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /usr/bin/env sh

__am_prompt_install_centos() {
YUM=$(command -v dnf 2>/dev/null || command -v yum 2>/dev/null)
PACKAGES='bash bash-completion'

print-success "centos: installing $PACKAGES..."
# shellcheck disable=SC2086
sudo "$YUM" install -y $PACKAGES
}

__am_prompt_install_centos
20 changes: 20 additions & 0 deletions src/bash/install/debian.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /usr/bin/env sh

set -e

__am_prompt_install_debian() {
SUDO=$(command -v sudo 2>/dev/null || "")
PACKAGES='bash bash-completion'

print-success "debian: updating software repositories..."
$SUDO apt-get update -y

print-success "debian: installing $PACKAGES..."
# shellcheck disable=SC2086
$SUDO apt-get install -y $PACKAGES

print-success "debian: removing unnecessary dependencies..."
$SUDO apt-get autoremove -y
}

__am_prompt_install_debian
18 changes: 0 additions & 18 deletions src/bash/install/linux.sh

This file was deleted.

3 changes: 3 additions & 0 deletions src/bash/install/linuxmint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /usr/bin/env sh

. "$AM_PROMPT"/bash/install/debian.sh
Loading