Debian Codegraph @

bin/ftar

raw symbols SCIP
1 #! /bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 #*********************************************************************
4 #
5 # ftar -- extract tar files using FAI classes
6 #
7 # This script is part of FAI (Fully Automatic Installation)
8 # Copyright (C) 2001-2021 Thomas Lange, [email protected]
9 # Universitaet zu Koeln
10 #
11 #*********************************************************************
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # General Public License for more details.
21 #
22 # A copy of the GNU General Public License is available as
23 # '/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
24 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
25 # can also obtain it by writing to the Free Software Foundation, Inc.,
26 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 #*********************************************************************
28
29 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30 diescip-shell shell fai 6.6 die().() {
31
32 local e=$1 # first parameter is the exit code
33 shift
34
35 echoscip-shell system . . echo. "ftar: $*" >&2 # print error message
36 exit $e
37 }
38 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 extractscip-shell shell fai 6.6 extract().() {
40
41 local file=$1
42 local catname=$2
43
44 if [scip-shell system . . `[`. $deletefiles -eq 1 ] ; then
45 cd $target/$dir && rmscip-shell system . . rm. -f -- .* * 2>/dev/nullscip-shell filesystem . . `/dev/null`.
46 deletefiles=0
47 fi
48
49 if [scip-shell system . . `[`. $removedir -eq 1 ]; then
50 cd $target/$dir || diescip-shell shell fai 6.6 die(). 4 "ERROR: cd to $target/$dir failed. Aborting."
51 [scip-shell system . . `[`. $PWD = "/scip-shell filesystem . . `/`." ] && diescip-shell shell fai 6.6 die(). 3 "WARNING: Will not do recursive removal of directory /"
52 rmscip-shell system . . rm. -rf -- .* * 2>/dev/nullscip-shell filesystem . . `/dev/null`.
53 removedir=0
54 fi
55
56 echoscip-shell system . . echo. "ftar: extracting $file to $target/$dir" | trscip-shell system . . tr. -s '/scip-shell filesystem . . `/`.'
57 $catname $file | tarscip-shell system . . tar. $xattrs --numeric-owner -C $target/$dir $vflag -xf -
58 tardone=1
59 # if option -1 is set, only one class will be used
60 [scip-shell system . . `[`. $single -eq 1 ] && exit 0
61 }
62 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 usagescip-shell shell fai 6.6 usage().() {
64
65 catscip-shell system . . cat. <<EOF
66 ftar, extract tar files using classes.
67
68 Copyright (C) 2001-2021 by Thomas Lange
69
70 Usage: ftar [OPTION] ... SOURCE
71
72 -1 Use only first tar file matching class name.
73 -c class[class] Define classes (space separated).
74 -d Delete all files in target before extracting.
75 -D Create debug output.
76 -h Show summary of options.
77 -r Recursively remove files in target before extracting.
78 -s source_dir Look for source files relative to source_dir.
79 -t target_dir Extract files relativ to target_dir.
80 -v Be verbose. Not yet used.
81
82 EOF
83 exit 0
84 }
85 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86
87 source=$FAI/files
88 target=$FAI_ROOT
89 deletefiles=0
90 removedir=0
91 tardone=0
92 single=0
93 ignore=0
94
95 if [scip-shell system . . `[`. -n "$classes" ]; then
96 [scip-shell system . . `[`. -f $LOGDIR/FAI_CLASSES ] && classes=$(< $LOGDIR/FAI_CLASSES)
97 fi
98
99 while getopts 1hDdrvs:t:c:i opt ; do
100 case "$opt" in
101 d) deletefiles=1 ;;
102 D) debug=1 ;;
103 i) ignore=1 ;;
104 r) removedir=1 ;;
105 # v) verbose=1 ;;
106 1) single=1 ;;
107 s) source=$OPTARG ;;
108 t) target=$OPTARG ;;
109 c) classes=$OPTARG ;;
110 h) usagescip-shell shell fai 6.6 usage(). ;;
111 esac
112 done
113 shift $((OPTIND - 1))
114
115 [scip-shell system . . `[`. "$1" ] || usagescip-shell shell fai 6.6 usage().
116
117 # detect target fstype
118 targetfstype=$(awkscip-shell system . . awk. -vt="$target" '{if($2==t){print $3}}' /proc/mountsscip-shell filesystem . . `/proc/mounts`.)
119 if [scip-shell system . . `[`. "$targetfstype" != "nfs" ]; then
120 xattrs="--xattrs --xattrs-include=*.* --selinux --acl"
121 else
122 xattrs=
123 fi
124
125 # last class has highest priority
126 # reverse order of classes
127 for class in $classes; do
128 revclasses="$class $revclasses"
129 done
130
131 [scip-shell system . . `[`. "$debug" ] && vflag="-v"
132 [scip-shell system . . `[`. "$debug" ] && echoscip-shell system . . echo. "ftar: classes : $revclasses"
133 [scip-shell system . . `[`. -z "$source" ] && diescip-shell shell fai 6.6 die(). 1 "Source directory undefined."
134 [scip-shell system . . `[`. -z "$target" ] && diescip-shell shell fai 6.6 die(). 1 "Target directory undefined."
135
136 # currently only one directory is used
137 dir=$1
138 fpath=$source/$dir
139 [scip-shell system . . `[`. -d $fpath ] || diescip-shell shell fai 6.6 die(). 1 "No directory $fpath"
140
141 for c in $revclasses ; do
142 # what if a directory exists which is equal to the hostname or a classname?
143 [scip-shell system . . `[`. -f $fpath/$c.tgz ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tgz zcat
144 [scip-shell system . . `[`. -f $fpath/$c.tar ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tar cat
145 [scip-shell system . . `[`. -f $fpath/$c.tar.gz ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tar.gz zcat
146 [scip-shell system . . `[`. -f $fpath/$c.tar.bz2 ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tar.bz2 bzcat
147 [scip-shell system . . `[`. -f $fpath/$c.tar.xz ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tar.xz xzcat
148 [scip-shell system . . `[`. -f $fpath/$c.txz ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.txz xzcat
149 [scip-shell system . . `[`. -f $fpath/$c.tar.zst ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tar.zst zstdcat
150 [scip-shell system . . `[`. -f $fpath/$c.tzst ] && extractscip-shell shell fai 6.6 extract(). $fpath/$c.tzst zstdcat
151 done
152
153 if [scip-shell system . . `[`. $tardone -eq 0 ]; then
154 if [scip-shell system . . `[`. $ignore -eq 1 ]; then
155 echoscip-shell system . . echo. "ftar: No matching class found in $fpath"
156 exit 0
157 else
158 diescip-shell shell fai 6.6 die(). 1 "No matching class found in $fpath"
159 fi
160 fi
161
162 exit 0
163