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

Output of sfdisk -d in Ubuntu 20.04 does not end in a comma #2

Merged
merged 2 commits into from
May 13, 2020

Conversation

craigfrancis
Copy link
Contributor

No description provided.

@s-n-ushakov
Copy link
Owner

s-n-ushakov commented May 13, 2020

Hi Craig, and thank you for your patch.
The only reason why I have not accepted it yet, is that I do not understand why/how it works for me without that comma on my Ubuntu 18.04... :)
Just to have things clarified: could you share your output of sfdisk -d ... command? Or maybe just a single line for a relevant partition... Mine is the following:
/dev/sda1 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=2FFCC127-F6CE-40F0-9932-D1DFD14E9462, name="EFI System Partition"
And the only current guess of mine why your patch works for me, and why BASH_REMATCH[2] does not include the "name=..." trailer, is that it may be a result of a kind of side effect in the shell, when the space before "]]" in the condition is treated as a part of regular expression too. Any ideas of yours are most welcome... :)

@s-n-ushakov
Copy link
Owner

@craigfrancis ... or maybe I rather do not understand why it works for you, in particular why ([^,]+) does not get the "name=..." trailer included. Do you have that trailer?

@craigfrancis
Copy link
Contributor Author

First, thanks for the script, it's been really useful.

As to my issue, I simply don't have the ", name="EFI System Partition" at the end (the UUID is the last thing).

I'm hoping that sfdisk will either finish the UUID with a comma, or end of line; but I suppose there could be other things?

So maybe something like uuid=([a-fA-F0-9-]+) would be better?

Here are some tests, the first one is the original, second is the one in this patch, and two other options:

^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([^,]+),
1) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
2) -
3) -

^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([^,]+)
1) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
2) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
3) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462 made up example'

^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([^,[:blank:]]+)
1) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
2) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
3) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'

^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([a-fA-F0-9-]+)
1) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
2) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'
3) '2FFCC127-F6CE-40F0-9932-D1DFD14E9462'

Test script...

declare -A lines;
lines[0]='/dev/sda1 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=2FFCC127-F6CE-40F0-9932-D1DFD14E9462, name="EFI System Partition"';
lines[1]='/dev/sda1 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=2FFCC127-F6CE-40F0-9932-D1DFD14E9462';
lines[2]='/dev/sda1 : start= 2048, size= 1048576, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=2FFCC127-F6CE-40F0-9932-D1DFD14E9462 made up example';

declare -A regexps;
regexps[0]='^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([^,]+),'; # Does not handle UUID being last.
regexps[1]='^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([^,]+)';
regexps[2]='^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([^,[:blank:]]+)';
regexps[4]='^([^[:blank:]]+)[[:blank:]]:[[:blank:]].*[[:blank:]]uuid=([a-fA-F0-9-]+)';

for regexp in "${regexps[@]}"; do
  echo;
  echo "$regexp"
  i=0;
  for line in "${lines[@]}"; do
    i=$((i+1));
    if [[ "${line}" =~ $regexp ]] ; then
      echo "$i) '${BASH_REMATCH[2]}'";
    else
      echo "$i) -";
    fi
  done
  echo;
done

@s-n-ushakov
Copy link
Owner

Well... what about [^,[:blank:]] ?
It looks least restrictive... Do you agree?
If yes, and if you agree to update your patch, I'm ok with merging it... :)

@craigfrancis
Copy link
Contributor Author

Yep, done.

@s-n-ushakov s-n-ushakov merged commit e3ab260 into s-n-ushakov:master May 13, 2020
@s-n-ushakov
Copy link
Owner

Merged, thanks :)

@craigfrancis
Copy link
Contributor Author

np, and thanks for writing this, made it much easier to re-name.

@s-n-ushakov s-n-ushakov added the bug Something isn't working label Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants