#!/bin/bash

os_release="/etc/os-release"

if [ ! "$(id -u)" = "0" ]
then
	echo "you are not root"
	exit 1
fi

os=$(grep "^NAME" $os_release | cut -d \" -f 2)

case $os in
	"CentOS Linux")
		yum makecache && yum update
	;;
	"Ubuntu" | "Kali GNU/Linux" | "Linux Mint" )
		apt update && apt upgrade && apt-get autoremove
	;;	
	"Debian GNU/Linux" )
		apt update && apt upgrade && apt autoremove
	;;
	"Raspbian GNU/Linux" )
		aptitude update && aptitude safe-upgrade && aptitude autoclean
	;;
	"openSUSE" | "SLED" | "SLES" )
		zypper refresh && zypper update
	;;
	"Manjaro Linux" )
		if [ "$(find /var/lib/pacman-mirrors/ -name status.json -mmin +40)" = "" ]
		then
			pacman -Syuu --noconfirm
		else
			pacman-mirrors -c de && pacman -Syyu --noconfirm
		fi
	;;
	"Fedora Linux" )
		dnf makecache && dnf update && dnf autoremove
	;;
	*)
		echo "OS not supported"
		exit 1
esac
