develia.org
»» i686 slackware tarballs..
»» software projects..
»» and much more..
 NAVIGATION 
 OPTIONS 

 INFO 
*** develia.org ***
by Giacomo Lozito
© 2004-2010

valid xhtml 1.0valid css!
powered by apachepowered by php
valid rss 2.0get firefox!

NO software patents in UE
 DOCUMENTS 
 gziplinks, automatic correction of links for gzipped files

This bash script is one of my precious "assistants" during the creation of tarballs for Slackware Linux. The job done by the script can be described in a couple of simple steps; suppose that there's a directory containing some files and some symbolic links pointing to those files, in example:

filelink1 -> file1
filelink2 -> file2
filelink3 -> file3
file1
file2
file3

First, the script gzips the files in the directory; then, the script corrects the links making them point to the gzipped files and making them appear as gzipped too. This is the resulting content of the directory: filelink1.gz -> file1.gz
filelink2.gz -> file2.gz
filelink3.gz -> file3.gz
file1.gz
file2.gz
file3.gz

The script does this job in the current working directory (the one you get from pwd), and it does the job for all files in the directory.
The primary practical application of the script is to fix quickly the man pages for a Slackware Linux tarball. In fact, the man pages in Slackware packages are always gzipped; so it is necessary to fix all the symbolic links in man directories, making them point to the gzipped files and making them appear as gzipped too. Doing this task manually can take too much time, expecially when there are a lot of links (in example, this happens with OpenLDAP man pages).
The script is written below, and it is downloadable from this link too.

#!/bin/bash
#
# "gziplinks" script
# Version 0.2 by Giacomo Lozito
# Last edited on 26/2/2005
# License: General Public License v2
#
# This script removes symbolic links to man pages, gzippes
# them and then rebuilds symbolic links for gzipped man pages
# IT DOES THE JOB IN THE CURRENT WORKING DIRECTORY!
#

read -n1 -p "This will gzip and rebuild links for
all directory content. Continue? (y/n) " _USERKEYPRESS
echo ""

if [ "$_USERKEYPRESS" != "y" ]
then
  exit 0
fi

gzip -9 -q *
for _MANSYMLINK in `ls -F | grep @$ | tr -d @`
do
	_MANDESTLINK=`readlink $_MANSYMLINK`
	rm $_MANSYMLINK
	ln -s $_MANDESTLINK.gz $_MANSYMLINK.gz
done

echo "Directory content gzipped and links rebuilt!"