Skip to content

Instantly share code, notes, and snippets.

@ijash
Last active June 25, 2021 03:36
Show Gist options
  • Save ijash/8dc25f7889b5f8a008049e596deaab6c to your computer and use it in GitHub Desktop.
Save ijash/8dc25f7889b5f8a008049e596deaab6c to your computer and use it in GitHub Desktop.
Automatic upgrade apt and clean in one command. Bash or zsh compatible. For debian-based like ubuntu, kde-neon, linux mint, raspberry-os(raspbian), etc.
#!/usr/bin/env bash
# www.github.com/ijash
bold=$(tput bold)
normal=$(tput sgr0)
zshrc_file=".zshrc"
bashrc_file=".bashrc"
command_alias='autoupgrade'
update_command="alias $command_alias='sudo apt update -y && sudo apt full-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y'"
exit_msg='exitting..'
function append_command() {
[[ -f "$1" ]] || {
echo "$1 Not Found"
return 1
}
if grep -Fxq "$2" "$1"; then
# code if found
echo "command already exist in $1"
echo $exit_msg
return 2
else
# code if not found
echo $2 >>$1
echo "success appending to $1"
echo "Done."
echo "reload '${bold}$1${normal}' by running '${bold}source /home/$USER/$1${normal}' to use '${bold}$command_alias${normal}' command"
fi
}
check_shell() {
append_command "$zshrc_file" "$update_command"
return_status=$?
[[ $return_status -eq 1 ]] || {
echo $exit_msg
return 1
}
[[ $return_status -eq 0 ]] || {
echo "Attempting $bashrc_file"
append_command "$bashrc_file" "$update_command"
[[ $? -eq 0 ]] || {
echo "No candidates found"
echo $exit_msg
return 1
}
}
}
cd "/home/$USER/"
echo "${bold}Script by Ijash (https://github.com/ijash)${normal}"
echo "Adding '${bold}$command_alias${normal}' to your shell"
check_shell
@ijash
Copy link
Author

ijash commented May 19, 2021

to use, execute this to terminal.

curl -s -L "https://gist.github.com/ijash/8dc25f7889b5f8a008049e596deaab6c/raw/4535f5a00ff76b26134361eedb5cdb82ceebd656/autoupgrade" | bash 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment