/
install_nexus_on_ubuntu.sh
71 lines (54 loc) · 1.83 KB
/
install_nexus_on_ubuntu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Update the package list
sudo apt update -y
# Install OpenJDK 8
sudo apt install -y openjdk-8-jre-headless
# Install net-tools
sudo apt install -y net-tools
# Navigate to the /opt directory
cd /opt
#Latest Nexus Downlad url
download_url="https://download.sonatype.com/nexus/3/latest-unix.tar.gz"
downloaded_file="latest-unix.tar.gz"
# Download Nexus
sudo wget "$download_url"
# Extract Nexus version from the downloaded file name
nexus_version=$(tar tzf "$downloaded_file" | grep -oP 'nexus-3\.\d+\.\d+-\d+' | head -n 1)
# Extract Nexus
sudo tar -zxvf "$downloaded_file"
# Create a Nexus user (modify as needed for password input)
sudo useradd -m -s /bin/bash -U nexus
# Set password for the Nexus user password: nexus123
#Change with your own password
echo "nexus:nexus123" | sudo chpasswd
# Set ownership for Nexus directories (checking if nexus_version is set)
if [ -n "$nexus_version" ]; then
sudo chown -R nexus:nexus "$nexus_version"
sudo chown -R nexus:nexus sonatype-work
else
echo "Failed to determine Nexus version. Check the script and try again."
exit 1
fi
# Edit Nexus runtime configuration (checking if nexus_version is set)
if [ -n "$nexus_version" ]; then
sudo sed -i 's/^run_as_user=.*/run_as_user="nexus"/' "/opt/$nexus_version/bin/nexus.rc"
else
echo "Failed to determine Nexus version. Check the script and try again."
exit 1
fi
# Switch to the Nexus user and start Nexus
sudo su - nexus <<EOF
/opt/$nexus_version/bin/nexus start
EOF
# Wait for 60 seconds to allow Nexus to initialize
echo "Waiting for Nexus to initialize..."
sleep 60
# Check Nexus process status
ps aux | grep nexus
# Check Nexus port status
netstat -lnpt
# Print admin password
echo -e "=========== Admin Password ===========\n"
cat /opt/sonatype-work/nexus3/admin.password
echo -e "\n"
echo -e "=========== Admin Password ==========="