How to check if gpg key already exist with bash then skip downloading/adding?Added key, but dget still shows “gpg: Can't check signature: public key not found”How do I publish a GPG Key?How do I import a private key into GPG so that it becomes the default key?GPG encryption with and without public keyHow to skip unzipping a file that already exists?Bash Script that check if a database exist

Encrypting email addresses in php

Is the .wav file created from a .mp3 file has better quality than the .mp3 file itself?

Schemes/ Mechanisms that could provide one time decryption?

Selecting from a list of tuples

Is the "p" in "spin" really a "b"?

Am I being exploited by my supervisor?

Rules about invisibility, bag of holding, an imp and an undead's head scenario

When is TeX better than LaTeX?

How to set up a "Forced choice" for players in a game?

What would happen if the Queen died immediately before a general election?

Computer power supplies usually have higher efficiency on 230V than on 115V. Why?

Is Bitlocker secure enough for portable storage devices?

Can two Cloud of Daggers be cast in the same area by different spell casters?

Am I overreacting or seeing things where they don't exist?

Controlling a robot blindfolded on a 9x9 grid

Gradient, Divergence and Curl

Large (70) stellar mass black hole disrupts astrophysics?

How do I check if proportion of values in list are mostly positive?

Germany's Ladenschlussgesetz in comparison to Israel's business laws about the Sabbath

Angled cuts without miter saw or miter box?

Correct word for "the law does not allow for that"

"I did it this way, it worked, so what I did is correct"

Is it possible for a moon to have a higher gravity than the planet it is attached to?

How much piloting did the Apollo astronauts actually do?



How to check if gpg key already exist with bash then skip downloading/adding?


Added key, but dget still shows “gpg: Can't check signature: public key not found”How do I publish a GPG Key?How do I import a private key into GPG so that it becomes the default key?GPG encryption with and without public keyHow to skip unzipping a file that already exists?Bash Script that check if a database exist






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









1


















So basically, I want to run these 2 commands but I want to check if the keys already existed. I know how to do the ifthenelse in bash but I'm not sure how to get the result and store in variable for me to check so that i can put it in the conditional operator. For example, if it already existed then I can skip downloading and adding it again.



Example 1 (--fetch-keys):



 sudo apt-key adv --fetch-keys https://packages.microsoft.com/keys/microsoft.asc
sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null <<- END
deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main
END


Example 2 (--recv-keys):



 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B9A06DE3
sudo tee /etc/apt/sources.list.d/inkscape.list > /dev/null <<- END
deb [arch=amd64] http://ppa.launchpad.net/inkscape.dev/stable-daily/ubuntu bionic main
END









