Created
October 21, 2016 14:41
-
-
Save ssmythe/0ec6b1ec842d5e1632b6d70c812ad0d1 to your computer and use it in GitHub Desktop.
install-nexus3-oss-centos6.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## Instructions based on https://books.sonatype.com/nexus-book/reference3/install.html | |
## Oracle JDK | |
JDK_RPM_VERSION=8u102 | |
JDK_BUILD=14 | |
JDK_ARCH=x64 | |
## Version 3 - supports Docker NuGet npm Bower | |
NEXUS_DEPLOY_VERSION=3.0.2 | |
NEXUS_PACKAGE_SUFFIX=unix | |
NEXUS_PATCH_LEVEL=02 | |
NEXUS_DOWNLOAD_URL=http://download.sonatype.com/nexus/3 | |
# | |
# ORACLE SERVER JRE | |
# | |
echo "nexus: install Oracle JRE" | |
cd /tmp | |
curl -L -O -H "Cookie: oraclelicense=accept-securebackup-cookie" -k http://download.oracle.com/otn-pub/java/jdk/${JDK_RPM_VERSION}-b${JDK_BUILD}/jdk-${JDK_RPM_VERSION}-linux-${JDK_ARCH}.rpm | |
yum -y localinstall jdk-${JDK_RPM_VERSION}-linux-${JDK_ARCH}.rpm | |
rm -f jdk-${JDK_RPM_VERSION}-linux-${JDK_ARCH}.rpm | |
# | |
# DOWNLOAD NEXUS | |
# | |
if [ ! -h /app/nexus/nexus ]; then | |
echo "nexus: installing Nexus" | |
# Add nexus user | |
if [ `grep -c "^nexus:" /etc/passwd` -eq 0 ]; then | |
echo "nexus: creating nexus user" | |
/usr/sbin/groupadd nexus | |
/usr/sbin/useradd -g nexus -c "nexus Server" nexus | |
chage -I -1 -m 7 -M -1 -E -1 nexus | |
chown nexus:nexus /home/nexus | |
chmod 0755 /home/nexus | |
if [ ! `grep -q '^#includedir /etc/sudoers.d' /etc/sudoers` ]; then | |
mkdir -p /etc/sudoers.d | |
chmod 0750 /etc/sudoers.d | |
echo '#includedir /etc/sudoers.d' >> /etc/sudoers | |
fi | |
if [ ! -f /etc/sudoers.d/nexus ]; then | |
echo "nexus ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/nexus | |
chmod 0440 /etc/sudoers.d/nexus | |
fi | |
if [ ! `grep -q '^NEXUS_HOME=' /home/nexus/.bashrc` ]; then | |
echo 'NEXUS_HOME="/app/nexus/nexus"' >> /home/nexus/.bashrc | |
fi | |
fi | |
# Create nexus root | |
if [ ! -d /app/nexus ]; then | |
echo "nexus: creating directory /app/nexus" | |
mkdir -p /app/nexus | |
chown nexus:nexus /app/nexus | |
chmod 700 /app/nexus | |
fi | |
# Create nexus log root | |
if [ ! -d /var/log/nexus ]; then | |
echo "nexus: creating directory /var/log/nexus" | |
mkdir /var/log/nexus | |
chown nexus:nexus /var/log/nexus | |
chmod 700 /var/log/nexus | |
fi | |
# Install createrepo | |
echo "nexus: installing createrepo" | |
yum -y install createrepo | |
# Install wget | |
echo "nexus: installing wget" | |
yum -y install wget | |
# Install nexus | |
echo "nexus: Installing nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-${NEXUS_PACKAGE_SUFFIX}.tar.gz" | |
cd /tmp | |
wget -nv --no-check-certificate ${NEXUS_DOWNLOAD_URL}/nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-${NEXUS_PACKAGE_SUFFIX}.tar.gz | |
mv nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-${NEXUS_PACKAGE_SUFFIX}.tar.gz /app/nexus | |
cd /app/nexus | |
tar xvzf nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-${NEXUS_PACKAGE_SUFFIX}.tar.gz | |
rm -f nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-${NEXUS_PACKAGE_SUFFIX}.tar.gz | |
mkdir sonatype-work | |
chown -R nexus:nexus nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL} sonatype-work | |
rm -f nexus | |
ln -f -s /app/nexus/nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL} nexus | |
ln -f -s /app/nexus/nexus/bin/nexus /etc/init.d/nexus | |
if [ `grep NEXUS_HOME /etc/profile | wc -l` -eq 0 ]; then | |
echo export NEXUS_HOME=/app/nexus/nexus >> /etc/profile | |
fi | |
chmod 755 /etc/init.d/nexus | |
sed -i "s:^run_as_user='':run_as_user='nexus':" /app/nexus/nexus/bin/nexus | |
sed -i 's:^application-port=8081:application-port=8080:' /app/nexus/nexus/etc/org.sonatype.nexus.cfg | |
cd /etc/init.d | |
chkconfig --add nexus | |
chkconfig --levels 345 nexus on | |
# Add nexus alias to hosts | |
if [ `grep 127.0.0.1 /etc/hosts | grep nexus | wc -l` -eq 0 ]; then | |
echo "nexus: Adding nexus alias to /etc/hosts" | |
sed -i -e 's:^127.0.0.1:127.0.0.1 nexus:' /etc/hosts | |
fi | |
# Start nexus | |
echo "nexus: starting Nexus" | |
service nexus start | |
# Verify nexus is running | |
echo "nexus: verifying Nexus is running" | |
sleep 2 | |
COUNTER=0 | |
grep -q 'JettyServer - Running' /app/nexus/nexus/data/log/nexus.log | |
while [[ $? -ne 0 && ${COUNTER} -lt 60 ]]; do | |
sleep 2 | |
let COUNTER+=2 | |
echo "nexus: waiting for Nexus to start... (${COUNTER} seconds so far)" | |
grep -q 'JettyServer - Running' /app/nexus/nexus/data/log/nexus.log | |
done | |
if [[ $(grep -q 'JettyServer - Running' /app/nexus/nexus/data/log/nexus.log) -eq 0 ]]; then | |
echo "nexus: nexus is running" | |
else | |
echo "nexus: ERROR: nexus is NOT running. Something went wrong." | |
exit 1 | |
fi | |
# Check main page is loading | |
echo "nexus: verifying Nexus main page is loading" | |
sleep 2 | |
COUNTER=0 | |
curl -sSL http://localhost:8080 | grep -q "Nexus Repository Manager OSS" | |
while [[ $? -ne 0 && ${COUNTER} -lt 60 ]]; do | |
sleep 2 | |
let COUNTER+=2 | |
echo "nexus: waiting for Nexus main page to load... (${COUNTER} seconds so far)" | |
curl -sSL http://localhost:8080 | grep -q "Nexus Repository Manager" | |
done | |
if [[ $(curl -sSL http://localhost:8080 | grep -q "Nexus Repository Manager") -eq 0 ]]; then | |
echo "nexus: nexus main page is loading" | |
else | |
echo "nexus: ERROR: nexus main page is NOT loading. Something went wrong." | |
exit 1 | |
fi | |
echo "nexus: complete" | |
else | |
echo "nexus: nexus repository already installed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment