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

Bash script to install nexus correctly #35

Open
sysadmin-info opened this issue May 14, 2024 · 2 comments
Open

Bash script to install nexus correctly #35

sysadmin-info opened this issue May 14, 2024 · 2 comments

Comments

@sysadmin-info
Copy link

Script requires that the user is in sudoers.

Make the Script Executable

chmod +x setup_nexus.sh

Run the Script with Superuser Privileges

sudo ./setup_nexus.sh

script:

#!/bin/bash
echo "This quick installer script requires root privileges."
echo "Checking..."
if [[ $(/usr/bin/id -u) -ne 0 ]];
then
    echo "Not running as root"
    exit 0
else
	echo "Installation continues"
fi

SUDO=
if [ "$UID" != "0" ]; then
	if [ -e /usr/bin/sudo -o -e /bin/sudo ]; then
		SUDO=sudo
	else
		echo "*** This quick installer script requires root privileges."
		exit 0
	fi
fi

# Install necessary packages
apt install gnupg gnupg1 gnupg2 -y
wget -P /etc/apt/sources.list.d/ https://repo.sonatype.com/repository/community-hosted/deb/sonatype-community.list
sed -i '1i deb [arch=all trusted=yes] https://repo.sonatype.com/repository/community-apt-hosted/ bionic main' /etc/apt/sources.list.d/sonatype-community.list
sed -i '2s/^/#/' /etc/apt/sources.list.d/sonatype-community.list
wget -q -O - https://repo.sonatype.com/repository/community-hosted/pki/deb-gpg/DEB-GPG-KEY-Sonatype.asc | sudo apt-key add -
apt update && sudo apt install nexus-repository-manager -y

# Stop the Nexus Repository Manager service
systemctl stop nexus-repository-manager.service

# Install Java JDK 8 update 412
wget https://download.bell-sw.com/java/8u412+9/bellsoft-jdk8u412+9-linux-amd64.deb
dpkg -i bellsoft-jdk8u412+9-linux-amd64.deb
apt --fix-broken install -y
dpkg -i bellsoft-jdk8u412+9-linux-amd64.deb

# Set correct ownership and permissions
chown -R nexus3:nexus3 /opt/sonatype
chmod -R 750 /opt/sonatype

# Start the Nexus Repository Manager service
systemctl start nexus-repository-manager.service

# Install curl
apt install curl -y

# Extract the first IP address from `hostname -I` and store it in a variable
IP_ADDRESS=$(hostname -I | awk '{print $1}')

echo "sleep 120 seconds ..."
sleep 120

# Use the IP address variable
echo "The IP address is: $IP_ADDRESS"
curl http://$IP_ADDRESS:8081

# Stop the Nexus Repository Manager service
systemctl stop nexus-repository-manager.service

# Execute OrientDB console commands using a here document
java -jar /opt/sonatype/nexus3/lib/support/nexus-orient-console.jar <<EOF
connect plocal:/opt/sonatype/sonatype-work/nexus3/db/security admin admin
select * from user where id = "admin"
update user SET password="\$shiro1\$SHA-512\$1024\$NE+wqQq/TmjZMvfI7ENh/g==\$V4yPw8T64UQ6GfJfxYq2hLsVrBY8D1v+bktfOxGdt4b/9BthpWPNUy/CBk6V9iA0nHpzYzJFWO8v/tZFtES8CA==" UPSERT WHERE id="admin"
exit
EOF

# Set correct ownership and permissions
chown -R nexus3:nexus3 /opt/sonatype
chmod -R 750 /opt/sonatype

# Start the Nexus Repository Manager service
systemctl start nexus-repository-manager.service

# Check logs with the below command:
#sudo tail -f /opt/sonatype/sonatype-work/nexus3/log/nexus.log
@sysadmin-info
Copy link
Author

I added it to my own repository: sysadmin-nexus

@sysadmin-info
Copy link
Author

My tutorial, so you can see how it works in Debian 12.
YouTube Nexus installation via Bash script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant