Tech_Curiosity - My Wanderings in the Tech World
  • Home
  • About me
Home
About me
Tech_Curiosity - My Wanderings in the Tech World

_> Reads

  • Home
  • About me
Browsing Tag
gentoo linux script
Gentoo Linux

Gentoo PkgConfCleaner Script

January 14, 2020 No Comments

Introduction

I’m a messy guy when it comes to my /etc/portage/package.accept_keywords or my /etc/portage/package.use conf files. To that end, I created a short script using sed to get things cleaned up. I will admit that I could have avoided using a script at all if I asserted more control over what is put in those files. But if you’re lazy like me and were checking out the deployment script I cobbled together, you might find this useful. Hopefully, my laziness is of benefit to you.

Disclaimer

I’m a strong proponent of testing before implementing. Therefore, I do not take any responsibility for your use of this script on your systems and the consequences that will ensue (good or bad). Please do not just run this on a Gentoo system without first backing up your files. Remember the golden rules of IT:

1) Have a backup plan
2) Have a data backup

Follow these rules, and you will successfully recover most of the time.

Code Me

#!/bin/bash
##Name: pkgconfcleaner
##Author: Cephas0
##License? No Brah!

sed -i 's+#.*++g' /etc/portage/package.use
sed -i '/^\s*$/d' /etc/portage/package.use

sed -i 's+#.*++g' /etc/portage/package.accept_keywords
sed -i '/^\s*$/d' /etc/portage/package.accept_keywords

What does it do?

This is a rather simple thing. The first string finds all of the commented lines in your conf file of choice (hard coded here) and removes them. Then the second line removes all of the leftover space. It looks gnarly but it’s pretty simple in its objective.

I don’t know anything about scripts. How do I get started?

Using a text editor like “nano”, create a file named “pkgconfcleaner” in the /usr/local/bin folder so that the script will be in the path. Next copy and paste the code into the editor. Ok, so here’s a testing hint. If you remove the “-i” from the sed commands, it will not implement the code, but it will print out what the file would look like if it did. Neat, huh? The last thing you need to do to make this work is to run the “chmod” command to make the file executable.

chmod a+x /usr/local/bin/pkgconfcleaner

Something like the code above should be sufficient. (It might not work for you if you are not root or using “sudo”. If you got an error use “sudo” and try again. If it just failed, don’t type it out again, use “sudo !!”)

Wrap up

That’s a wrap on this post. While scripting this short script to fix my laziness may not have been the best allocation of my time, it does have other applicable uses you may find helpful.

Continue reading
Reading time: 2 min
Written by: cephas0

Recent Posts

Setting up Jenkins with a Freestyle Project for Java and Apache Ant

February 28, 2021

Making a Deployment Script Part II

February 21, 2021

Making a Deployment Script Part I

February 14, 2021

Winapps Project on Alpine Linux Allows you to Run Windows Applications like they were Locally Installed

February 7, 2021

Getting an SSL cert into an NGINX Container

February 28, 2020

Archives

  • February 2021
  • February 2020
  • January 2020

Categories

  • Alpine
  • Alpine
  • Debian
  • Debian
  • Docker
  • Gentoo
  • Interesting Tools
  • Jenkins
  • Linux
  • Nginx
  • Shell Scripting
  • Ubuntu 18.04 Server

About me

I am Cephas0, also known as Jack Stone. I write about things that interest me. This could be tech, projects I’m working on, or things that are important to me. Join me in my journey.

Recent Comments

    © 2020 | An Echo Enterprise