Last active
July 12, 2023 18:12
-
-
Save tsleite/8e695f93ff774b2509f20802aa09334d to your computer and use it in GitHub Desktop.
Script for update Ubuntu Server
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
#!/bin/bash | |
# Written by Ted LeRoy with help from Google and the Linux community | |
# Follow or contribute on GitHub here: | |
# https://github.com/TedLeRoy/ubuntu-update.sh | |
# Edited and update by tsleite | |
updates(){ | |
# Defining Colors for text output | |
red=$( tput setaf 1 ); | |
yellow=$( tput setaf 3 ); | |
green=$( tput setaf 2 ); | |
normal=$( tput sgr 0 ); | |
# Defining Header | |
HEADER=" | |
ubuntu-update.sh Copyright (C) 2018 Ted LeRoy | |
This program comes with ABSOLUTELY NO WARRANTY see | |
https://github.com/TedLeRoy/ubuntu-update.sh/blob/master/LICENSE.md | |
This is free software, and you are welcome to redistribute it | |
under certain conditions. | |
Update for tsleite@icloud.com | |
" | |
# Defining USAGE Variable to print usage for -h or undefined args | |
USAGE=" | |
Usage: sudo bash ubuntu-update.sh [-ugdrh] | |
No option - Run all options (recommended) | |
-u Don't run apt-get update | |
-g Don't run apt-get upgrade -y | |
-d Don't run apt-get dist-upgrade -y | |
-r Don't run apt-get auto-remove | |
-h Display Usage and exit | |
" | |
# Evaluating Command Line args and setting case variables for later use | |
while getopts ":ugdrh" OPT; do | |
case ${OPT} in | |
u ) uOff=1 | |
;; | |
g ) gOff=1 | |
;; | |
d ) dOff=1 | |
;; | |
r ) rOff=1 | |
;; | |
h ) hOn=1 | |
;; | |
\?) noOpt=1 | |
esac | |
done | |
# Checking whether script is being run as root | |
if [[ ${UID} != 0 ]]; then | |
echo "${red} | |
This script must be run as root or with sudo permissions. | |
Please run using sudo.${normal} | |
" | |
exit 1 | |
fi | |
# Executing based on option selection | |
if [[ -n $hOn || $noOpt ]]; then | |
echo "${red}$USAGE${normal}" | |
exit 2 | |
fi | |
# Display HEADER | |
echo "${red}$HEADER${normal}" | |
if [[ ! -n $uOff ]]; then | |
echo -e "\e[32m1] ##### Updating Data Base\e[0m" | |
apt-get update -y | |
fi | |
if [[ ! -n $gOff ]]; then | |
echo -e "\e[32m2] ##### Upgrading Operating System\e[0m" | |
apt-get upgrade -y | |
fi | |
if [[ ! -n $dOff ]]; then | |
apt-get dist-upgrade -y | |
echo -e "\e[32m3] ##### Full Upgrade Complete\e[0m" | |
fi | |
if [[ ! -n $rOff ]]; then | |
apt-get clean -y | |
apt autoremove -y | |
echo -e "\e[32m4] ##### Apt Clean Complete \e\n\n[0m" | |
fi | |
exit 0 | |
echo -e "\e[32m5] ##### No items to check given your chosen options. Exiting.\e[0m\n" | |
} | |
app=dialog;apt-mark showinstall | grep -q $app && echo "$app is installed" || sudo apt install dialog -y | |
HEIGHT=15 | |
WIDTH=40 | |
CHOICE_HEIGHT=4 | |
BACKTITLE="Automation by TSL" | |
TITLE="MENU" | |
MENU="" | |
OPTIONS=(1 "Check Updates" | |
2 "Install Terraform" | |
3 "none") | |
CHOICE=$(dialog --clear \ | |
--backtitle "$BACKTITLE" \ | |
--title "$TITLE" \ | |
--menu "$MENU" \ | |
$HEIGHT $WIDTH $CHOICE_HEIGHT \ | |
"${OPTIONS[@]}" \ | |
2>&1 >/dev/tty) | |
clear | |
case $CHOICE in | |
1) | |
#sudo bash $HOME/.ubuntu_updates.sh | |
updates | |
;; | |
2) | |
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl | |
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add - | |
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | |
sudo apt-get update && sudo apt-get install terraform -y | |
;; | |
3) | |
echo "You chose Option 3" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment