Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Flightkick committed Aug 12, 2015
1 parent 2fed336 commit d0dcde2
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,34 @@
# lin-remoteupdate
Scripts for automatically updating a remote Linux server over SSH.
These scripts can update multiple remote Linux machines over SSH.

## Prerequisites
The scripts require sshpass (http://sourceforge.net/projects/sshpass/).
```
Ubuntu/Debian: apt-get install sshpass
Fedora/CentOS: yum install sshpass
Arch: pacman -S sshpass
```

## Usage instructions
1. Download the files to your Linux computer (not the server)
2. Install the prerequisites (see above)
2. Enable file execution permissions on local.sh if applicable
3. Open a terminal and run local.sh
4. Enter the IP's/Hostnames of the servers you would like to update, seperated by a semicolon (;)
5. Enter a sudoers account name
6. Enter the specified account's password
7. Choose the mode to run in:
* 1 = Auto restart when required
* 2 = Promt if restart is required
* 3 = Ignore (do not restart)
8. Profit!

## What does it do?
The local script opens a SSH tunnel to the remote server and does the following:
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y
sudo apt-get clean

After that the script will check if the machine requires a reboot, depending on your choices when running local.sh it will either automatically restart, prompt for restart or ignore the restart.
53 changes: 53 additions & 0 deletions local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash
hostReachable=0;
IFS=";"
while [ "$hostReachable" -eq 0 ]; do
echo "Please enter the IP/Hostname of the server you would like to update. You can enter multiple hosts semicolon (;) separated:"
read hostlist
for host in $hostlist
do
if ! ping -c 1 "$host" &> /dev/null
then
echo "ERROR: The specified IP/Hostname ($host) is unreachable."
hostReachable=0;
break
else
hostReachable=1;
fi
done
done

echo "Please enter the account name you would like to log in with:"
read user

echo "Please enter the password for the specified user account:"
read -s -p Password: pass
echo

echo "When new updates have been installed a server might need a restart, you can run this updater in various modes:"
echo "1 = Automatically reboot when needed"
echo "2 = Ask me if I would like to reboot"
echo "3 = Automatically ignore the need to reboot"
echo
echo "Please choose the mode you would like to run. (1, 2, 3):"

rebootBool=0;
while [ $rebootBool -eq 0 ]; do
read rebootInt
if [ "$rebootInt" == "1" ] || [ "$rebootInt" == "2" ] || [ "$rebootInt" == "3" ]; then
rebootBool=1;
else
echo "No valid response. (1, 2, 3):"
fi
done

echo "Starting routine..."
echo

for host in $hostlist
do
sshpass -p "$pass" ssh "$host" -l "$user" -o StrictHostKeyChecking=no "bash -s $pass $rebootInt $host" < remote.sh
done

echo
echo "Script finished!"
35 changes: 35 additions & 0 deletions remote.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
echo "$1" | sudo -S apt-get update -y
echo "$1" | sudo -S apt-get upgrade -y
echo "$1" | sudo -S apt-get dist-upgrade -y
echo "$1" | sudo -S apt-get autoremove -y
echo "$1" | sudo -S apt-get clean
if [ -f /var/run/reboot-required ]; then
if [ "$2" -eq 1 ]; then
echo "Autoreboot enabled, will reboot now."
echo "$1" | sudo -S reboot
elif [ "$2" -eq 2 ]; then
rebootBool=0;
while [ $rebootBool -eq 0 ]; do
echo "The newly installed updates require the server to be rebooted, do you wish to reboot this server ($3) now? (yes/no):"
read reboot

if [ "$reboot" == "yes" ] || [ "$reboot" == "y" ]; then
rebootBool=1;
echo "$1" | sudo -S reboot
elif [ "$reboot" == "no" ] || [ "$reboot" == "n" ]; then
rebootBool=1;
echo
echo "Updates installed but might not be applied until a reboot takes place."
else
echo
echo "$reboot is not a valid response."
fi
done
elif [ "$2" -eq 3 ]; then
echo "Autoignore enabled, will ignore reboot."
echo "Updates installed but might not be applied until a reboot takes place."
fi
else
echo "Reboot not required"
fi

0 comments on commit d0dcde2

Please sign in to comment.