share|improve this question































    1


















    So basically, I want to run these 2 commands but I want to check if the keys already existed. I know how to do the ifthenelse in bash but I'm not sure how to get the result and store in variable for me to check so that i can put it in the conditional operator. For example, if it already existed then I can skip downloading and adding it again.



    Example 1 (--fetch-keys):



     sudo apt-key adv --fetch-keys https://packages.microsoft.com/keys/microsoft.asc
    sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null <<- END
    deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main
    END


    Example 2 (--recv-keys):



     sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B9A06DE3
    sudo tee /etc/apt/sources.list.d/inkscape.list > /dev/null <<- END
    deb [arch=amd64] http://ppa.launchpad.net/inkscape.dev/stable-daily/ubuntu bionic main
    END









    share|improve this question



























      1













      1









      1








      So basically, I want to run these 2 commands but I want to check if the keys already existed. I know how to do the ifthenelse in bash but I'm not sure how to get the result and store in variable for me to check so that i can put it in the conditional operator. For example, if it already existed then I can skip downloading and adding it again.



      Example 1 (--fetch-keys):



       sudo apt-key adv --fetch-keys https://packages.microsoft.com/keys/microsoft.asc
      sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null <<- END
      deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main
      END


      Example 2 (--recv-keys):



       sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B9A06DE3
      sudo tee /etc/apt/sources.list.d/inkscape.list > /dev/null <<- END
      deb [arch=amd64] http://ppa.launchpad.net/inkscape.dev/stable-daily/ubuntu bionic main
      END









      share|improve this question














      So basically, I want to run these 2 commands but I want to check if the keys already existed. I know how to do the ifthenelse in bash but I'm not sure how to get the result and store in variable for me to check so that i can put it in the conditional operator. For example, if it already existed then I can skip downloading and adding it again.



      Example 1 (--fetch-keys):



       sudo apt-key adv --fetch-keys https://packages.microsoft.com/keys/microsoft.asc
      sudo tee /etc/apt/sources.list.d/vscode.list > /dev/null <<- END
      deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main
      END


      Example 2 (--recv-keys):



       sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B9A06DE3
      sudo tee /etc/apt/sources.list.d/inkscape.list > /dev/null <<- END
      deb [arch=amd64] http://ppa.launchpad.net/inkscape.dev/stable-daily/ubuntu bionic main
      END






      bash gnupg keys






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 25 at 7:35









      sudorangersudoranger

      335 bronze badges




      335 bronze badges























          1 Answer
          1






          active

          oldest

          votes


















          1



















          How about something like:



          TEST=$(apt-key list 2> /dev/null | grep my_app_name)
          if [[ ! $TEST ]]; then
          echo "Missing - need to run --fetch-keys or --recv-keys"
          fi


          I piped stderr into the null device ( 2> /dev/null ) to hide the warning you get for using apt-key list in a script.



          Try running "sudo apt-key list" on its own so you can see what the output looks like, in case you want to change the "grep" to be more selective.






          share|improve this answer



























          • Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

            – sudoranger
            Sep 26 at 1:47







          • 1





            Thanks for the question. I should have used apt-key list in my example. I've just modified it.

            – Eric Mintz
            Sep 26 at 10:25











          • I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

            – sudoranger
            Sep 27 at 6:43













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1176504%2fhow-to-check-if-gpg-key-already-exist-with-bash-then-skip-downloading-adding%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown


























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1



















          How about something like:



          TEST=$(apt-key list 2> /dev/null | grep my_app_name)
          if [[ ! $TEST ]]; then
          echo "Missing - need to run --fetch-keys or --recv-keys"
          fi


          I piped stderr into the null device ( 2> /dev/null ) to hide the warning you get for using apt-key list in a script.



          Try running "sudo apt-key list" on its own so you can see what the output looks like, in case you want to change the "grep" to be more selective.






          share|improve this answer



























          • Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

            – sudoranger
            Sep 26 at 1:47







          • 1





            Thanks for the question. I should have used apt-key list in my example. I've just modified it.

            – Eric Mintz
            Sep 26 at 10:25











          • I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

            – sudoranger
            Sep 27 at 6:43
















          1



















          How about something like:



          TEST=$(apt-key list 2> /dev/null | grep my_app_name)
          if [[ ! $TEST ]]; then
          echo "Missing - need to run --fetch-keys or --recv-keys"
          fi


          I piped stderr into the null device ( 2> /dev/null ) to hide the warning you get for using apt-key list in a script.



          Try running "sudo apt-key list" on its own so you can see what the output looks like, in case you want to change the "grep" to be more selective.






          share|improve this answer



























          • Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

            – sudoranger
            Sep 26 at 1:47







          • 1





            Thanks for the question. I should have used apt-key list in my example. I've just modified it.

            – Eric Mintz
            Sep 26 at 10:25











          • I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

            – sudoranger
            Sep 27 at 6:43














          1















          1











          1









          How about something like:



          TEST=$(apt-key list 2> /dev/null | grep my_app_name)
          if [[ ! $TEST ]]; then
          echo "Missing - need to run --fetch-keys or --recv-keys"
          fi


          I piped stderr into the null device ( 2> /dev/null ) to hide the warning you get for using apt-key list in a script.



          Try running "sudo apt-key list" on its own so you can see what the output looks like, in case you want to change the "grep" to be more selective.






          share|improve this answer
















          How about something like:



          TEST=$(apt-key list 2> /dev/null | grep my_app_name)
          if [[ ! $TEST ]]; then
          echo "Missing - need to run --fetch-keys or --recv-keys"
          fi


          I piped stderr into the null device ( 2> /dev/null ) to hide the warning you get for using apt-key list in a script.



          Try running "sudo apt-key list" on its own so you can see what the output looks like, in case you want to change the "grep" to be more selective.







          share|improve this answer















          share|improve this answer




          share|improve this answer








          edited Sep 27 at 10:37

























          answered Sep 25 at 9:27









          Eric MintzEric Mintz

          1,4435 silver badges18 bronze badges




          1,4435 silver badges18 bronze badges















          • Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

            – sudoranger
            Sep 26 at 1:47







          • 1





            Thanks for the question. I should have used apt-key list in my example. I've just modified it.

            – Eric Mintz
            Sep 26 at 10:25











          • I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

            – sudoranger
            Sep 27 at 6:43


















          • Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

            – sudoranger
            Sep 26 at 1:47







          • 1





            Thanks for the question. I should have used apt-key list in my example. I've just modified it.

            – Eric Mintz
            Sep 26 at 10:25











          • I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

            – sudoranger
            Sep 27 at 6:43

















          Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

          – sudoranger
          Sep 26 at 1:47






          Hi there, gpg list gives me different output than the keys i have added using apt-key can you confirm? Are they using the same “keyring” mechanism?

          – sudoranger
          Sep 26 at 1:47





          1




          1





          Thanks for the question. I should have used apt-key list in my example. I've just modified it.

          – Eric Mintz
          Sep 26 at 10:25





          Thanks for the question. I should have used apt-key list in my example. I've just modified it.

          – Eric Mintz
          Sep 26 at 10:25













          I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

          – sudoranger
          Sep 27 at 6:43






          I've accepted your answer. It should work now. I can use the subshell to check if one of my keys are matching the one that already existed on the machine, thus skipping them. Thank you so much!

          – sudoranger
          Sep 27 at 6:43



















          draft saved

          draft discarded















































          Thanks for contributing an answer to Ask Ubuntu!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1176504%2fhow-to-check-if-gpg-key-already-exist-with-bash-then-skip-downloading-adding%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown









          Popular posts from this blog

          Tamil (spriik) Luke uk diar | Nawigatjuun

          Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

          Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?