fcopy - copy files using classes
fcopy [options] SOURCE...
Copy a file from SOURCE to its target using classes. It also sets
permission modes for owner and group. Each SOURCE argument is a directory
which contains one or more template files for the source file to copy.
Depending on the list of defined classes, one file of the source directory
is selected and copied to the target. The target filename is the name of the
source directory.
The exit code returned by fcopy is 0 if all files are copied
successfully and >0 if an error occurs. For every successfully copied
file, a log message is printed to standard output.
- Options -c, -s, -t and a
SOURCE are required. Usually -c, -s and -t
- are set via variables in FAI.
- -B
- Remove backup files with suffix .pre_fcopy. You can also set the
environment variable FCOPY_NOBACKUP to 1.
- -b dir
- Don't copy files to file.pre_fcopy, but use hierarchy under
"dir" instead. The same effect is achieved by setting
environment variable FAI_BACKUPDIR.
- -c
class[,class]
- Define classes. Multiple classes must be comma separated. If not
specified, use the shell environment variable $classes (space separated).
The first class has lowest priority.
- -C file
- Read classes from file. Lines can contain multiple classes which
are space separated. Lines starting with # are comments.
- -d
- Delete target file if no class applies.
- -D
- Create debugging output.
- -F file
- Read list of sources from file. One SOURCE per line.
- -h
- Show help, version and summary of options.
- -H
- If source is a symbolic link, make destination a symbolic link too.
- -i
- Ignore warnings about no matching class and non-existing source
directories. These warnings will not set the exit code to 1.
- -I dir[,dir]
- Override list of ignored directories when recursing. If not given, it is
taken from $FCOPY_IGNOREDIRS and as a last chance an internal list of
known revision control system's metadata is used (CVS, .cvs, {arch},
.arch-ids).
- -l
- Do not copy if destination is a symbolic link
- -L file
- Log SOURCE and used class to file. Output format is
SOURCE CLASS COMMENT
where COMMENT gives some information about why the file has been preserved.
If not specified and $LOGDIR is set, use $LOGDIR/fcopy.log.
- -m
user,group,mode
- Set user, group and mode for all copied files (mode as octal number, user
and group numeric id or name). If not specified, use file file-modes or
data of source file.
- -M
- Use default values for user, group and mode. This is equal to -m
root,root,0644
- -n
- Print the commands, but do not execute them. This is like --dry-run in
other programs. You can enable it for all calls of fcopy by setting the
environment variable $FCOPY_DRYRUN.
- -r
- Copy recursively (traverse down the tree). Copy all files below SOURCE.
These are all subdirectory leaves in the SOURCE tree. Ignore
"ignored" directories (see "-I" for details).
- -s source_dir
- Look for SOURCE files relative to source_dir. Use $FAI/files if not
specified.
- -S
- Enable variable substitution. Every occurence of the pattern {%varname%}
will be substituted by the value of the shell variable $varname which is
mostly set in class/CLASSNAME.var. You can enable it for all calls of
fcopy by setting the environment variable $FCOPY_SUBSTITUTE. Variable
substitution is done before the execution of the preinst script.
- -t target_dir
- Copy files relative to target_dir. Use $FAI_ROOT if not
specified.
- -U
- If in softupdate mode skip this entire fcopy command.
- -v
- Create verbose output.
- preinst
- If a file 'preinst' exists and is executable, it is used in the following
way:
- 1.
- a temporary copy of the file for the used class is created
- 2.
- preinst is called with the used class and the full pathname to this
temporary copy (you can do in-place substitutions or other modifications
on this copy)
- 3.
- the copy is compared to the destination and replaces it only if there are
any differences and if the preinst scripts has a exit code zero.
- postinst
- If a file 'postinst' exists and is executable, it is called after
successfully having copied the file. It is called with two parameters, the
class being used and the full pathname to the target file. The variable
ROOTCMD is set, so you can prepend it to commands which should be executed
in the newly installed system.
Suppose the source directory /files/etc/X11/xorg.conf consists of
the following files:
CAD DEFAULT LAB MACH64 server1 ant04 postinst
Each file is an instance of a xorg.conf file for a different
Xserver configuration. The command
# fcopy -s /files -t /target /etc/X11/xorg.conf
copies one of these files from the directory
/files/etc/X11/xorg.conf to the file /target/etc/xorg.conf. For all defined
classes, fcopy looks if a corresponding file exists. The class with the
highest priority that matches an existing file name will be used for
copying. Here are examples of defined classes for different hosts and the
file which will be copied by fcopy.
- Host belongs to the
classes
- File used for copy
-
DEFAULT,LAB,server3
- LAB
-
DEFAULT,CAD,server1
- server1
-
DEFAULT,MACH64,ant01
- MACH64
-
DEFAULT,TFT,ant13
- DEFAULT server1
In FAI the list of defined classes starts with DEFAULT and the
last class is the hostname. DEFAULT is only used when no file for another
class exists. If a file is equal to the hostname, this will be used, since
hostname should always be the last class.
User, group and permissions for the files can be defined in
several ways. The file file-modes in the source directory has the highest
priority, followed by modes specified by -m/-M. If neither applies, the
modes from the source file are used.
The file file-modes in the source directory can contain one line
for each class. The space separated parameters are:
owner group mode class
Where owner and group can be specified by numeric id or by name.
The file permissions are defined by mode, which must be octal. If class is
missing, the data is used for all other classes, for which no data is
defined. If neither -m or file-modes data is available, the user, group and
mode of the source file will be used for the target file.
Missing subdirectories for the target file are created with mode
0755. If the destination file already exists and is different from the
source file, the suffix .pre_fcopy is appended to the old version of the
target file. If source and target files are equal, no copy is performed. A
copied file gets the same access and modification time as the source file,
not the time of the copy. If the file postinst exists, it will be executed
after the file was copied.
Do not create a file DEFAULT if no reasonable default
configuration file can be used. It's better to exit with an error than to
copy a wrong configuration file.
This command can also be used to maintain your configuration files
on a huge number of hosts.
ftar(8)
This program is part of FAI (Fully Automatic Installation). See
the FAI manual for more information on how to use fcopy. The FAI homepage is
https://fai-project.org.
Thomas Lange <lange@informatik.uni-koeln.de>
Henning Glawe <glaweh@physik.fu-berlin.de>