Moved some scripts to a VPS directory
This commit is contained in:
parent
4bcec25c2e
commit
7be8a13889
4 changed files with 2 additions and 16 deletions
61
VPS/AptUpdateWatcher.sh
Executable file
61
VPS/AptUpdateWatcher.sh
Executable file
|
@ -0,0 +1,61 @@
|
|||
#! /bin/bash
|
||||
|
||||
# This script updates the apt database if running as root and retrieves the number of upgradable packages.
|
||||
# If the count is high enough or if some important packages can be upgraded, inform the administrator.
|
||||
|
||||
|
||||
while getopts ":c:p:h" option; do
|
||||
case ${option} in
|
||||
c )
|
||||
trigger_count=$OPTARG
|
||||
;;
|
||||
p )
|
||||
# Add each matching option to the array
|
||||
key_packages+=("$OPTARG")
|
||||
;;
|
||||
h | \? | : )
|
||||
echo "Usage : AptUpdateWatcher [-c count] [-p package matching regex] [-h] [-?]"
|
||||
echo " -c : Change the minimum count of upgradable packages before sending a warning"
|
||||
echo " -p : Add an expression to watch for important packages. If a package matching this option is found, send a warning"
|
||||
echo " -h/-? : Prints this message"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Use default options if nothing provided
|
||||
|
||||
if [ -z "$trigger_count" ]; then
|
||||
trigger_count=20
|
||||
fi
|
||||
|
||||
if [ -z "$key_packages" ]; then
|
||||
key_packages=( "ssh" "ssl" "apache" "kernel" )
|
||||
fi
|
||||
|
||||
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
apt-get update
|
||||
fi
|
||||
|
||||
upgradable_packages="$(apt-get -s -V upgrade | grep -e'=>')"
|
||||
upgradable_count=$(echo "$upgradable_packages" | wc -l)
|
||||
|
||||
if [ $upgradable_count -gt $trigger_count ]; then
|
||||
output="There are more than $trigger_count packages ready to upgrade ($upgradable_count packages):\n"
|
||||
output+="$upgradable_packages\n\n"
|
||||
fi
|
||||
|
||||
for expression in "${key_packages[@]}"; do
|
||||
matching_packages=$(echo "$upgradable_packages" | grep -e"$expression")
|
||||
if [ -n "$matching_packages" ]; then
|
||||
output+="Packages matching the expression '""$expression""' can be upgraded: \n"
|
||||
output+="$matching_packages\n\n"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$output" ]; then
|
||||
output="The Apt Update Watcher has been triggered.\n\n""$output"
|
||||
|
||||
echo -e "$output" # Can be replaced by anything or piped into sendmail
|
||||
fi
|
63
VPS/package_save.sh
Executable file
63
VPS/package_save.sh
Executable file
|
@ -0,0 +1,63 @@
|
|||
#! /bin/bash
|
||||
|
||||
name=packages_state
|
||||
location="$HOME/SYS_SAVES/"
|
||||
|
||||
if [ $# -ne 0 ]; then
|
||||
if [ ! -z "$1" -a "$1" != "here" ]; then
|
||||
name=$1
|
||||
fi
|
||||
if [ "$2" = here -o "$1" = here ]; then
|
||||
location="."
|
||||
elif [ ! -z "$2" ]; then
|
||||
echo "Second argument can be void or 'here' only"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
cd $location
|
||||
pathName="$name""_$(date +'%Y-%m-%d @ %Hh%M')"
|
||||
|
||||
mkdir "$pathName"
|
||||
cd "./$pathName"
|
||||
mkdir "./preferences.d"
|
||||
|
||||
cp /etc/apt/sources.list .
|
||||
cp /etc/apt/preferences.d/my_preferences ./preferences.d/
|
||||
cp -r --copy-contents /etc/apt/sources.list.d .
|
||||
|
||||
sudo dpkg --get-selections > "manual_package_save"
|
||||
|
||||
a=C4.sh
|
||||
|
||||
echo "#! /bin/bash" > $a
|
||||
echo "" >> $a
|
||||
echo "cd .." >> $a
|
||||
echo "rm -r \"$pathName\"" >> $a
|
||||
|
||||
chmod u+x "$a"
|
||||
|
||||
b="package_restore.sh"
|
||||
|
||||
echo "#! /bin/bash" > $b
|
||||
echo "" >> $b
|
||||
echo 'if [ $(id -u) -ne "0" ]; then' >> $b
|
||||
echo ' echo "Please execute with superuser privileges"' >> $b
|
||||
echo " exit -1" >> $b
|
||||
echo fi >> $b
|
||||
echo "" >> $b
|
||||
echo cp ./sources.list /etc/apt/sources.list >> $b
|
||||
echo cp ./preferences.d/my_preferences /etc/apt/preferences.d/my_preferences >> $b
|
||||
echo 'cp -r ./sources.list.d/* /etc/apt/sources.list.d' >> $b
|
||||
echo "" >> $b
|
||||
echo apt-get update >> $b
|
||||
echo apt-get install dselect >> $b
|
||||
echo "dpkg --set-selections < "manual_package_save"" >> $b
|
||||
echo apt-get dselect-upgrade >> $b
|
||||
echo apt-get remove dselect >> $b
|
||||
|
||||
chmod u-x "$b"
|
||||
|
||||
cd -
|
||||
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue