Pages

Showing posts with label scripts. Show all posts
Showing posts with label scripts. Show all posts

28 January 2017

pharc v.6.0 released

Well, this is certainly unusual in 2017...

I used to release pharc once a year, so:
v.1.0 --> 2011
v.2.0 --> 2012
v.3.0 --> 2013
v.4.0 --> 2014
v.5.0 --> 2015

But like the wiki says:

Is pharc still actively developed?
pharc has now all the features and options I envisioned through all these years of development. From now on I only intend to make bug fixes and minor changes.

Well, this year one of the visitors said that the sorting of the archives was upside down, so I decided to change it to order archives in a more logical way.

Added to the changelog:

pharc (6.0-1)
v.6.0
Sort Archives in reverse mode.

You can read more in detail in the phlog post at: gopher://sdf-eu.org:70/1/users/chals/phlog
And get the software (all available versions) at: gopher://sdf-eu.org:70/1/users/chals/downloads/software

Have fun!

02 September 2015

pharc v.5.0 released

Today I released pharc v.5.0. You can find it in the usual places:

The downloads page (Includes the raw script and the .deb package):

gopher://sdf-eu.org:70/1/users/chals/downloads

The git repo, now hosted at gitlab, since gitorious closed down:

https://gitlab.com/pharc/pharc

LINKS TO FILES:

deb package 5.0.1

raw script pharc5

And the wiki:

https://gitlab.com/pharc/pharc/wikis/home

pharc has now all the features and options I envisioned through all these years of development. From now on I only intend to make bug fixes and minor changes.
Thanks for using pharc!
CHANGELOG
pharc (5.0-1)
  • v.5.0
    • Add '-A|--all' option to archive all years at once.
  • v.4.0
    • Changed shebang to #!/bin/sh to make script more portable.
    • Improved if[...]else statements to make script more robust.
    • Added functionality to choose year of archive.
    • Added functionality to specify several years in one go.
    • Added '-l|--list' option to list unarchived phlog posts.
    • Logging by default to "$HOME/pharc.log"
    • Split code into functions.
    • Added option '-d|--delete to delete the log file.
  • v.3.0
    • Added option -a to specify year of archive (Redundant).
    • Added -v (version information option).
    • Added -h (help menu).
    • Added -y (year of the archive).
    • Help function (usage).
    • Improve coding style.
    • Leave a backup of gophermap -> gophermap~ (in case things break).
    • Test before echoing "You're done now. Thanks for using pharc."
  • v.2.0
    • Updating for mkphlog v.0.2
    • Adding version number 2.0
    • Adding license (2012)
  • Initial release.

07 June 2014

pharc v.4.0 released

Today, even though I experienced some connectivity problems I managed to release pharc v.4.0. pharc is a very simple script that archives phlog posts on a yearly basis. The nice thing about it is that since a new version is released every year, it grows bigger, with more options, and hopefully, also better. Needless to say that the next release, unless there is a big bug to fix, is scheduled for 2015.

This year in particular, I did a lot of testing because there were many new options. And even so, I had to make a last minute change to make it work on NetBSD 6.1.2. I changed one echo call which contained a backlash escape character to printf because NetBSD's version of echo renders the backlash characters literally. So:

echo "1Archive $DIR\t$DIR" >> gophermap

Had to be re-written as:

printf "1Archive $DIR\t$DIR\n" >> gophermap

Not a big deal really, but last minute changes are sometimes annoying because you have to re-test and make sure that it remains posix compliant and that it works. Remember that I use two different platforms to test it: NetBSD + ksh and debian + bash

Below are some links that will lead you to more detailed information about pharc

The official release announcement, of course in my own phlog (which is archived by pharc):

gopher://sdf-eu.org:70/1/users/chals/phlog/./06-07-14

The downloads page (Includes the raw script and the .deb package):

gopher://sdf-eu.org:70/1/users/chals/downloads

The git repository, hosted at gitorious:

https://gitorious.org/pharc

and the wiki (important to consult, since in includes almost all possible use cases):

https://gitorious.org/pharc/pages/Home

I hope you like it and have fun with it! Happy phlogging :D


