#!/bin/bash
########################################################################################################### Author: Sysadmin ## mail: admin@sysadmin.info.pl ## Use freely ## Key Points: ## 1. **Root Privileges Check**: The script verifies if it's being run as root. ## 2. **Package Installation**: It installs necessary packages, including `gnupg` and `curl`. ## 3. **Nexus Repository Installation**: Downloads and installs Nexus Repository Manager. ## 4. **Java Installation**: Downloads and installs the specified Java version. ## 5. **Permissions**: Sets the correct ownership and permissions for Nexus directories. ## 6. **Service Management**: Stops and starts the Nexus service at appropriate points. ## 7. **OrientDB Console Commands**: Connects to the OrientDB console to update the admin password. ## 8. **Validation**: Uses `curl` to check if the Nexus service is running and accessible. ## This script covers the installation and setup process comprehensively, ## including handling dependencies and setting up the necessary environment for Nexus Repository Manager. ###########################################################################################################echo"This quick installer script requires root privileges."echo"Checking..."if[[$(/usr/bin/id -u) -ne 0]];thenecho"Not running as root"exit0elseecho"Installation continues"fiSUDO=if["$UID" !="0"];thenif[ -e /usr/bin/sudo -o -e /bin/sudo ];thenSUDO=sudo
elseecho"*** This quick installer script requires root privileges."exit0fifi# Install necessary packagesapt 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 | apt-key add -
apt update && apt install nexus-repository-manager -y
# Stop the Nexus Repository Manager servicesystemctl stop nexus-repository-manager.service
# Install Java JDK 8 update 412wget 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 permissionschown -R nexus3:nexus3 /opt/sonatype
chmod -R 750 /opt/sonatype
# Start the Nexus Repository Manager servicesystemctl start nexus-repository-manager.service
# Install curlapt install curl -y
# Extract the first IP address from `hostname -I` and store it in a variableIP_ADDRESS=$(hostname -I | awk '{print $1}')echo"sleep 120 seconds ..."sleep 120# Use the IP address variableecho"The IP address is: $IP_ADDRESS"curl http://$IP_ADDRESS:8081
# Stop the Nexus Repository Manager servicesystemctl stop nexus-repository-manager.service
# Execute OrientDB console commands using a here documentjava -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 permissionschown -R nexus3:nexus3 /opt/sonatype
chmod -R 750 /opt/sonatype
# Start the Nexus Repository Manager servicesystemctl start nexus-repository-manager.service
# Check logs with the below command:# sudo tail -f /opt/sonatype/sonatype-work/nexus3/log/nexus.log
Removal Script: remove_nexus.sh
This script automates the uninstallation and cleanup of the Nexus Repository Manager and the Java environment on Debian 11 and 12.
What the Script Does:
Root Privileges Check: Ensures the script is being run with root privileges.
Stop Nexus Service: Stops the Nexus service if it is running.
Disable Nexus Service: Disables the Nexus service to prevent it from starting on boot.
Remove Pre-removal Script: Manually removes the problematic pre-removal script to avoid errors during uninstallation.
Force Remove Nexus Package: Forces the removal of the Nexus package.
Remove Nexus Directories: Deletes all directories and files related to Nexus.
Remove Java Packages: Removes BellSoft Java and Temurin JDK 8 packages if they are installed.
Remove Residual Configurations: Removes any remaining configuration files for Java packages.
Clean Up Dependencies: Removes unused dependencies and cleans up package manager files.
Remove Nexus User and Group: Optionally removes the user and group created for Nexus.
Final Cleanup: Ensures that all configuration files are purged.
Verify Removal: Checks and lists any remaining Nexus and Java packages to verify complete removal.
#!/bin/bash
echo"This uninstaller script requires root privileges."echo"Checking..."if[[$(/usr/bin/id -u) -ne 0]];thenecho"Not running as root"exit0elseecho"Uninstallation continues"fi# Stop the Nexus Repository Manager service if it existsif systemctl is-active --quiet nexus-repository-manager.service;then systemctl stop nexus-repository-manager.service
fi# Disable the Nexus Repository Manager service if it existsif systemctl is-enabled --quiet nexus-repository-manager.service;then systemctl disable nexus-repository-manager.service
fi# Manually remove the problematic pre-removal script of nexus-repository-managerif[ -e /var/lib/dpkg/info/nexus-repository-manager.prerm ];then mv /var/lib/dpkg/info/nexus-repository-manager.prerm /var/lib/dpkg/info/nexus-repository-manager.prerm.bak
fi# Force remove Nexus Repository Manager packagedpkg --remove --force-remove-reinstreq nexus-repository-manager
# Remove Nexus directoriesrm -rf /
opt/sonatype
rm -f /etc/systemd/system/nexus-repository-manager.service
rm -f /etc/apt/sources.list.d/sonatype-community.list
rm -rf /var/cache/apt/archives/nexus-repository-manager_*.deb
rm -rf /usr/share/doc/nexus-repository-manager
# Remove BellSoft Java package if installedif dpkg -l | grep -q bellsoft-java8;then dpkg --purge bellsoft-java8 ||truefi# Remove Temurin JDK 8 package if installedif dpkg -l | grep -q temurin-8-jdk;then apt remove --purge temurin-8-jdk -y ||truefi# Remove residual configuration filesdpkg --purge ca-certificates-java java-common
# Clean up unused dependenciesapt autoremove -y
# Clean up any remaining configuration filesapt clean
echo"Uninstallation completed."# Optionally remove user and group created for Nexusif id -u nexus3 >/dev/null 2>&1;then userdel nexus3
fiif getent group nexus3 >/dev/null 2>&1;then groupdel nexus3
fi# Remove any remaining configuration filesdpkg --purge nexus-repository-manager ca-certificates-java java-common
# Verify the removalecho"Verifying the removal of Nexus and Java packages..."dpkg -l | grep nexus
dpkg -l | grep java
Accessing Nexus and Setting Up an NPM Proxy Repository
Access Nexus Repository Manager
Open Nexus in Your Browser:
Open your preferred web browser.
In the address bar, type http://<IP_ADDRESS>:8081 and press Enter. Replace <IP_ADDRESS> with the actual IP address of your Nexus server.
Example:
1
http://192.168.1.100:8081
Log in to Nexus:
On the login page, use the default credentials:
Username:admin
Password:admin123
Click on the Sign In button.
Change the Admin Password
Change the Admin Password:
After logging in, click on the user icon in the top-right corner of the interface.
Select Change Password from the dropdown menu.
Enter the current password (admin123) and then enter and confirm your new password.
Click on the Save button to apply the changes.
Disable Anonymous Access
Disable Anonymous Access:
From the left-hand sidebar, navigate to Security -> Anonymous Access.
Uncheck the Allow anonymous users to access the server option.
Click Save to apply the changes.
Log out and Log in with the New Password:
Click on the user icon in the top-right corner again.
Select Sign Out from the dropdown menu.
Log back in using the new admin password you set in the previous step.
Set Up an NPM Proxy Repository
Set Up an NPM Proxy Repository:
From the left-hand sidebar, navigate to Repositories.
Click on the Create repository button.
Select npm (proxy) from the list of repository types.
Configure the NPM Proxy Repository:
In the Name field, enter a meaningful name for your repository (e.g., npm-proxy).
In the Remote storage field, enter the URL of the NPM registry:
1
http://registry.npmjs.org
Adjust other settings as needed (e.g., Blob store, Strict Content Validation).
Save the Repository Configuration:
Scroll to the bottom of the configuration page and click the Create repository button to save the new NPM proxy repository.
Verification
Verify the Repository:
Navigate to the Repositories section to ensure your new NPM proxy repository is listed and active.
Summary of Commands and Configuration
Login to Nexus:
1
http://<IP_ADDRESS>:8081
Default Credentials:
1
2
Username: admin
Password: admin123
NPM Registry URL for Proxy Repository:
1
http://registry.npmjs.org
By following these steps, you should have successfully accessed Nexus Repository Manager, changed the admin password, disabled anonymous access, and set up an NPM proxy repository. You are now ready to manage your NPM packages through Nexus!
This tutorial covers the full lifecycle of installing, configuring, and removing the Nexus Repository Manager and Java on Debian 11 and 12, as well as setting up and securing your Nexus environment.