Skip to content

Commit d21dc08

Browse files
authored
bash-my-aws: 2020-01-11 -> 2025-01-22 and refactor (#381934)
2 parents 69191b1 + a8d4b83 commit d21dc08

File tree

3 files changed

+151
-45
lines changed

3 files changed

+151
-45
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
diff --git a/bin/bma b/bin/bma
2+
index 6144842..26965ce 100755
3+
--- a/bin/bma
4+
+++ b/bin/bma
5+
@@ -13,7 +13,7 @@
6+
#
7+
# Assumes you have installed bash-my-aws to standard location
8+
9+
-for f in "${BMA_HOME:-$HOME/.bash-my-aws}"/lib/*-functions; do source $f; done
10+
+for f in @out@/lib/*-functions; do source $f; done
11+
12+
# Disable awcli client side pager
13+
#
14+
diff --git a/scripts/build b/scripts/build
15+
index 54a786b..37a05df 100755
16+
--- a/scripts/build
17+
+++ b/scripts/build
18+
@@ -41,7 +41,7 @@ funcs_after_bma=$(compgen -A function)
19+
exclusions=('region')
20+
21+
for fnc in $(echo "${funcs_before_bma}" "${funcs_after_bma}" "${exclusions}" | tr ' ' '\n' | LC_ALL=C sort | uniq -u); do
22+
- echo "alias $fnc='\${BMA_HOME:-\$HOME/.bash-my-aws}/bin/bma $fnc'" >> "$aliases_destination"
23+
+ echo "alias $fnc='@out@/bin/bma $fnc'" >> "$aliases_destination"
24+
done;
25+
26+
27+
diff --git a/scripts/build-completions b/scripts/build-completions
28+
index 2b5d49b..bf86af6 100755
29+
--- a/scripts/build-completions
30+
+++ b/scripts/build-completions
31+
@@ -6,7 +6,7 @@ cat <<EOF
32+
# DO NOT MANUALLY MODIFY THIS FILE.
33+
# Use 'scripts/build' to regenerate if required.
34+
35+
-bma_path="\${BMA_HOME:-\$HOME/.bash-my-aws}"
36+
+bma_path="@out@"
37+
EOF
38+
39+
# load in all the completions from scripts/completions
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
diff --git a/test/stack-spec.sh b/test/stack-spec.sh
2+
index f04a10c..1165953 100755
3+
--- a/test/stack-spec.sh
4+
+++ b/test/stack-spec.sh
5+
@@ -72,28 +72,30 @@ describe "_bma_stack_template_arg:" "$(
6+
7+
)"
8+
9+
-[[ -d cloudformation/params ]] || mkdir -p cloudformation/params
10+
+TEST_DIR=$(mktemp -d)
11+
+
12+
+[[ -d "$TEST_DIR"/cloudformation/params ]] || mkdir -p "$TEST_DIR"/cloudformation/params
13+
14+
15+
# templates
16+
touch \
17+
- $(dirname $0)/cloudformation/great-app.json \
18+
- $(dirname $0)/cloudformation/great-app.yml \
19+
- $(dirname $0)/cloudformation/great-app.yaml \
20+
+ "$TEST_DIR"/cloudformation/great-app.json \
21+
+ "$TEST_DIR"/cloudformation/great-app.yml \
22+
+ "$TEST_DIR"/cloudformation/great-app.yaml \
23+
24+
# params
25+
26+
[[ -d params ]] || mkdir params
27+
28+
touch \
29+
- $(dirname $0)/cloudformation/great-app-params.json \
30+
- $(dirname $0)/cloudformation/great-app-params-staging.json \
31+
- $(dirname $0)/cloudformation/great-app-params-another-env.json \
32+
- $(dirname $0)/cloudformation/params/great-app-params.json \
33+
- $(dirname $0)/cloudformation/params/great-app-params-staging.json \
34+
- $(dirname $0)/cloudformation/params/great-app-params-another-env.json
35+
+ "$TEST_DIR"/cloudformation/great-app-params.json \
36+
+ "$TEST_DIR"/cloudformation/great-app-params-staging.json \
37+
+ "$TEST_DIR"/cloudformation/great-app-params-another-env.json \
38+
+ "$TEST_DIR"/cloudformation/params/great-app-params.json \
39+
+ "$TEST_DIR"/cloudformation/params/great-app-params-staging.json \
40+
+ "$TEST_DIR"/cloudformation/params/great-app-params-another-env.json
41+
42+
-cd $(dirname $0)/cloudformation
43+
+cd "$TEST_DIR"/cloudformation
44+
45+
describe "_bma_stack_args:" "$(
46+
context "without an argument" "$(
47+
@@ -115,3 +117,5 @@ describe "_bma_stack_args:" "$(
48+
)"
49+
50+
cd -
51+
+
52+
+rm -rf "$TEST_DIR"

pkgs/by-name/ba/bash-my-aws/package.nix

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,102 @@
22
lib,
33
stdenv,
44
makeWrapper,
5-
awscli,
5+
awscli2,
66
jq,
77
unixtools,
88
fetchFromGitHub,
99
installShellFiles,
1010
bashInteractive,
11+
getopt,
12+
python3,
1113
}:
12-
14+
let
15+
runtimeDeps = [
16+
awscli2
17+
jq
18+
unixtools.column
19+
bashInteractive
20+
getopt
21+
(python3.withPackages (ps: [ ps.jmespath ]))
22+
];
23+
in
1324
stdenv.mkDerivation rec {
1425
pname = "bash-my-aws";
15-
version = "unstable-2020-01-11";
26+
version = "0-unstable-2025-01-22";
1627

1728
src = fetchFromGitHub {
1829
owner = "bash-my-aws";
1930
repo = "bash-my-aws";
20-
rev = "5a97ce2c22affca1299022a5afa109d7b62242ba";
21-
sha256 = "sha256-RZvaiyRK8FnZbHyLkWz5VrAcsnMtHCiIo64GpNZgvqY=";
31+
rev = "d338b43cc215719c1853ec500c946db6b9caaa11";
32+
sha256 = "sha256-PR52T6XCrakQsBOJXf0PaYpYE5oMcIz5UDA4I9B7C38=";
2233
};
2334

2435
dontConfigure = true;
25-
dontBuild = true;
2636

27-
propagatedBuildInputs = [
28-
awscli
29-
jq
30-
unixtools.column
31-
bashInteractive
32-
];
37+
propagatedBuildInputs = runtimeDeps;
38+
3339
nativeBuildInputs = [
3440
makeWrapper
3541
installShellFiles
42+
bashInteractive
3643
];
3744

38-
checkPhase = ''
39-
pushd test
40-
./shared-spec.sh
41-
./stack-spec.sh
42-
popd
45+
patches = [
46+
./0001-update-paths-to-placeholders.patch
47+
./0002-fix-tests.patch
48+
];
49+
50+
postPatch = ''
51+
patchShebangs --build ./scripts
52+
53+
substituteAllInPlace ./scripts/build
54+
substituteAllInPlace ./scripts/build-completions
55+
substituteAllInPlace ./bin/bma
56+
'';
57+
58+
buildPhase = ''
59+
runHook preBuild
60+
./scripts/build
61+
runHook postBuild
4362
'';
63+
4464
installPhase = ''
65+
runHook preInstall
66+
4567
mkdir -p $out
4668
cp -r . $out
47-
'';
48-
postFixup = ''
49-
pushd $out
50-
substituteInPlace scripts/build \
51-
--replace '~/.bash-my-aws' $out
52-
substituteInPlace scripts/build-completions \
53-
--replace "{HOME}" $out \
54-
--replace '~/.bash-my-aws' $out
55-
./scripts/build
56-
./scripts/build-completions
57-
substituteInPlace bash_completion.sh \
58-
--replace "{HOME}" $out \
59-
--replace .bash-my-aws ""
60-
substituteInPlace bin/bma \
61-
--replace '~/.bash-my-aws' $out
62-
wrapProgram $out/bin/bma --prefix PATH : ${
63-
lib.makeBinPath [
64-
awscli
65-
jq
66-
unixtools.column
67-
bashInteractive
68-
]
69-
}
70-
installShellCompletion --bash --name bash-my-aws.bash bash_completion.sh
71-
chmod +x $out/lib/*
72-
patchShebangs --host $out/lib
73-
installShellCompletion --bash --name bash-my-aws.bash bash_completion.sh
69+
7470
cat > $out/bin/bma-init <<EOF
7571
echo source $out/aliases
76-
echo source $out/bash_completion.sh
7772
EOF
7873
chmod +x $out/bin/bma-init
74+
75+
installShellCompletion --bash --name bash-my-aws.bash $out/bash_completion.sh
76+
77+
runHook postInstall
78+
'';
79+
80+
doInstallCheck = true;
81+
installCheckPhase = ''
82+
runHook preInstallCheck
83+
pushd $out
84+
make test
7985
popd
86+
runHook postInstallCheck
87+
'';
88+
89+
preFixup = ''
90+
wrapProgram $out/bin/bma --prefix PATH : ${lib.makeBinPath runtimeDeps}
91+
92+
# make lib file executable so they are picked up by patchShebangs
93+
chmod +x $out/lib/*
8094
'';
8195

8296
meta = with lib; {
8397
homepage = "https://bash-my-aws.org";
8498
description = "CLI commands for AWS";
8599
license = licenses.mit;
86100
maintainers = with maintainers; [ tomberek ];
101+
mainProgram = "bma";
87102
};
88103
}

0 commit comments

Comments
 (0)