18 December 2013

pharc v.3.0 released

I have been procrastinating a bit about publishing version 3.0 because I wanted to do two things:
1.- Add functionality to choose the year of the archive, this would only be useful for people who are new to pharc but still, it would be a nice feature.
2.- Rewrite it in python, but unfortunately I'm still not proficient enough with python to do it (even though this is a simple script).
These things will have to wait for a later release someday :)
My initial idea was to publish one new release each year, i.e pharc1 saw the light in 2011, pharc2 in 2012, pharc3 in 2013 and so on and so forth, but to tell you the truth, gopher stuff is rather stagnant so I do not anticipate to see many changes in how things work form now on.
Anyway, the changelog for v.3.0 is:
 - Added option -a to specify current year of archive (redundant).

 - Added -v (version information option).

 - Added -h (help menu).

 - Added -y (year of the archive).

 - Help function (usage).

 - Improve coding style.

 - Leave a backup of gophermap > gophermap~ (in case things break).

 - Test before echoing "You're done now. Thanks for using pharc."
You can find all pharc versions here (gopher link):
gopher://sdf-eu.org:70/1/users/chals/downloads
There is also a .deb package available here:
And as usual, the git repository is hosted at gitorious:
pharc git repo

The wiki is located here:

09 April 2013

Clean (script)



