-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fed336
commit d0dcde2
Showing
3 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
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
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. |
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
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!" |
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
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 |