Skip to content

Instantly share code, notes, and snippets.

@chetanppatil
Last active December 28, 2023 04:31
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 22 You must be signed in to fork a gist
  • Save chetanppatil/85e80d2a17c4d2d75172bf378efe93b9 to your computer and use it in GitHub Desktop.
Save chetanppatil/85e80d2a17c4d2d75172bf378efe93b9 to your computer and use it in GitHub Desktop.
Install sonar-scanner in linux mint, ubuntu...
#!/bin/bash
cd /tmp || exit
echo "Downloading sonar-scanner....."
if [ -d "/tmp/sonar-scanner-cli-4.7.0.2747-linux.zip" ];then
sudo rm /tmp/sonar-scanner-cli-4.7.0.2747-linux.zip
fi
wget -q https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
echo "Download completed."
echo "Unziping downloaded file..."
unzip sonar-scanner-cli-4.7.0.2747-linux.zip
echo "Unzip completed."
rm sonar-scanner-cli-4.7.0.2747-linux.zip
echo "Installing to opt..."
if [ -d "/var/opt/sonar-scanner-4.7.0.2747-linux" ];then
sudo rm -rf /var/opt/sonar-scanner-4.7.0.2747-linux
fi
sudo mv sonar-scanner-4.7.0.2747-linux /var/opt
echo "Installation completed successfully."
echo "You can use sonar-scanner!"
@rizrepos
Copy link

rizrepos commented Oct 8, 2019

@emersonbatista
Copy link

emersonbatista commented Dec 16, 2022

echo "Creating links"
ln -s /var/opt/sonar-scanner-4.7.0.2747-linux/bin/sonar-scanner /usr/local/bin/

echo "path sonar-scanner: "
which sonar-scanner

@miniGweek
Copy link

Great script! Thanks

Here's an improved version.

Usage : ./sonar-installer.sh sonar-scanner-cli-5.0.1.3006-linux.zip

#!/bin/bash -e
if [ $# -eq 0 ]; then
    >&2 echo "Sonar scanner cli binary package not supplied."
    exit 1
fi

echo "Chosen sonar scanner cli binary package is: $1"

SONAR_CLI_BINARY_BASE_URL="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli"

echo "Sonar Cli Binary Download Url is $SONAR_CLI_BINARY_BASE_URL/$1"

cd /tmp || exit
echo "Downloading sonar-scanner....."
if [ -d "/tmp/$1" ];then
    echo "Removing existing directory /tmp/$1"
    sudo rm /tmp/$1
fi

echo "Downloading sonar cli binary from $SONAR_CLI_BINARY_BASE_URL/$1"

wget -q "$SONAR_CLI_BINARY_BASE_URL/$1"

echo "Download completed."

SONAR_CLI_FOLDER_NAME=$(unzip -Z -1 $1 | head -1 | grep -oP '.*(?=/)')
echo "Unziping downloaded file..."
unzip $1
echo "Unzip completed. Zip contents are in the folder $SONAR_CLI_FOLDER_NAME"

rm $1
echo "Removed zip file $1"

echo "Installing to opt..."
if [ -d "/var/opt/$SONAR_CLI_FOLDER_NAME" ];then
    sudo rm -rf /var/opt/$SONAR_CLI_FOLDER_NAME
    echo "Removed existing sonar cli folder /var/opt/$SONAR_CLI_FOLDER_NAME"
fi
sudo mv /tmp/$SONAR_CLI_FOLDER_NAME /var/opt

echo "Installation completed successfully."

echo "You can use sonar-scanner!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment