#!/bin/bash # # templatepkg: create a simplepkg package list from # a legacy slackware /var/log/packages # # pkgtool stuff package_name() { STRING=`basename $1 .tgz` # Check for old style package name with one segment: if [ "`echo $STRING | cut -f 1 -d -`" = "`echo $STRING | cut -f 2 -d -`" ]; then echo $STRING else # has more than one dash delimited segment # Count number of segments: INDEX=1 while [ ! "`echo $STRING | cut -f $INDEX -d -`" = "" ]; do INDEX=`expr $INDEX + 1` done INDEX=`expr $INDEX - 1` # don't include the null value # If we don't have four segments, return the old-style (or out of spec) package name: if [ "$INDEX" = "2" -o "$INDEX" = "3" ]; then echo $STRING else # we have four or more segments, so we'll consider this a new-style name: NAME=`expr $INDEX - 3` NAME="`echo $STRING | cut -f 1-$NAME -d -`" echo $NAME fi fi } if [[ ! -z "$3" && "$1" == "-o" ]]; then ROOT="$2" TEMPLATE="$3" OPTION="o" elif [[ ! -z "$2" && "$1" == "-o" ]]; then ROOT="/" TEMPLATE=$2 OPTION="o" elif [[ ! -z "$2" && "$1" != "-o" ]]; then ROOT="$1" TEMPLATE="$2" elif [ ! -z "$1" ]; then ROOT="/" TEMPLATE="$1" else echo "usage: [MASK=mask] $0 [-o root-dir] [-a] " echo -e "\troot-dir is the absolute path from with the desired /var/log/packages is placed" echo -e "\toptionaly, use MASK=mask $0 ..., eg: MASK=gcc* $0 ..." exit 1 fi if [ ! -d "$ROOT/var/log/packages" ]; then echo $ROOT/var/log/packages: directory not found exit 1 elif [[ -f "$TEMPLATE" && "$OPTION" != "o" ]]; then echo template $TEMPLATE already exists: use -o to overwrite exit 1 elif [[ -f "$TEMPLATE" && "$OPTION" == "o" ]]; then rm -f $TEMPLATE fi for package in `ls -1 $ROOT/var/log/packages/$MASK`; do package_name $package >> $TEMPLATE done