~vcs-imports/fai/trunk

« back to all changes in this revision

Viewing changes to scripts/ftar

  • Committer: lange
  • Date: 2005-11-10 12:47:47 UTC
  • Revision ID: svn-v4:ba5ec265-b0fb-0310-8e1a-cf9e4c2b1591:trunk:3022
rename directory scripts to bin, fix pathes in Makefile

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
 
3
 
# $Id$
4
 
#*********************************************************************
5
 
#
6
 
# ftar -- extract tar files using FAI classes
7
 
#
8
 
# This script is part of FAI (Fully Automatic Installation)
9
 
# Copyright (C) 2001-2003 Thomas Lange, lange@informatik.uni-koeln.de
10
 
# Universitaet zu Koeln
11
 
#
12
 
#*********************************************************************
13
 
# This program is free software; you can redistribute it and/or modify
14
 
# it under the terms of the GNU General Public License as published by
15
 
# the Free Software Foundation; either version 2 of the License, or
16
 
# (at your option) any later version.
17
 
#
18
 
# This program is distributed in the hope that it will be useful, but
19
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 
# General Public License for more details.
22
 
23
 
# A copy of the GNU General Public License is available as
24
 
# '/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
25
 
# or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html.  You
26
 
# can also obtain it by writing to the Free Software Foundation, Inc.,
27
 
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
 
#*********************************************************************
29
 
 
30
 
version="Version 1.5.3, 24-dec-2004"
31
 
 
32
 
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33
 
die() {
34
 
    echo "ftar died with error: $1"
35
 
    exit 99
36
 
}
37
 
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38
 
extract() {
39
 
 
40
 
    local file=$1
41
 
    local catname=$2
42
 
 
43
 
    echo "ftar: extracting $file to $target/$dir"
44
 
    $catname $file | tar -C $target/$dir $vflag -xf -
45
 
    tardone=1
46
 
    # if option -1 is set, only one class will be used
47
 
    $single && exit 0
48
 
}
49
 
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50
 
usage() {
51
 
 
52
 
    cat <<EOF
53
 
ftar, extract tar files using classes. $version
54
 
 
55
 
   Copyright (C) 2001-2003 by Thomas Lange
56
 
 
57
 
Usage: ftar [OPTION] ... SOURCE
58
 
 
59
 
   -1                   Use only first tar file matching class name.
60
 
   -c class[class]      Define classes (space separated).
61
 
   -d                   Delete all files in target before extracting.
62
 
   -D                   Create debug output.
63
 
   -h                   Show summary of options.
64
 
   -r                   Recursively remove files in target before extracting.
65
 
   -s source_dir        Look for source files relative to source_dir.
66
 
   -t target_dir        Extract files relativ to target_dir.
67
 
   -v                   Be verbose. Not yet used.
68
 
 
69
 
Report bugs to <lange@informatik.uni-koeln.de>.
70
 
EOF
71
 
    exit 0
72
 
}
73
 
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74
 
 
75
 
source=$FAI/files
76
 
target=$FAI_ROOT
77
 
deletefiles=0
78
 
removedir=0
79
 
tardone=0
80
 
 
81
 
while getopts 1hDdrvs:t:c: opt ; do
82
 
        case "$opt" in
83
 
        d) deletefiles=1 ;;
84
 
        D) debug=1 ;;
85
 
        r) removedir=1 ;;
86
 
#        v) verbose=1 ;;
87
 
        1) single=1 ;;
88
 
        s) source=$OPTARG ;;
89
 
        t) target=$OPTARG ;;
90
 
        c) classes=$OPTARG ;;
91
 
        h) usage ;;
92
 
        esac
93
 
done
94
 
shift $(($OPTIND - 1))
95
 
 
96
 
[ "$1" ] || usage
97
 
[ -f $ENV{LOGDIR}/FAI_CLASSES ] && classes=`cat $ENV{LOGDIR}/FAI_CLASSES`
98
 
# last class has highest priority
99
 
 
100
 
# reverse order of classes
101
 
for class in $classes; do
102
 
    revclasses="$class $revclasses"
103
 
done
104
 
 
105
 
[ "$debug" ] && vflag="-v"
106
 
[ "$debug" ] && echo "ftar: classes : $revclasses"
107
 
[ -z "$source" ] && die "Source directory undefined."
108
 
[ -z "$target" ] && die "Target directory undefined."
109
 
 
110
 
# currently only one directory is used
111
 
dir=$1
112
 
fpath=$source/$dir
113
 
[ -d $fpath ] || die "No directory $fpath"
114
 
 
115
 
[ $deletefiles -eq 1 ] && cd $target/$dir && rm -f  .* * 2>/dev/null
116
 
 
117
 
if [ $removedir -eq 1 ]; then
118
 
    cd $target/$dir
119
 
    if [ $PWD = "/" ]; then
120
 
        echo "ftar WARNING: Will not do recursive removal of directory /"
121
 
    else
122
 
        rm -rf .* * 2>/dev/null
123
 
    fi
124
 
fi
125
 
 
126
 
for c in $revclasses ; do
127
 
    # what if a directory exists which is equal to the hostname or a classname?
128
 
    # [ -f $fpath/$c ]          && extract $fpath/$c cat
129
 
    [ -f $fpath/$c.tar ]      && extract $fpath/$c.tar cat
130
 
    [ -f $fpath/$c.tar.gz ]   && extract $fpath/$c.tar.gz zcat
131
 
    [ -f $fpath/$c.tar.bz2 ]  && extract $fpath/$c.tar.bz2 bzcat
132
 
done
133
 
 
134
 
[ $tardone -eq 0 ] && echo "ftar: No matching class found in $fpath"
135
 
exit 0