Certainly! Below is a detailed analysis of the provided shell script, focusing on all locations where the script writes to the filesystem. This includes file creations, modifications, and symbolic links.
Key Variables and Their Roles
EXEDIR: Determines the directory where the script is located.
BINDIR: Points to the binaries subdirectory within EXEDIR.
ZAPRET_BASE: Base directory for installation, defaults to EXEDIR if not set.
ARCHLIST: List of supported architectures based on the operating system.
PKTWS: Optional component based on the OS.
Function Analysis
1. check_dir Function
- Purpose: Validates the presence and executability of the
ip2net executable within a specified architecture directory.
- Write Operations:
- Standard Error (
stderr):
echo >&2 "$exe is not executable. set proper chmod."
echo >&2 "$exe is absent"
- Filesystem: No direct writes; it only reads and executes files.
2. ccp Function
- Purpose: Handles the linking or copying of executables to the
ZAPRET_BASE directory.
- Write Operations:
- Directory Creation:
mkdir "$ZAPRET_BASE/$2": Creates the target directory if it doesn't exist.
- File Removal:
rm -f "$ZAPRET_BASE/$2/$F": Removes existing files before creating new links or copies.
- Symbolic Linking:
ln -fs "../$BINS/$1" "$ZAPRET_BASE/$2": Creates a symbolic link from the source binary to the target directory.
- File Copying (Commented Out):
cp -f "../$BINS/$1" "$ZAPRET_BASE/$2": Copies the binary to the target directory (if uncommented).
Filesystem Write Locations
Based on the ccp function and the main script logic, the script writes to the following locations within the ZAPRET_BASE directory:
-
$ZAPRET_BASE/ipnet/ip2net
- Action: Creates a symbolic link or copies the
ip2net executable.
- Source:
binaries/<arch>/ip2net
-
$ZAPRET_BASE/mdig/mdig
- Action: Creates a symbolic link or copies the
mdig executable.
- Source:
binaries/<arch>/mdig
-
$ZAPRET_BASE/nfq/<PKTWS>
- Action: Creates a symbolic link or copies the
<PKTWS> executable.
- Condition: Only if
PKTWS is set based on the operating system.
- Source:
binaries/<arch>/<PKTWS>
-
$ZAPRET_BASE/tpws/tpws
- Action: Creates a symbolic link or copies the
tpws executable.
- Condition: Skipped if the operating system is CYGWIN.
- Source:
binaries/<arch>/tpws
Directory Creations
The script ensures the following directories exist within ZAPRET_BASE before writing files:
$ZAPRET_BASE/ipnet/
$ZAPRET_BASE/mdig/
$ZAPRET_BASE/nfq/ (if PKTWS is used)
$ZAPRET_BASE/tpws/ (unless OS is CYGWIN)
Summary of Write Operations
| Location | Operation | Source | Condition |
|---|
$ZAPRET_BASE/ipnet/ip2net | Create symlink or copy ip2net | binaries/<arch>/ip2net | Always |
$ZAPRET_BASE/mdig/mdig | Create symlink or copy mdig | binaries/<arch>/mdig | Always |
$ZAPRET_BASE/nfq/<PKTWS> | Create symlink or copy <PKTWS> | binaries/<arch>/<PKTWS> | If PKTWS is defined based on OS |
$ZAPRET_BASE/tpws/tpws | Create symlink or copy tpws | binaries/<arch>/tpws | Unless the OS is CYGWIN |
$ZAPRET_BASE/ipnet/ | Create directory | N/A | If it doesn't exist |
$ZAPRET_BASE/mdig/ | Create directory | N/A | If it doesn't exist |
$ZAPRET_BASE/nfq/ | Create directory | N/A | If PKTWS is used and directory doesn't exist |
$ZAPRET_BASE/tpws/ | Create directory | N/A | Unless the OS is CYGWIN and directory doesn't exist |
Additional Notes
- Symbolic Links vs. Copies: By default, the script uses symbolic links (
ln -fs). If you prefer to copy the files instead, you can uncomment the cp command and comment out the ln command within the ccp function.
- Error Messages: The script writes error messages to
stderr but does not write them to any files.
- Conditional Operations: Some write operations depend on the detected operating system and available executables (
bash, zsh, etc.).
Conclusion
The script primarily writes executable binaries or their symbolic links to specific subdirectories within the ZAPRET_BASE directory. The exact locations depend on the detected architecture and operating system. By understanding these operations, you can better manage, troubleshoot, or modify the installation process as needed.