Last active
June 25, 2021 03:36
-
-
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.
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to use, execute this to terminal.