Skip to content
Permalink
Browse files

Prepare cleanup operation for AWS

  • Loading branch information...
NEMS Linux
NEMS Linux committed Aug 24, 2019
1 parent 8efa216 commit 2da05dd0986d9adf7a01bab10fdec24cedc83508
Showing with 25 additions and 18 deletions.
  1. +25 −18 nems-cleanup.sh
@@ -31,14 +31,18 @@ else

platform=$(/usr/local/share/nems/nems-scripts/info.sh platform)

# Check if nemsadmin exists, and create it if not
if [ ! -d /home/nemsadmin ]; then
# Create the nemsadmin user
/root/nems/nems-admin/build/030-user
if (( $platform != 22 )); then
# Check if nemsadmin exists, and create it if not
if [ ! -d /home/nemsadmin ]; then
# Create the nemsadmin user
/root/nems/nems-admin/build/030-user
fi
fi

# Reset the RPi-Monitor users
cp /root/nems/nems-migrator/data/rpimonitor/daemon.conf /etc/rpimonitor
if (( $platform >= 0 )) && (( $platform <= 9 )); then
# Reset the RPi-Monitor users
cp /root/nems/nems-migrator/data/rpimonitor/daemon.conf /etc/rpimonitor
fi

# Reset Samba users
cp /root/nems/nems-migrator/data/samba/smb.conf /etc/samba
@@ -54,12 +58,12 @@ else
fi

sync

echo "Did you cp the database? This script will restore from Migrator. CTRL-C to abort."
sleep 5

ver=$(/usr/local/bin/nems-info nemsver)

# Stop services which may be using these files
systemctl stop webmin
systemctl stop rpimonitor
@@ -113,17 +117,17 @@ else
rm /var/webmin/miniserv.log
rm /var/webmin/miniserv.error
rm /var/webmin/sessiondb.pag

# Clear RPi-Monitor history and stats
rm /usr/share/rpimonitor/web/stat/*.rrd

# Clear Monitorix history, stats and config
echo "" > /etc/monitorix/conf.d/nems.conf
rm /var/lib/monitorix/*.rrd
rm /var/log/monitorix*
rm /var/lib/monitorix/www/imgs/*.png
rm /var/lib/monitorix/usage/*

cd /root
rm .nano_history
rm .bash_history
@@ -135,8 +139,9 @@ else
rm /var/log/lastlog
touch /var/log/lastlog

# Remove DNS Resolver config (will be auto-generated on first boot)
echo "# Default resolv.conf file created by NEMS Admin
if (( $platform != 22 )); then
# Remove DNS Resolver config (will be auto-generated on first boot)
echo "# Default resolv.conf file created by NEMS Admin
# Cloudflare
nameserver 1.1.1.1
@@ -150,16 +155,18 @@ nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844
" > /etc/resolv.conf
fi

# remove output from nconf
rm /var/www/nconf/output/*

# Remove NEMS init password file
rm /var/www/htpasswd

# Reset NEMS Log Files
# Remove resize from patches.log
# This will be put back in below for non-applicable platforms such as virtual appliance
/bin/sed -i~ '/PATCH-000002/d' /var/log/nems/patches.log

# Move patches.log so it can persist after clear
mv /var/log/nems/patches.log /tmp
find /var/log/nems/ -name "*" -type f -delete
@@ -180,7 +187,7 @@ nameserver 2001:4860:4860::8844
echo "################################################################################" > /usr/local/nagios/etc/resource.cfg
echo "# Do not edit this file here. Use the NEMS System Settings Tool web interface. #" >> /usr/local/nagios/etc/resource.cfg
echo "################################################################################" >> /usr/local/nagios/etc/resource.cfg
echo "\$USER1$=/usr/local/nagios/libexec" >> /usr/local/nagios/etc/resource.cfg
echo "\$USER1$=/usr/lib/nagios/plugins" >> /usr/local/nagios/etc/resource.cfg

# Import default Nagios configs
/root/nems/nems-admin/nems-restore-sample-db.sh
@@ -253,8 +260,8 @@ nameserver 2001:4860:4860::8844
rm -rf /root/scripts
fi

if (( $platform == 20 )); then
# Virtual Appliance does not need to resize the filesystem
if (( $platform == 20 )) || (( $platform == 21 )) || (( $platform == 22 )); then
# Virtual Appliance / Docker / Amazon Web Services does not need to resize the filesystem, so pretend it has already been done
if ! grep -q "PATCH-000002" /var/log/nems/patches.log; then
echo "PATCH-000002" >> /var/log/nems/patches.log
fi
@@ -312,7 +319,7 @@ nameserver 2001:4860:4860::8844

sync

if (( $platform != 20 )); then
if (( $platform != 20 )) && (( $platform != 21 )) && (( $platform != 22 )); then
# Write zeros to unused blocks before halting to create the img
echo "Filling empty space with zeros..."
dd if=/dev/zero bs=1M of=/root/.null && sync

0 comments on commit 2da05dd

Please sign in to comment.
You can’t perform that action at this time.