I really do not know if this can be achieved automatically in a different/more effective way. The reason why I wrote this simple script is that I wanted to clean certain directories in my filesystem. The idea started with /tmp but I decided to include other directories such as the Trash bin.
What the script does is: One after the other, it tests whether the directories are empty or not. If they are empty it does nothing. If they contain files the script removes them, including the dot files.
BUGS: The script has, at least, one bug. Since it is set -e it stops after the very last iteration if there are hidden files in /tmp which cannot be removed if you run the script by hand as normal user. That is why I put /tmp in the last place. When it stops, all the other files are already deleted so it does not really matter whether it stops or not.
Why do I use set -e? Because I think that the rm -rf command toghether with a * wildcard is way too dangerous to let it loose.
Why keeping a log file? Because I can :)
Why to log ${DIR} is empty? This way I can adjust cron/anacron timing. For example, if I run it weekly and after a week the ${DIR} is empty, I may prefer to run it after two weeks or so. Do you get the idea? ;)
Why does the log file not include a list of all the deleted files? Who cares about the contents of Trash or tmp anyway? Especially after they have already been deleted.
Why not write a log function instead of redirecting the output to a log file?Because I'm too lazy to do that? Now seriously, the idea was in mind but the script is too simple to do that. Perhaps one day it will get better and grow bigger, and I do finally write that function then. (Note: That is not likely going to happen).
What is the best way to use this script? To tell you the truth, the best way to use this script is simply NOT using it. I mean that it really is very dangerous to remove files like that, hence the 'Big Fat Warning' on the header of the script. But still, if you want to give it a try, first read it, understand what the script does and adapt it to your needs.
Then, I recommend you add the script to, say, /etc/cron.monthly so that it is run by your system on a monthly basis.
Here is the script:
 #!/bin/sh

 set -e

 # Script to clean directories. The ls -A means that it does not list . & ..
 #
 # BIG FAT WARNING: rm -rf is potentially dangerous. Use this at your own risk!

 # Directories to clean.

 TRASH="/home/chals/.local/share/Trash/files" # Trash in Xfce
 DIR_TO_CLEAN1="/home/chals/tmp"
 DIR_TO_CLEAN2="/tmp"

 # Where to write the log file.

 LOG_FILE="/home/chals/clean.log"

 # Let's do it!

 for DIR in ${TRASH} ${DIR_TO_CLEAN1} ${DIR_TO_CLEAN2}
     do
         if [ "$(ls -A ${DIR})" ]
             then
                 rm -rf ${DIR}/* && rm -rf ${DIR}/.??* > /dev/null 2>&1 # Remove dot files too.
                 echo "$(date) Cleaning ${DIR} :) " >> ${LOG_FILE} 
             else
                 echo "$(date) Nothing to be done, ${DIR} is empty :( " >> ${LOG_FILE}
         fi
     done

02 December 2012

multinput (Multiple mouse/keyboard input with xinput)


I have got a dual head main desktop. I always thought it would be nice to be able to use several keyboards and mice working independently. Today I learnt how to easily configure multiple input with xinput only to discover that my settings will always disappear after every reboot or logout.


Well, the logical next step was to write an script to automatically activate multiple input but since I also want to be able to deactivate it at will I wrote two parts "start" and "stop". So the usage goes:
 $ multinput start
or
 $ multinput stop
or
 $ multinput restart
The script can either be run automatically at startup (anacron comes to mind) or manually.
Note: Be warned that this script is for personal use only. Feel free to adapt it to your own needs. I hope you like it and that it is useful for you too.
Here it is:
#!/bin/sh

set -e

# Script for personal use, to set multiple mouse/keyboard input on "odd".
#
# It uses xinput, so read its man page for more info. In order to list your
# devices type "xinput list"

MOUSE2="PIXART USB OPTICAL MOUSE"
KEYBOARD2="AT Translated Set 2 keyboard"

usage ()
{
echo "Type 'multinput start' to use multiple mice/keyboards."
echo "Type 'multinput stop' to stop using multiple mice/keyboards."
}

start ()
{
xinput create-master multinput
xinput reattach "$MOUSE2" "multinput pointer"
xinput reattach "$KEYBOARD2" "multinput keyboard"
} 
# Leave devices floating.    
 stop ()
{
xinput remove-master "multinput pointer"
}

if [ "$1" = "start" ]
    then
        start
        exit 0
elif [ "$1" = "stop" ]
    then
        stop
        exit 0
elif [ "$1" = "restart" ]
    then
        stop
        start
        exit 0
else
        usage
        exit 0
fi

29 July 2012

poic and poo


I published this script I wrote for personal use several weeks ago in my gopher hole concretely in the phlog but I decided to include it here under the scripts tag for an easy reference.

Credits go to Robby for his extraordinary suggestion of:

 "This .po file is 'poo'"

I must confess I'm still laughing at it every time I think about it but hopefully I will not get that message very often.

Here is the script:

(As you can see the usage is:  ~$ poic file.po)


 #!/bin/sh

 # 'poic' stands for Po Integrity Check

 msgfmt --verbose --check --output-file=/dev/null $1

 if [ "$?" -eq "0" ]
 then
      echo ""
      echo "This .po file is 'good': $(echo $1)"
 elif [ "$?" -ne "0" ]
 then
      echo ""
      echo "This .po file is 'poo': $(echo $1)"
 fi


A friend of mine, skizzhg, proposed this alternative version and renamed it to 'poo':
 #!/bin/sh

 if [ "$1" = "" ]; then
    printf '%s\n' " Po Integrity Check"
    printf '%s\n' " No file specified. Usage: poo <file.po>"
 else
   msgfmt --verbose --check --output-file=/dev/null "$1" && \
   { printf "\n This .po file is 'good': $1 \n"; } || \
   { printf "\n This .po file is 'poo': $1 \n"; }
 fi
I think that skizzhg's version is cleverer than mine and also more complete because it includes information about the script and usage notes.
If you think that 'poo' is not a very nice name be aware that it could perfectly stand for "PO Officer" ;-)
Thank you very much skizzhg. You rock!


Another friend proposed this other version. Let's call it poo2 (His suggestion)


 #!/bin/sh

 if [ -z "$1" ]; then
     echo ' Po Integrity Check'
     echo ' No file specified. Usage: poo2 <file.po>'
     exit 1
 fi

 if msgfmt --verbose --check --output-file=/dev/null "$1";then
    status=good 
 else
    status=poo
 fi
 printf "\n This .po file is '%s': %s \n" "$status" "$1"
Thanks :-)

08 January 2012

pharc v 2.0 released.

Today I released pharc 2.0. pharc is a script that organizes your phlog posts on a yearly basis.

pharc is based on mkphlog written by octotep. The reason for releasing v 2.0 is that mkphlog has been updated to v.0.2 so I needed to adapt my script to the changes.

You can read my phlog post on the release of mkphlog v.0.2 in my phlog here (gopher link)

You can read my phlog post on the release of pharc v.2.0 in my phlog here (gopher link)

pharc is version controlled using git. You can find the script v.2.0 here

If you're interested in the .deb package it is available in two places:

a. In my gopher hole (gopher link)
b. here: pharc 2.0-1 all.deb


The changelog is:
  • Updating for mkphlog v.0.2
  • Adding version number 2.0
  • Adding license (2012)
Enjoy!!!

03 January 2012

My first .deb

\o/ Today I built my first debian package or .deb

I wrote the source code of the package myself. You can find the main script here. It is a simple script to archive phlog (gopher blog) posts on a yearly basis. I called it pharc which stands for phlog archiver. It is based on the mkphlog script, written by octotep, that I use to build my own phlog

It takes a little bit of work, then

    $ debuild -us -uc

And voilà! you can find the package here:

pharc 1.0-1 all.deb

Important: This package was built for learning purposes only. It has some limitations I am perfectly aware of. Just to name a few:
  • The script assumes that you have a link in your $HOME/gopher to your gopher server. And that all your posts are in directories named $(date +%m-%d-%y)
  • The makefile is ridiculous. It only has seven lines! I wrote it in 25 seconds just to experience quick success. Now if you're really curious I can paste it here or somewhere else.
  • The complete list of files is not available online. They are stored on my server but if you want them you can ask for them. Here is the list:

    pharc_1.0.orig.tar.gz
    pharc_1.0-1_i386.changes
    pharc_1.0-1_i386.build
    pharc_1.0-1_all.deb
    pharc_1.0-1.dsc
    pharc_1.0-1.diff.gz
  • Who uses gopher or keeps a phlog anyway?

01 January 2012

'pharc' a phlog archiver.

I write my phlog using a script called mkphlog. It creates each phlog post in the form of a directory using the following variable: entrydate=date +%m-%d-%y
I started my phlog in October so there were not many posts. However, reaching the end of the year made me realize that I had to devise a way to archive all the posts on a yearly basis. Doing it by hand took me approximately 10 minutes. It basically means copying a bunch of directories into a single directory and editing the gophermaps so that the servers know where to look for files once the links are clicked.
But as you can imagine I am a busy person and I just can't add any more thing to my todo. So I decided to write a script to do the work for me automatically every year. Isn't that fantastic? Well it didn't take long to write a first functional version of the script. However, like all scripts, it was open for improvement.
This afternoon I have improved it a bit and I have committed what I imagine is the final version as of now. You can see it here
By the way, the title of this post is self explanatory enough. I called it pharc which stands for "phlog archiver". It would be very nice that someone tested it and found it useful.

25 August 2011

Moles

Moles are dynamic content scripts run by a Gopher server This last week I have been experimenting with them a little bit.

My first mole

This first one was a little naive, just to get the gist of how moles work:

#!/bin/sh

/usr/pkg/bin/cal
You can imagine the output of this script...

My second mole

This is the original code of the script. I had to strip it down a bit for it to properly work. But I'm including here this version as a starting point for a future revision and improvement. (You're warned. This mole has flaws!!!)

 #!/bin/sh

 #This mole creates a digest of the main text content of my gopher site.

 cd ~/gopher

 if test -d ~/gopher/digest; then
  cd ~/gopher/digest
 else
  mkdir ~/gopher/digest
  cd ~/gopher/digest
 fi

 echo "This is a digest of the most important text content of the gopher
 version of chalsattack. It is automatically created by a script for
 the very lazy people, too lazy even to navigate the site. Enjoy." > at_a_glance.txt

 #TODO:Add suffix .txt to files to be able to use *.txt and skip silly steps -->

 cp ~/gopher/presentation ~/gopher/digest
 cp ~/gopher/chalsattack/about ~/gopher/digest
 cp ~/gopher/chalsattack/history ~/gopher/digest

 FILES="presentation
 about
 history"

 for i in $FILES
 do
 cat $i >> at_a_glance.txt
 done

 cat at_a_glance.txt



 #Notify me if the script is run

 MAD=mail@address.com #MAD short for Mail ADdress

 echo "Mole out of the hole!!!" > ~/gopher/digest/mole.txt
 echo $(date) >> ~/gopher/digest/mole.txt
 cat ~/gopher/digest/mole.txt | mutt -s "Automatically sent report" $MAD

 #Please turn off the lights and take the garbage out!!!
 #rm -r ~/gopher/digest > /dev/null 2>&1

07 June 2011

Script to copy a customized debian-live image to a USB drive with persistence

I assume:

-You like creating customized debian-live images
-You like using them with persistence to store changes
-You copy the image and create the partitions by hand which is great to learn how to do it but you would like to make it all automatically using a script.

Well you're reading the right post then, but be warned that:

-This script is very simple and written and tested for personal use at home.
-No magic regexes used, just a logical sequence of variables and commands.
-You really must know what you're doing if you decide to try this script. Use at your own risk. The commands in the following script are very useful but if misused they can cause a filesystem mayhem and even destroy important data.

Here it is:

#!/bin/bash

 ## Script to automatically copy a customized debian live system image to a usb flash drive and create a partition for persistence

 ############ BE WARNED!!!! ###############

 ## This script assumes you know what you're doing!!! Using dd, parted and mkfs can end up in data loss!!!

 ## X = # Letter of your device /dev/sdX could be /dev/sdb or /dev/sdc ...

 ## In order to know your device name you can run ls -l /dev/disk/by-id

 ## Y/Z = # Numbers of your partitions. /dev/sdXY could be /dev/sdb1 or /dev/sdc2 ...




 X= # For example < c >

 Y= # For example <1>

 Z= # For example <2>

 START= # Number in MB where the partition must start for example <166> or <1024>

 END= # Number in MB where the partition must end for example <4007>

 cd /directory/where/your/image/is

 dd if=binary.img of=/dev/sd$X

 umount /dev/sd$X$Y

 parted /dev/sd$X mkpart primary $START $END && mkfs.ext2 -L live-rw /dev/sd$X$Z

25 April 2011

ftpbackup

This is a shell script I use to backup my home folder to a remote server. It uses lftp and it was written using a here document.

I got the inspiration from an article at linux.com and I improved it

I must tell you that this script is used to upload data to a remote directory but it also erases everything contained there. Do not use the -e option if you do not wish to delete anything.

# Script to backup an entire /home/< user > directory with lftp. Neat and clean. No sweat.

# Simply replace < whatever > with your own data. That's it.

###### BE WARNED!!! Option -e erases all the data on the target directory########

######DO NOT USE IT if you want to keep all the data there####################

 #!/bin/bash

 lftp << EOF > /dev/null 2>&1

 open -u < username >,< password > -p 21 < serveraddress >

 mirror -c -e -R /home/< user > < /path/to/remotedirectory >

 exit

EOF

22 October 2010

My backup script (improved)

Some months ago I published "Backup with rsync" one of my shell scripts because I had tried several backup utilities but none suited my needs. But as so many things in life you  never finish a script. You keep on thinking about different ways to improve it. So it grows bigger and (hopefully) better. I have changed the location of the backup, instead of using a usb pendrive I bought a toshiba usb hard drive (1Tb) and added two useful features. One is the date and time in the log file and the other is that the script now sends me an e-mail with the log file.
I started working with mutt including the log file as an attachment but I think that this way it is even easier. Nevertheless I think I'll continue working with the script. I might use it to make remote backups.



Feel free to use it or adapt it to your liking and also to let me know if it useful for you. Here it is:


#! /bin/bash

#This is a very simple backup script using rsync. It copies files to a (local) usb hard drive       asuming that it is already mounted. If not, I recommend using pmount.
# The ampersand sign is used to redirect standard error to a logfile.
# I use it with anacron. (15 minutes after startup)
# I have added date and time as useful information.
# I have also added a line to send me a daily report to my e-mail address.


MAD=myemail@address.com #MAD short for Mail ADdress
rsync -rlptoDvh  --delete /home/chals/*. /media/USB-HDD/backups &> asb.log
echo $(date) >> asb.log
mail -s "Automatically Sent Backup report" $MAD < /asb.log