Jump to content

BASH Scripts


Diminished2b

Recommended Posts

Post your useful BASH scripts here (Original only).

 

 

 

Umerge - For Gentoo Linux, unmerges multiple packages based on a keyword. I was disapointed that you couldn't use wildcards with emerge considering FreeBSD's Ports (Which are the role-model for portage) tools supported wildcards.

 

#!/bin/bash



keyword=$1



if [[ $1 = "" ]]

then echo "Please input the keyword to be mass unmerged:"

    read keyword

else :

fi



if [[ $keyword = "" ]]; then

       echo "You need to enter a keyword next time"

       exit

fi



ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ | xargs emerge -pC





echo "These are the packages that I will unmerge. Are you sure you want

to go through with this? [y/n]:"



read var



if [ $var = "y" ]; then

       ls -R /var/db/pkg/ | grep $keyword | sed 's/\/var\/db\/pkg\///g' | sed 's/://g' | sed 's/-r[0-9]$//g' | sed 's/\.//g' | sed 's/-[0-9]*$//g' | grep \/ | xargs emerge -C

else

       echo "Sorry to hear that, maybe you should revise your keyword"

       exit

fi

 

 

 

Kernel updater [incomplete] -

 

Requires Lynx (Feel free to revise)

 

- Updates your kernel to the latest with git-sources patches. Incomplete, needs work. (Feel free to revise). It was distro-dependant but I never got to redoing it for compatibility with any distro. You can probably just wget the latest Linux version, wget the latest scripts, untar, patch, cp, oldconfig, compile, cp, sed some lines in bootloader configuration file.

 


#!/bin/bash



installed=`uname -r`

installed_ver=`echo $installed | cut -d- -f1 | awk -F "." '{ print $3 }'`

installed_rc=`echo $installed | awk -F "-" '{ print $2 }' | cut -c3-`

installed_git=`echo $installed | awk -F "git" '{ print $2 }'`



current=`lynx -dump http://www.kernel.org/kdist/finger_banner | grep git | awk '{ print $11 }'`

current_ver=`echo $current | cut -d- -f1 | awk -F "." '{ print $3 }'`

current_rc=`echo $current | awk -F "-" '{ print $2 }' | cut -c3-`

current_git=`echo $current | awk -F "git" '{ print $2 }'`



if [ "$installed_ver" -lt "$current_ver" ]; then upgrade="1"

elif [ "$installed_ver" -eq "$current_ver" ] && [ "$installed_rc" -lt "$current_rc" ]; then upgrade="1"

elif [ "$installed_ver" -eq "$current_ver" ] && [ "$installed_rc" -eq "$current_rc" ] \

 && [ "$installed_git" -lt "$current_git" ]; then upgrade="1"

fi



if [ -n "$upgrade" ]

then

   echo -e "Your kernel version is out of date\n"

   #To be done

fi



#debug

echo "Upgrade: $upgrade"

echo "Installed: $installed"

echo "Installed ver: $installed_ver"

echo "Installed rc: $installed_rc"

echo -e "Installed git: $installed_git\n"

echo "Current: $current"

echo "Current ver: $current_ver"

echo "Current rc: $current_rc"

echo "Current git: $current_git"

 

 

 

 

 

Yeah, I know, not much. I'm working on a few more but I'm already heavily into something else.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.