Skip to content

Commit

Permalink
Release 1.4.0-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Dec 7, 2016
1 parent 01d20d0 commit 9129c72
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
9 changes: 9 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
small-cleanup-script (1.4.0-1) unstable; urgency=medium

* Changed Messages
* Replaced realpath with readlink
* Use "snap refresh"
* Added "set -e"

-- Maciej Krüger <[email protected]> Wed, 07 Dec 2016 15:42:52 +0100

small-cleanup-script (1.3.0-1) unstable; urgency=medium

* Fixed some bugs
Expand Down
46 changes: 34 additions & 12 deletions script.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
#!/bin/sh
#!/bin/bash

red=$(tput setaf 1)
reset=$(tput sgr0)
logfile="/var/log/small-cleanup-script.log"

set -e

log() {
echo "$(tput setaf 1)[CLEAN] $(date) $@$(tput sgr0)"
echo "$red[CLEAN] $(date) $@$reset"
}
logit() {
logger "[small-cleanup-script] $*"
logger "[$$] [small-cleanup-script] $*"
}

if [ $USER != "root" ]; then
if [ "$USER" != "root" ]; then
groups $USER | grep "sudo" -o > /dev/null 2> /dev/null
if [ $? -ne 0 ] && [ "x$1" != "x-f" ]; then
log "You have no permission to run this command!"
log "This was reported"
log "If you think this is an error try -f"
logit "User $USER had no permission to run this script! (arguments: $*)"
arg=""
if ! [ -z "$1" ]; then
arg=" (arguments: $*)"
fi
logit "User $USER had no permission to run this script!$arg"
exit 2
fi
logit "Executed from user $USER with arguments $*"
s="sudo bash `realpath $0` $*"
log "Run as root via sudo... ($s)"
if ! [ -z "$1" ]; then
logit "Executed by user $USER with arguments $*"
s="sudo bash $(readlink -f $0) $*"
else
logit "Executed by user $USER"
s="sudo bash $(readlink -f $0)"
fi
log "Executing $s..."
sudo $s
exit $?
fi

logit "Running script with arguments $*"

if [ "x$1" = "xcron" ]; then
log "Logging to /var/log/small-cleanup-script.log"
if ! [ -e "$logfile" ]; then
touch $logfile
chmod 755 $logfile
chown root:root $logfile
fi
log "Logging to $logfile"
tail -f $logfile -n 0 --pid=$$ &
logit "Running as cronjob"
#Set PATH for cronjob
PATH="$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
#Execute as cronjob
bash `realpath $0` &>> /var/log/small-cleanup-script.log
bash $(readlink -f $0) &>> $logfile
logit "Cronjob finished"
exit $?
fi

#Update and Clean
log "APT-GET UPDATE"
apt-get update > /dev/null
log "APT-GET DISTUPGRADE -Y"
log "APT-GET DIST-UPGRADE -Y"
apt-get dist-upgrade -y
log "APT-GET AUTOREMOVE -Y"
apt-get autoremove -y
Expand All @@ -60,7 +82,7 @@ fi
#Snappy Stuff
if [ -f "/usr/bin/snap" ]; then
log "SNAP REFRESH"
snap list | awk -F" " '{if ($1 && NR>1) { system("snap refresh " $1 " 2> /dev/null") }}'
snap refresh
fi

log "DONE"

0 comments on commit 9129c72

Please sign in to comment.