Skip to content

Instantly share code, notes, and snippets.

@atirut-w
Last active May 5, 2018 14:51
Show Gist options
  • Save atirut-w/53ad9956e95506932df3ed60eb3a66be to your computer and use it in GitHub Desktop.
Save atirut-w/53ad9956e95506932df3ed60eb3a66be to your computer and use it in GitHub Desktop.
#!/bin/bash
#An APT utility script
#Pretty much all in one. update repos, upgrade packages, autoremove, you name it
#First update to this program:
# +Added ability to add or remove software repository
# +Utilize ppa-purge to remove software repository
# +Some more features
#My banner made using figlet
# _ ____ _____ _ _ _ _ _ _ _
# / \ | _ \_ _| | | | | |_(_) (_) |_ _ _
# / _ \ | |_) || | | | | | __| | | | __| | | |
# / ___ \| __/ | | | |_| | |_| | | | |_| |_| |
#/_/ \_\_| |_| \___/ \__|_|_|_|\__|\__, |
# |___/
#Set grep highlight color
#Will be uncommented when i can make it work
#Uncomment this if you want to try it
#GREP_COLOR=32
#Color sheet
white='\033[0m'
black='\033[30m'
green='\033[32m'
red='\033[31m'
yellow='\033[93m'
#Text presets
warning='\033[1;4;91m'
yellow_bold='\033[93;1m'
underlined_bold='\033[1;4m'
#Functions
display_usage () {
echo -e "${green}APT${white} utility script by ${green}Wattana Gaming${white}"
echo -e ""
echo -e "This utility can:"
echo -e " ${green}Add${white} software repository : As the name suggests. Automatically
update the software list"
echo -e " ${green}Autoremove${white} : Automatically remove unused softwares downloaded
to satisfy the dependency"
echo -e " ${green}Autoclean${white} : Automatically remove archived software packages"
echo -e " ${green}Check${white} upgradable softwares: As the name suggests"
echo -e " ${green}Install${white} a software : As the name suggests, will try to update
if already installed"
echo -e " ${green}Search${white} For a software : As the name suggests"
echo -e " ${green}Remove${white} a software : As the name suggests"
echo -e " ${green}Remove${white} software repository: As the name suggests"
echo -e " ${green}Update${white} software list : Check for ${green}new/upgradable${white} softwares"
echo -e " ${green}Update${white} softwares : Update all installed software"
echo -e ""
#echo -e "${underlined_bold}NOTE${white}: software/package and package have the same meaning in this case"
}
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
pause() {
#PRESS ENTER 2 CONTINUE
read -p "Press enter to continue"
}
display_banner () {
echo -e "${green}
_ ____ _____ _ _ _ _ _ _ _
/ \ | _ \_ _| | | | | |_(_) (_) |_ _ _
/ _ \ | |_) || | | | | | __| | | | __| | | |
/ ___ \| __/ | | | |_| | |_| | | | |_| |_| |
/_/ \_\_| |_| \___/ \__|_|_|_|\__|\__, |
|___/${white}"
}
if [[ ( $1 == "--help") || $1 == "-h" ]]
then
display_banner
display_usage
#Whats this exit for? I got it from online tutorial and looks like its no problem
#removing this command
#exit 0
fi
#Main code
if [ -z "$1" ]
then
display_banner
while true
do
sudo echo
echo -e "${green}APT${white} utility script by ${green}Wattana Gaming${white}"
echo -e ""
echo -e " 1. ${green}Add${white} software repository"
echo -e " 2. ${green}Autoremove${white}"
echo -e " 3. ${green}Autoclean${white}"
echo -e " 4. ${green}Check${white} for upgradable softwares"
echo -e " 5. ${green}Install${white} a software"
echo -e " 6. ${green}Search${white} For a software"
echo -e " 7. ${green}Remove${white} a software"
echo -e " 8. ${green}Remove${white} software repository"
echo -e " 9. ${green}Update${white} software list"
echo -e " 10. ${green}Update${white} all installed softwares"
echo -e " 11. ${green}EXIT${white}"
echo -e ""
echo -e "Consult the manual by running this program with ${green}-h${white} or ${green}--help${white} for more info"
read -p "Please choose one of the options: " option
#For testing purpose only!
#echo "${option}"
#Again, An updated shitton of "if" statements
#This is where all the APT magic happens
if [[ $option == '1' ]]; then
echo -e ""
echo -e "Please enter the repository name"
echo -e "The repository name will be after the \"${green}add-apt-repository${white}\" command"
echo -e "Example:"
echo -e "sudo add apt repository ${green}ppa:webupd8team/java${white}"
echo -e ""
read -p "Repository name: " repository
sudo add-apt-repository ${repository}
sudo apt update
elif [[ $option == '2' ]]; then
confirm "Use autoremove?[Y/n] " && sudo apt autoremove
elif [[ $option == '3' ]]; then
confirm "use autoclean?[Y/n] " && sudo apt autoclean
elif [[ $option == '4' ]]; then
confirm "Update the software list before checking?[Y/n] " && sudo apt update
echo -e "${warning}WARNING: Huge wall of text incoming!${white}"
sleep 1.3
sudo apt list --upgradeable
elif [[ $option == '5' ]]; then
confirm "Do you want to search for an available software?[Y/n] " && read -p "Search for: " search && sudo apt search ${search}
read -p "Software to install: " install
sudo apt install ${install}
elif [[ $option == '6' ]]; then
echo -e "Do you want to search for all softwares or installed softwares?"
echo -e "1. ${green}All${white} softwares"
echo -e "2. Only ${green}Installed${white} softwares"
read -p "Option: " option
if [[ $option == '1' ]]; then
read -p "Search for: " search
sudo apt search ${search}
pause
elif [[ $option == '2' ]]; then
read -p "Search for: " search
sudo apt list --installed | grep ${search}
pause
fi
elif [[ $option == '7' ]]; then
confirm "Search for an installed softwares?[Y/n] " && read -p "Search for: " search && sudo apt list --installed | grep ${search}
read -p "Software to remove: " remove
sudo apt remove ${remove}
elif [[ $option == '8' ]]; then
confirm "Search for a software repository?[Y/n] " && read -p "Search for: " search && grep -r --include '*.list' '^deb ' /etc/apt/ | sed -re 's/^\/etc\/apt\/sources\.list((\.d\/)?|(:)?)//' -e 's/(.*\.list):/\[\1\] /' -e 's/deb http:\/\/ppa.launchpad.net\/(.*?)\/ubuntu .*/ppa:\1/' | grep ${search}
read -p "Software repository to remove" remove
sudo ppa-purge ${remove}
elif [[ $option == '9' ]]; then
confirm "Update the software list?[Y/n] " && sudo apt update
elif [[ $option == '10' ]]; then
echo -e ""
echo -e "${warning}WARNING!${white}: Updating all installed software may ${green}takes long time${white} depending on"
echo -e " your ${green}internet${white} and ${green}CPU${white} speed"
echo -e ""
confirm "Update?[Y/n] " && sudo apt upgrade
notify-send "APT Utility" "APT Utility has finished updating the software list"
elif [[ $option == '11' ]]; then
exit
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment