Announcement

Collapse
No announcement yet.

CLI system updates - little script help...

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    CLI system updates - little script help...

    I know many of us prefer the CLI to do updates - better feedback. I had taken to building aliases for the commands to shorten the typing. The other day I thought "why not a little script to do this?" I am not a programmer but I gave it a go.

    Feedback and enhancements desired:

    Code:
    #! /bin/bash
    
    # functions
    function quit {
      echo "Quiting..."
      exit
    }
    function badinput {
      echo "Invalid responce, please try again."
    }
    function update {
      echo "Updating..."
      sudo apt-get update
      break
    }
    function upgrade {
      echo "Upgrading..."
      sudo apt-get upgrade
      break
    }
    function dupgrade {
      echo "Dist-Upgrading..."
      sudo apt-get dist-upgrade
      break
    }
    function aremove {
      echo "Auto-removing..."
      sudo apt-get autoremove
    }
    function clean {
      echo "Cleaning..."
      sudo apt-get clean
    }
    function aclean {
      echo "Auto-cleaning..."
      sudo apt-get autoclean
    }
    
    
    #do it
    while true; do
    
    
        read -p "Would you like to update your repos? [Y/n/q]: " uanswer
    
    
        case $uanswer in
    
    
            n|N*)    echo "Skipping update..."
                       break 
            ;;
            
            q|Q*)    quit
            ;;
            
            *)    update
            ;;
        esac
        
    done
    
    
    while true; do
    
    
        read -p "Dist-upgrade, Upgrade, Skip or Quit? [D/u/s/q]: " danswer
    
    
        case $danswer in
    
    
            u|U*)    upgrade
            ;;
    
    
            n|N*)    echo "Skipping upgrade..."
                       break
            ;;
            
            q|Q*)    quit
            ;;
            
            *)    dupgrade
            ;;
        esac
        
    done
    
    
    echo "Final stage: Clean up..."
    
    
    while true; do
    
    
        read -p "Autoremove, Clean, autocLean or Exit script? [a/c/l/E]: " canswer
    
    
        case $canswer in
    
    
            a|A*)    aremove
            ;;
    
    
            c|C*)    clean
            ;;
            
            l|L*)    aclean
            ;;
            
            *)    quit
            ;;
        esac
        
    done
    I set the defaults based on my typical use of the script. Update, Dist-upgrade, Exit.

    Thoughts?

    Please Read Me

    #2
    Slick. I'm up for anything that reduces keystrokes

    Comment


      #3
      I tend to use aliases, but since you asked for improvement suggestions, I'd add some command line options for the script, like:

      -a|--automatic == run default actions without asking (update/dist-upgrade/exit)
      -i|--interactive == ask what do to (as the current script does)
      -s|--safe-upgrade == upgrade instead of dist-upgrade
      -c|--clean == run clean after upgrade
      etc.

      Of course some of these can be default (like "interactive" or "automatic"), which will be used if no options are specified.

      P.S. I'm not native in English, but I think "responce" should be spelled "response"
      Last edited by kubicle; Jul 05, 2013, 11:35 PM.

      Comment


        #4
        Originally posted by kubicle View Post
        P.S. I'm not native in English, but I think "responce" should be spelled "response"
        Opps! One of my least talented areas - speeling!

        I thought of some command line switches but I haven't figured the best way to add those yet. For my personal taste, I like to see what's going to be installed before going for it so I need to build in a break there or something. I'm still tinkering with it but I'm getting the family/house ready for a long trip to France [/brag] so I may not finish it real soon. It's at least partially an exercise to get my head back into programming mode. I quit college in 1982 but now that my main career is over I'd like to get back into programming as a hobby. I write little Service Menus to do stuff I do often and I'm trying to automate my server as much as possible but I'd really like to write a useful app like a full featured hard drive manager or maybe a working distro install tool. That will probably have to wait until next year after we move to the left coast.

        Please Read Me

        Comment


          #5
          Originally posted by oshunluvr View Post
          I like to see what's going to be installed before going for it so I need to build in a break there or something.
          Running the default actions in your script automatically doesn't actually change that, dist-upgrade will still stop to ask whether you wish to proceed before doing the upgrade...you'd just save three hits on enter when doing "the defaults" (you wouldn't need to confirm choices in the script)

          Comment


            #6
            I also use aliases.
            Code:
            alias a='clear && alias | more'alias addppa='sudo add-apt-repository'
            alias aremove='clear && sudo apt-get autoremove'
            alias chattr='sudo chattr'
            alias checkHD='clear && sudo smartctl --all /dev/sda'
            alias chkrk='clear && sudo chkrootkit'
            alias clean='clear && sudo apt-get clean'
            alias cleanup='clear && sudo apt-get --purge autoremove && sudo apt-get clean && sudo updatedb'
            alias debs='clear && ls -l /var/cache/apt/archives && ls -l /var/cache/apt/archives/partial'
            alias dependson='clear && apt-cache depends'
            alias dfsee='cd dfsee11x_linux/linux && sudo ./dfsee'
            alias dgrub='clear && cat /etc/default/grub'
            alias distupgrade='clear && sudo apt-get dist-upgrade'
            alias dload='aria2c '
            alias ea='clear && nano .bash_aliases'
            alias findit='clear && sudo find /* -mount -name'
            alias fstab='clear && cat /etc/fstab'
            alias getISO='aria2c -x2 '
            alias gpgkeys='clear && gpg --list-keys'
            alias grub='clear && less /boot/grub/grub.cfg'
            alias info='apt-cache policy'
            alias install='clear && sudo apt-get install'
            alias installNR='clear && sudo apt-get install --no-install-recommends'
            alias installed='dpkg --get-selections | grep install > junk'
            alias itsin='clear && apt-file find'
            alias kcmshell4='clear && kcmshell4 --list | sort'
            alias kfn='clear && ping www.kubuntuforums.net'
            alias killall='sudo killall -9'
            alias killzombie='sudo kill -9'
            alias kscrubber='clear && sudo kscrubber'
            alias la='clear && alias'
            alias ls.='ls -d .*'
            alias ls='ls --color=auto'
            alias mp32wav='lame --decode'
            alias mtab='clear && cat /etc/mtab'
            alias myOS='clear && lsb_release -d -c'
            alias myhdd='clear && sudo sfdisk -uS -l /dev/sda'
            alias mykernels="dpkg --list | awk '/linux-image/ {print \$2}' && cat Documents/Remove\ a\ Kernel"
            alias no#='clear && grep -v [#]'
            alias purge='clear && sudo apt-get remove --purge'
            alias revdepends='clear && apt-cache showpkg'
            alias rkh='clear && sudo rkhunter --check'
            alias rkhdb='clear && sudo rkhunter --propupd'
            alias sL='clear && cat /etc/apt/sources.list'
            alias scanPC='clear && sudo chkrootkit && sudo rkhunter --check'
            alias sessions='clear && ls -lat ~/.kde/share/config/session/'
            alias show='clear && sudo apt-cache show'
            alias simI='clear && sudo apt-get install --simulate'
            alias simINR='clear && sudo apt-get install --no-install-recommends --simulate'
            alias simP='clear && sudo apt-get purge --simulate'
            alias simR='clear && sudo apt-get remove --simulate'
            alias simU='clear && sudo apt-get dist-upgrade --simulate'
            alias snano='sudo nano'
            alias startkdm='clear && sudo service kdm start'
            alias ua='clear && source ~/.bash_aliases'
            alias ugrub='sudo update-grub2'
            alias update='clear && sudo apt-get update && sudo apt-file update'
            alias updatedb='clear && sudo updatedb' 
            alias used='clear && df -hT --exclude-type=tmpfs --exclude-type=devtmpfs'
            alias version='clear && apt-cache policy'
            alias zombies='clear && ps -elF | grep Z'
            alias inxic='echo Go to  http://code.google.com/p/inxi/source/list to see current changes to inxi'
            alias recordit="avconv -f x11grab -s $(xdpyinfo | awk '/dimensions/ {print $2}') -i :0.0 -vcodec libtheora -q 10 vid.mkv"
            alias na='nano .bash_aliases'
            alias login='Xephyr :1 -query 127.0.0.1 -screen 1024x768'
            alias weather='inxi -Zwxxx -W=wasilla,ak'
            alias list='ls -la'
            alias INXI='sudo inxi -U'
            Windows no longer obstructs my view.
            Using Kubuntu Linux since March 23, 2007.
            "It is a capital mistake to theorize before one has data." - Sherlock Holmes

            Comment


              #7
              Originally posted by Snowhog View Post
              I also use aliases.
              Snowhog ♥ clear

              btw:
              Code:
              alias ea='clear && nano ~/.bash_aliases'
              would also work if you are not in your home directory...your 'mykernels' also uses relative "Documents" path.

              Comment


                #8
                I like a 'clean' console when outputting a new command.

                I fixed the two aliases so they will work 'globally' in the console. Thanks for pointing out the omissions.
                Windows no longer obstructs my view.
                Using Kubuntu Linux since March 23, 2007.
                "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                Comment


                  #9
                  Originally posted by Snowhog View Post
                  I like a 'clean' console when outputting a new command.

                  I fixed the two aliases so they will work 'globally' in the console. Thanks for pointing out the omissions.
                  Oh, I have one more...'ea' and 'na' do pretty much the same thing.

                  Comment


                    #10
                    Hehe. Yup. ea was created earlier, and I had forgotten about it when I create na. Removed ea and updated na for 'global' use. Thanks again.

                    Added:
                    Made the following change to my sL alias:

                    alias sL="clear && grep -v [#] /etc/apt/sources.list | awk 'NF'"
                    Last edited by Snowhog; Jul 06, 2013, 12:50 PM.
                    Windows no longer obstructs my view.
                    Using Kubuntu Linux since March 23, 2007.
                    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                    Comment


                      #11
                      Originally posted by Snowhog View Post
                      alias sL="clear && grep -v [#] /etc/apt/sources.list | awk 'NF'"
                      I assume you are aiming to print only active repos? how about:
                      alias sL='grep "^[^#]" /etc/apt/sources.list'
                      (there's nothing better than shaving off a few nanoseconds from your aliases ..."^[^#]" means "line begins with a character that's not '#'"...so it will shave off of both commented repos and empty lines)

                      Comment


                        #12
                        Cool! I like that. Shorter code, which is consistent with the idea of an alias as well! I've made the change.
                        Windows no longer obstructs my view.
                        Using Kubuntu Linux since March 23, 2007.
                        "It is a capital mistake to theorize before one has data." - Sherlock Holmes

                        Comment


                          #13
                          Originally posted by Snowhog View Post
                          Cool! I like that. Shorter code, which is consistent with the idea of an alias as well! I've made the change.
                          Not to mention that by not piping grep results through awk, you'll save minutes of cpu time in roughly 100 years (if you use the alias every day)

                          Comment

                          Working...
                          X