Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Copyright (C) 2014 Alexander Mohn <pogrmman+dev@gmail.com>
- # Permission is hereby granted, free of charge, to any person obtaining a copy of this script to use it without restriction,
- # including without limitation of the rights to use, copy, modify, merge, publish, distribute, and/or sublicense this script
- # subject to the following conditions:
- # The above copyright notice and this permission notice shall be included in all copies or substantial portions of this
- # script.
- # THIS SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR
- # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THIS SCRIPT.
- # This script provides a way to update and maintain your Gentoo system
- # with a single command.
- ####### Functions #######
- # This updates the portage tree.
- function sync
- {
- read -p "Press [Enter] to update the portage tree..."
- sudo emerge --sync
- }
- # This logs the old python version.
- function python_old
- {
- mkdir /tmp/update
- eselect python list > /tmp/update/python_old.lst # Makes a list of old python versions.
- awk '{print $2}' < /tmp/update/python_old.lst > /tmp/update/python_old # Extracts version names.
- python_old=($(cat /tmp/update/python_old))
- pyv2_old=${python_old[1]}
- pyv3_old=${python_old[2]}
- echo $pyv2_old > /tmp/update/pyv2_old
- echo $pyv3_old > /tmp/update/pyv3_old
- cut -c 9 /tmp/update/pyv2_old > /tmp/update/v2_old # Converts version names into numbers.
- cut -c 9 /tmp/update/pyv3_old > /tmp/update/v3_old
- pyv2_old=($(cat /tmp/update/v2_old))
- pyv3_old=($(cat /tmp/update/v3_old))
- }
- # This logs the new python version.
- function python_new
- {
- eselect python list > /tmp/update/python.lst # Lists new versions of python.
- awk '{print $2}' < /tmp/update/python.lst > /tmp/update/python # Extracts the version names.
- py=($(cat /tmp/update/python))
- pyv2=${py[1]}
- pyv3=${py[2]}
- echo $pyv2 > /tmp/update/pyv2
- echo $pyv3 > /tmp/update/pyv3
- cut -c 9 /tmp/update/pyv2 > /tmp/update/v2 # Converts the version names into numbers.
- cut -c 9 /tmp/update/pyv3 > /tmp/update/v3
- pyv2=($(cat /tmp/update/v2))
- pyv3=($(cat /tmp/update/v3))
- }
- # This updates the system.
- function update
- {
- read -p "Press [Enter] key to begin updating system..."
- python_old
- sudo emerge --ask --update --deep --with-bdeps=y --newuse @world
- python_new
- if [ "$pyv2_old" != "$pyv2" ]; then
- read -p "Press [Enter] key to fix files broken by Python 2.x update..."
- sudo python-updater
- fi
- if [ "$pyv3_old" != "$pyv3" ]; then
- read -p "Press [Enter] key to fix files broken by Python 3.x update..."
- sudo python-updater
- fi
- }
- # This changes any configuration files that must be updated.
- function config
- {
- read -p "Press [Enter] key to change configuration files..."
- sudo dispatch-conf
- }
- # This checks for broken packages.
- function pkg_check
- {
- read -p "Press [Enter] key to check for broken packages..."
- sudo revdep-rebuild -p
- }
- # This rebuilds broken packages.
- function pkg_rebuild
- {
- read -p "Press [Enter] key to rebuild broken packages..."
- sudo revdep-rebuild
- }
- # This removes obsolete packages.
- function clean
- {
- read -p "Press [Enter] key to remove obsolete packages..."
- sudo emerge --ask --depclean --with-bdeps=y
- }
- # This prints introductory text.
- function intro
- {
- cat <<- _INTRO_
- Welcome to the system updater.
- You may be asked to enter your password several times during the process.
- If you do not have sudo privilages for emerge, revdep-rebuild, dispatch-conf,
- python-updater, and perl-cleaner this script may fail.
- _INTRO_
- }
- # If no options are specified.
- function noopts
- {
- cat <<- _DESC_
- This script helps to keep your Gentoo system up to date.
- You must specify at least one option.
- USAGE: update [-option1] [-option2] [-option3] [-option4] [-option5] [-option6]
- -S Sync the portage tree.
- -U Update the system.
- -C Change config files.
- -P Check for broken packages.
- -p Rebuild broken packages.
- -D Remove obsolete packages and dependenicies.
- -h Display this help text.
- WARNING: Options will be parsed in the order in which they are given.
- It is generally wise to use -S before -U, -U before -D, and -D before -p.
- _DESC_
- }
- ####### End of Function Declarations #######
- ####### Main #######
- if [ "$1" = "" ]; then # Checks to see if any options are specified.
- noopts # If not, it displays usage.
- else
- if [ "$1" = "-h" ]; then # Checks to see if -h is specified.
- noopts # If it is, it displays usage.
- else
- intro # Display introductory text.
- while [ "$1" != "" ]; do # Option parser.
- case $1 in
- -h ) noopts ;;
- -S ) sync ;;
- -U ) update ;;
- -C ) config ;;
- -P ) pkg_check ;;
- -p ) pkg_rebuild ;;
- -D ) clean ;;
- esac
- shift
- done # End of option parser.
- echo "Done updating system!"
- fi
- fi
- rm -r /tmp/update
- exit 0
- ####### End #######
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement