Unverified Commit d21dc08c authored by tomberek's avatar tomberek Committed by GitHub
Browse files

bash-my-aws: 2020-01-11 -> 2025-01-22 and refactor (#381934)

parents 69191b1a a8d4b839
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
diff --git a/bin/bma b/bin/bma
index 6144842..26965ce 100755
--- a/bin/bma
+++ b/bin/bma
@@ -13,7 +13,7 @@
 #
 # Assumes you have installed bash-my-aws to standard location
 
-for f in "${BMA_HOME:-$HOME/.bash-my-aws}"/lib/*-functions; do source $f; done
+for f in @out@/lib/*-functions; do source $f; done
 
 # Disable awcli client side pager
 #
diff --git a/scripts/build b/scripts/build
index 54a786b..37a05df 100755
--- a/scripts/build
+++ b/scripts/build
@@ -41,7 +41,7 @@ funcs_after_bma=$(compgen -A function)
 exclusions=('region')
 
 for fnc in $(echo "${funcs_before_bma}" "${funcs_after_bma}" "${exclusions}" | tr ' ' '\n' | LC_ALL=C sort | uniq -u); do
-  echo "alias $fnc='\${BMA_HOME:-\$HOME/.bash-my-aws}/bin/bma $fnc'" >> "$aliases_destination"
+  echo "alias $fnc='@out@/bin/bma $fnc'" >> "$aliases_destination"
 done;
 
 
diff --git a/scripts/build-completions b/scripts/build-completions
index 2b5d49b..bf86af6 100755
--- a/scripts/build-completions
+++ b/scripts/build-completions
@@ -6,7 +6,7 @@ cat <<EOF
 # DO NOT MANUALLY MODIFY THIS FILE.
 # Use 'scripts/build' to regenerate if required.
 
-bma_path="\${BMA_HOME:-\$HOME/.bash-my-aws}"
+bma_path="@out@"
 EOF
 
 # load in all the completions from scripts/completions
+52 −0
Original line number Diff line number Diff line
diff --git a/test/stack-spec.sh b/test/stack-spec.sh
index f04a10c..1165953 100755
--- a/test/stack-spec.sh
+++ b/test/stack-spec.sh
@@ -72,28 +72,30 @@ describe "_bma_stack_template_arg:" "$(
 
 )"
 
-[[ -d cloudformation/params ]] || mkdir -p cloudformation/params
+TEST_DIR=$(mktemp -d)
+
+[[ -d "$TEST_DIR"/cloudformation/params ]] || mkdir -p "$TEST_DIR"/cloudformation/params
 
 
 # templates
 touch            \
-  $(dirname $0)/cloudformation/great-app.json \
-  $(dirname $0)/cloudformation/great-app.yml  \
-  $(dirname $0)/cloudformation/great-app.yaml \
+  "$TEST_DIR"/cloudformation/great-app.json \
+  "$TEST_DIR"/cloudformation/great-app.yml  \
+  "$TEST_DIR"/cloudformation/great-app.yaml \
 
 # params
 
 [[ -d params ]] || mkdir params
 
 touch                                      \
-  $(dirname $0)/cloudformation/great-app-params.json                    \
-  $(dirname $0)/cloudformation/great-app-params-staging.json            \
-  $(dirname $0)/cloudformation/great-app-params-another-env.json        \
-  $(dirname $0)/cloudformation/params/great-app-params.json             \
-  $(dirname $0)/cloudformation/params/great-app-params-staging.json     \
-  $(dirname $0)/cloudformation/params/great-app-params-another-env.json
+  "$TEST_DIR"/cloudformation/great-app-params.json                    \
+  "$TEST_DIR"/cloudformation/great-app-params-staging.json            \
+  "$TEST_DIR"/cloudformation/great-app-params-another-env.json        \
+  "$TEST_DIR"/cloudformation/params/great-app-params.json             \
+  "$TEST_DIR"/cloudformation/params/great-app-params-staging.json     \
+  "$TEST_DIR"/cloudformation/params/great-app-params-another-env.json
 
-cd $(dirname $0)/cloudformation
+cd "$TEST_DIR"/cloudformation
 
 describe "_bma_stack_args:" "$(
   context "without an argument" "$(
@@ -115,3 +117,5 @@ describe "_bma_stack_args:" "$(
 )"
 
 cd -
+
+rm -rf "$TEST_DIR"
+60 −45
Original line number Diff line number Diff line
@@ -2,81 +2,95 @@
  lib,
  stdenv,
  makeWrapper,
  awscli,
  awscli2,
  jq,
  unixtools,
  fetchFromGitHub,
  installShellFiles,
  bashInteractive,
  getopt,
  python3,
}:

let
  runtimeDeps = [
    awscli2
    jq
    unixtools.column
    bashInteractive
    getopt
    (python3.withPackages (ps: [ ps.jmespath ]))
  ];
in
stdenv.mkDerivation rec {
  pname = "bash-my-aws";
  version = "unstable-2020-01-11";
  version = "0-unstable-2025-01-22";

  src = fetchFromGitHub {
    owner = "bash-my-aws";
    repo = "bash-my-aws";
    rev = "5a97ce2c22affca1299022a5afa109d7b62242ba";
    sha256 = "sha256-RZvaiyRK8FnZbHyLkWz5VrAcsnMtHCiIo64GpNZgvqY=";
    rev = "d338b43cc215719c1853ec500c946db6b9caaa11";
    sha256 = "sha256-PR52T6XCrakQsBOJXf0PaYpYE5oMcIz5UDA4I9B7C38=";
  };

  dontConfigure = true;
  dontBuild = true;

  propagatedBuildInputs = [
    awscli
    jq
    unixtools.column
    bashInteractive
  ];
  propagatedBuildInputs = runtimeDeps;

  nativeBuildInputs = [
    makeWrapper
    installShellFiles
    bashInteractive
  ];

  checkPhase = ''
    pushd test
    ./shared-spec.sh
    ./stack-spec.sh
    popd
  patches = [
    ./0001-update-paths-to-placeholders.patch
    ./0002-fix-tests.patch
  ];

  postPatch = ''
    patchShebangs --build ./scripts

    substituteAllInPlace ./scripts/build
    substituteAllInPlace ./scripts/build-completions
    substituteAllInPlace ./bin/bma
  '';

  buildPhase = ''
    runHook preBuild
    ./scripts/build
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    mkdir -p $out
    cp -r . $out
  '';
  postFixup = ''
    pushd $out
    substituteInPlace scripts/build \
        --replace '~/.bash-my-aws' $out
    substituteInPlace scripts/build-completions \
        --replace "{HOME}" $out \
        --replace '~/.bash-my-aws' $out
    ./scripts/build
    ./scripts/build-completions
    substituteInPlace bash_completion.sh \
        --replace "{HOME}" $out \
        --replace .bash-my-aws ""
    substituteInPlace bin/bma \
        --replace '~/.bash-my-aws' $out
    wrapProgram $out/bin/bma --prefix PATH : ${
      lib.makeBinPath [
        awscli
        jq
        unixtools.column
        bashInteractive
      ]
    }
    installShellCompletion --bash --name bash-my-aws.bash bash_completion.sh
    chmod +x $out/lib/*
    patchShebangs --host $out/lib
    installShellCompletion --bash --name bash-my-aws.bash bash_completion.sh

    cat > $out/bin/bma-init <<EOF
    echo source $out/aliases
    echo source $out/bash_completion.sh
    EOF
    chmod +x $out/bin/bma-init

    installShellCompletion --bash --name bash-my-aws.bash $out/bash_completion.sh

    runHook postInstall
  '';

  doInstallCheck = true;
  installCheckPhase = ''
    runHook preInstallCheck
    pushd $out
    make test
    popd
    runHook postInstallCheck
  '';

  preFixup = ''
    wrapProgram $out/bin/bma --prefix PATH : ${lib.makeBinPath runtimeDeps}

    # make lib file executable so they are picked up by patchShebangs
    chmod +x $out/lib/*
  '';

  meta = with lib; {
@@ -84,5 +98,6 @@ stdenv.mkDerivation rec {
    description = "CLI commands for AWS";
    license = licenses.mit;
    maintainers = with maintainers; [ tomberek ];
    mainProgram = "bma";
  };
}