#!/bin/bash
#################################################
## ##
## auto-update.sh v1.0 ##
## Use this script to set up automatic updates ##
## on your debian/ubuntu box. ##
## ##
#################################################
## Creating /usr/bin/auto-update.sh file
sudo touch /usr/bin/auto-update.sh
sudo chmod 700 /usr/bin/auto-update.sh
sudo chown root:root /usr/bin/auto-update.sh
echo '#!/bin/bash' | sudo tee -a /usr/bin/auto-update.sh
echo 'touch /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'echo '------------------' >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'echo `date` >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin' | sudo tee -a /usr/bin/auto-update.sh
echo 'export PATH' | sudo tee -a /usr/bin/auto-update.sh
echo '/usr/bin/aptitude update >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo '/usr/bin/aptitude -y safe-upgrade >> /var/log/auto-update.log' | sudo tee -a /usr/bin/auto-update.sh
echo 'exit' | sudo tee -a /usr/bin/auto-update.sh
# Creating a cron job for root user (it will run /usr/bin/auto-update.sh every day at 14:30)
echo '30 14 * * * /usr/bin/auto-update.sh > /dev/null' > cron_file.txt && sudo crontab -u root cron_file.txt && rm -f cron_file.txt