Skip to content

Commit 37726e7

Browse files
authored
Merge pull request #32 from art19/ziggythehamster/make-ec2nvme-nsid-bash-only
Change ec2nvme-nsid to use Bash built-ins
2 parents 220d932 + 83f080f commit 37726e7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

amazon-ec2-utils.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Name: amazon-ec2-utils
22
Summary: A set of tools for running in EC2
3-
Version: 2.1.0
3+
Version: 2.2.0
44
Release: 1%{?dist}
55
License: MIT
66
Group: System Tools
@@ -75,6 +75,9 @@ rm -rf $RPM_BUILD_ROOT
7575
/etc/udev/rules.d/60-cdrom_id.rules
7676

7777
%changelog
78+
* Thu Jan 18 2024 Keith Gable <[email protected]> - 2.2.0-1
79+
- Change ec2nvme-nsid to use Bash string manipulation to improve
80+
performance and reliability
7881

7982
* Thu Apr 6 2023 Noah Meyerhans <[email protected]> - 2.1.0-1
8083
- Add --quiet option to ec2-metadata

ec2nvme-nsid

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
# for the specific language governing permissions and limitations under
77
# the License.
88

9-
#Expected input if partition's kernel name like nvme0n1p2
10-
if [ $# -eq 0 ] ; then
9+
# Expected input is partition's kernel name like nvme0n1p2 or nvme0n1, output would be 1
10+
11+
if [[ $# -ne 1 ]]; then
1112
exit 1
1213
else
13-
# extract ns id from partition's kernel name and export it
14-
NSID=$(echo -n "$@" | cut -f 3 -d 'n' | cut -f 1 -d 'p')
14+
kernel_name=$1
15+
16+
# Remove nvme prefix (also deals with any /dev that might accidentally get passed in)
17+
prefix_removed=${kernel_name#*nvme*n}
18+
19+
# Remove partition suffix
20+
NSID=${prefix_removed%p*}
21+
1522
echo "_NS_ID=${NSID}"
1623
fi

0 commit comments

Comments
 (0)