Created
February 22, 2016 23:41
-
-
Save ssmythe/d4377ccb4ac0ff6fc874 to your computer and use it in GitHub Desktop.
Install Nexus OSS for CentOS6
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 | |
NEXUS_DEPLOY_VERSION=2.12.0 | |
NEXUS_PATCH_LEVEL=01 | |
# | |
# JAVA OPENJDK | |
# | |
echo "nexus: install Java OpenJDK" | |
yum -y install java-1.8.0-openjdk | |
echo "nexus: displaying system Java version" | |
java -version | |
# | |
# 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 | |
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 nexus | |
echo "nexus: installing nexus" | |
yum -y install wget | |
cd /tmp | |
wget -nv --no-check-certificate http://www.sonatype.org/downloads/nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-bundle.tar.gz | |
mv nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-bundle.tar.gz /app/nexus | |
cd /app/nexus | |
tar xvzf nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-bundle.tar.gz | |
rm -f nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL}-bundle.tar.gz | |
chown -R nexus:nexus nexus-${NEXUS_DEPLOY_VERSION}-${NEXUS_PATCH_LEVEL} sonatype-work | |
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:^NEXUS_HOME="..":NEXUS_HOME="/app/nexus/nexus":' /etc/init.d/nexus | |
sed -i 's:^#RUN_AS_USER=:RUN_AS_USER=nexus:' /etc/init.d/nexus | |
sed -i 's:^#PIDDIR=".":PIDDIR="/home/nexus":' /etc/init.d/nexus | |
sed -i 's:^application-port=8081:application-port=8080:' /app/nexus/nexus/conf/nexus.properties | |
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 '/^127.0.0.1 / s/$/ 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/logs/wrapper.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/logs/wrapper.log | |
done | |
if [[ $(grep -q 'JettyServer - Running' /app/nexus/nexus/logs/wrapper.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/nexus | 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/nexus | grep -q "Nexus Repository Manager OSS" | |
done | |
if [[ $(curl -sSL http://localhost:8080/nexus | grep -q "Nexus Repository Manager OSS") -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