Skip to content

Commit

Permalink
Merge pull request #32 from art19/ziggythehamster/make-ec2nvme-nsid-b…
Browse files Browse the repository at this point in the history
…ash-only

Change ec2nvme-nsid to use Bash built-ins
  • Loading branch information
vigh-m authored Mar 6, 2024
2 parents 220d932 + 83f080f commit 37726e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion amazon-ec2-utils.spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Name: amazon-ec2-utils
Summary: A set of tools for running in EC2
Version: 2.1.0
Version: 2.2.0
Release: 1%{?dist}
License: MIT
Group: System Tools
Expand Down Expand Up @@ -75,6 +75,9 @@ rm -rf $RPM_BUILD_ROOT
/etc/udev/rules.d/60-cdrom_id.rules

%changelog
* Thu Jan 18 2024 Keith Gable <gablk@amazon.com> - 2.2.0-1
- Change ec2nvme-nsid to use Bash string manipulation to improve
performance and reliability

* Thu Apr 6 2023 Noah Meyerhans <nmeyerha@amazon.com> - 2.1.0-1
- Add --quiet option to ec2-metadata
Expand Down
15 changes: 11 additions & 4 deletions ec2nvme-nsid
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
# for the specific language governing permissions and limitations under
# the License.

#Expected input if partition's kernel name like nvme0n1p2
if [ $# -eq 0 ] ; then
# Expected input is partition's kernel name like nvme0n1p2 or nvme0n1, output would be 1

if [[ $# -ne 1 ]]; then
exit 1
else
# extract ns id from partition's kernel name and export it
NSID=$(echo -n "$@" | cut -f 3 -d 'n' | cut -f 1 -d 'p')
kernel_name=$1

# Remove nvme prefix (also deals with any /dev that might accidentally get passed in)
prefix_removed=${kernel_name#*nvme*n}

# Remove partition suffix
NSID=${prefix_removed%p*}

echo "_NS_ID=${NSID}"
fi

0 comments on commit 37726e7

Please sign in to comment.