Using scripts to add GPG Keys and Repository Lists
sudo
is a command one normally doesn’t use in scripts (see How do I run a 'sudo' command inside a script?), you rather run the whole script as root. Your script would then be
#!/bin/bash
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | apt-key add -
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" >>/etc/apt/sources.list.d/elastic-6.x.list
and you should make it executable with chmod +x /path/to/script
and run it with:
sudo /path/to/script
Related videos on Youtube
![robz](https://lh4.googleusercontent.com/-UBPZkWFMMDc/AAAAAAAAAAI/AAAAAAAAAQU/8EnVH9mr8JM/photo.jpg?sz=256)
robz
Updated on September 18, 2022Comments
-
robz almost 2 years
I am in need of installing elasticstack on multiple systems currently and would like to invoke this via bash script. Two of the steps to installing elasticsearch is to add the GPG Key and then create a
sources.list
file for the repository.When running this manually in terminal these commands are piped as follows:
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add - echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list
when attempting to create the script for this action it seems to just hang. I am assuming that this is due to the command pipes. So my question would be how can I add these lines into a bash script so that I am able to run this without any issue?