The Autopackage API

Filesystem

Miscellaneous filesystem-related functions.

Functions in this category

NameParameters
baselineFile <FILENAME>
dirIsEmpty <DIRECTORY> [--no-recurse]
getBaseline [OPTIONS] <MATCH>
getFile [OPTIONS] <FILENAME>
getFileMD5 <FILENAME>
haveWriteAccess <DIRECTORY>
recoverFile <FILENAME>
removeFile <FILENAME>
removeDir <DIRECTORY>

Details

baselineFile
Syntax: baselineFile <FILENAME>
FILE: file to compare.
Returns: 0 if FILE is processed; 1 if malformed function call.
Process to compare two files and archive FILE if it is different from file information which is archived in a baseline file defined by $ROOTNAME/baseline.


baselineFile() is the companion to installConfig() function. During the installConfig, a MD5 of the original configuration file is added to the baseline file called $ROOTNAME/baseline. The logfile would have a baselineFile to determine how to handle this special file. During the uninstall, baselineFile() creates a MD5 of the configuration file to delete and compares it the baseline MD5. autopackage will archive configuration files that are different from installed files while deleting the configuration files if they match. So custom or modified configuration files will still exist in the system for reference purposes.


If files are different then FILE is archived to FILE.apkgsave . If FILE.apkgsave exists then FILE.apkgsave is moved to FILE.apkgsave.1 and FILE is copied to FILE.apkgsave . With this method, if FILE is archived then FILE.apkgsave is the latest saved version. Archived version are then FILE.apkgsave.2, FILE.apkgsave.3, etc.
See also: installConfig().

Example:
installConfig "etc/foo-config"
# uninstall log would have either entry
# baselineFile /home/user/.local/etc/foo-config
#   or
# baselineFile /etc/foo-config


dirIsEmpty
Syntax: dirIsEmpty <DIRECTORY> [--no-recurse]
--no-recurse: Do not recursively look for empty directories.
DIRECTORY: A directory name.
Returns: 0 if DIRECTORY is empty, 1 if it's not.
Check whether DIRECTORY is empty. If DIRECTORY only contains empty subdirectories then DIRECTORY will be considered empty, unless --no-recurse is passed.


getBaseline
Syntax: getBaseline [OPTIONS] <MATCH>
MATCH: string to match and retrieve information from.
--links: links to file.
--no-newline: output to not contain a newline
--no-whitespace: output to not contain whitespace
--mtime: last modified time in seconds of file.
--gid: groud id of file.
--uid: user id of file.
--md5: generated MD5 checksum of file.
--name: name of file.
--perms: permission block of file.
Returns any information from the baseline file that matches the defined string. The MATCH string must match an entire piece of data, therefore a string that is a filename must be absolute.
See also: getFile().
Example:
  getBaseline "/lib/libfoo.so.1.1.2"


getFile
Syntax: getFile [OPTIONS] <FILENAME>
--links: links to file.
--no-newline: output to not contain a newline
--no-whitespace: output to not contain whitespace
--mtime: last modified time in seconds of file.
--gid: groud id of file.
--uid: user id of file.
--md5: generated MD5 checksum of file.
--name: name of file.
--baseline: text to be used in baseline file.
FILENAME: file to retrieve information from.
--perms: permission block of file.
Returns any information about a valid file.
See also: getFileMD5().
Example:
  getFile "/lib/libfoo.so.1.1.2"


getFileMD5
Syntax: getFileMD5 <FILENAME>
FILENAME: file to generate MD5 checksum.
Generate a MD5 checksum for the given file.
See also: getFile(), getBaseline().
Example:
  getFileMD5 "/lib/libfoo.so.1.1.2"


haveWriteAccess
Syntax: haveWriteAccess <DIRECTORY>
DIRECTORY: The directory name.
Returns: 0 if we have write access, 1 if we don't.
Checks whether we have write access to DIRECTORY.


recoverFile
Syntax: recoverFile <FILENAME>
FILENAME: file or directory to move back into filesystem.
Returns: 0 always.
Recovers file or directory from the package's BACKUP environment variable directory and moves it back into the filesystem.


recoverFile() is the companion to the copyFile() functions. During a copy process if the file exists, the previous file is moved to $autopackage_db/$BACKUP/. The $BACKUP variable is set as `$ROOTNAME/backup'.
See also: copyFiles(), copyFile(), linkFile().

Example:
copyFiles "foo" "/some/directory" collides with a pre-existing file
# uninstall log would have the entry
# recoverFile /some/directory/foo   and the colliding file
# would be copied to $autopackage_db/$BACKUP/some/directory/foo


removeFile
Syntax: removeFile <FILENAME>
FILE: file to remove.
Returns: 0 for all cases.


removeDir
Syntax: removeDir <DIRECTORY>
DIRECTORY: The directory to remove.
Returns: 0 always.
Recursively check if DIRECTORY is empty, and remove it if it is. Checks for any directory in the DIRECTORYs path.
See also: dirIsEmpty()
Example:
mkdir -p a/deep/directory
touch a/file
pruneDir a/deep/directory
ls a/deep   # =>  "a/deep: no such file or directory"
ls a/file   # =>  exists