aboutsummaryrefslogtreecommitdiff
path: root/old/templatepkg.old
blob: 51a4fc2dc4cdf0e54c18263aa947bfaa7db9429c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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] <template-file>"
  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