Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib_install): Disable file system translation in checkinstall during dependency installation (fixes #642). #644

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented Dec 24, 2024

Description

  1. Disable file system translation in checkinstall during dependency installation.
  2. Streamline install commands composition.

Validation performed

  1. Entered an environment where GCC 13 is installed (e.g., Ubuntu 2404)
  2. Followed https://docs.yscope.com/clp/main/dev-guide/building-package.html#:~:text=Install%20CLP%20core%E2%80%99s%20dependencies to install CLP's core dependencies.
  3. Observed successful installations for all dependencies.

Summary by CodeRabbit

  • New Features

    • Enhanced command execution structure for installation scripts, improving flexibility and clarity.
    • Added support for checkinstall with structured command arguments across multiple scripts.
  • Bug Fixes

    • Improved error handling and checks for the existence of necessary directories and files during installation.
  • Refactor

    • Replaced privileged_command_prefix with install_cmd_args array in multiple scripts for better command management.

Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

The pull request involves modifications to multiple library installation scripts in the components/core/tools/scripts/lib_install/ directory. The primary changes focus on refactoring command execution logic across various scripts, replacing the privileged_command_prefix variable with an install_cmd_args array. This approach provides more flexible and clearer command construction, particularly for installation processes involving checkinstall and potential sudo elevation.

Changes

File Change Summary
fmtlib.sh, libarchive.sh, lz4.sh, mariadb-connector-c.sh, msgpack.sh, spdlog.sh, zstandard.sh - Replaced privileged_command_prefix with install_cmd_args array
- Added dynamic sudo handling
- Improved checkinstall command construction
- Used array expansion for command execution
mongocxx.sh - Added specific checkinstall flags: --default, --fstrans=no, --nodoc
- Removed -y flag from checkinstall command

Possibly Related PRs

Suggested Reviewers

  • kirkrodrigues

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (10)
components/core/tools/scripts/lib_install/mongocxx.sh (1)

88-90: The changes effectively address the filesystem translation issue.

The addition of these checkinstall flags aligns well with the PR objectives:

  • --fstrans=no properly disables filesystem translation
  • --default improves automation
  • --nodoc reduces package size

Consider adding a comment to explain the purpose of these flags:

  install_cmd_args+=(
    checkinstall
+   # Accept defaults, disable filesystem translation, and skip documentation
    --default
    --fstrans=no
    --nodoc
components/core/tools/scripts/lib_install/fmtlib.sh (2)

78-87: Document the purpose of disabling filesystem translation

While the implementation is correct, please add a comment explaining why --fstrans=no is necessary. This will help future maintainers understand the rationale behind this specific configuration.

Add a comment like:

  install_cmd_args+=(
    checkinstall
    --default
+   # Disable filesystem translation to prevent path manipulation issues during installation
    --fstrans=no
    --nodoc

89-92: Add error handling for installation command

Consider adding error handling to provide better feedback if the installation fails.

Here's a suggested improvement:

 install_cmd_args+=(
   make install
 )
-"${install_cmd_args[@]}"
+if ! "${install_cmd_args[@]}"; then
+  echo "Error: Installation failed"
+  exit 1
+fi
components/core/tools/scripts/lib_install/zstandard.sh (1)

89-92: Consider adding error handling for installation command

While the command construction is clean, consider adding error handling for the make install command. This could help diagnose installation failures more effectively.

 install_cmd_args+=(
   make install
 )
-"${install_cmd_args[@]}"
+if ! "${install_cmd_args[@]}"; then
+  echo "Error: Installation failed"
+  exit 1
+fi
components/core/tools/scripts/lib_install/msgpack.sh (2)

81-86: Consider adding error handling for failed builds

While the command construction is correct, consider adding error handling to capture and report build failures more gracefully.

Add error handling like this:

-"${install_cmd_args[@]}"
+if ! "${install_cmd_args[@]}"; then
+  echo "Error: Installation failed" >&2
+  exit 1
+fi

89-89: Consider adding trap-based cleanup

To ensure cleanup occurs even if the script fails, consider adding a trap-based cleanup mechanism.

Add this near the start of the script:

+cleanup() {
+  rm -rf "$temp_dir"
+}
+trap cleanup EXIT
components/core/tools/scripts/lib_install/mariadb-connector-c.sh (1)

93-98: Add comment explaining the rsync operation

The command construction is correct, but it would be helpful to document why rsync is used here instead of a simple copy operation.

Add a comment before the command:

+# Use rsync to preserve file attributes and perform an atomic copy
 install_cmd_args+=(
   rsync
   -a .
   "${install_dir}/"
 )
components/core/tools/scripts/lib_install/spdlog.sh (2)

85-94: Consider enhancing package metadata handling

While the checkinstall configuration is good, consider these improvements:

  1. Add version format validation before using it in --pkgversion
  2. Consider adding alternative package names in --provides for better compatibility

Example validation:

+ if ! [[ "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+   echo "Error: Version must be in format X.Y.Z"
+   exit 1
+ fi
  install_cmd_args+=(
    checkinstall
    --default
    --fstrans=no
    --nodoc
    --pkgname "${package_name}"
    --pkgversion "${version}"
-   --provides "${package_name}"
+   --provides "${package_name}, libspdlog"
    --pakdir "${deb_output_dir}"
  )

96-99: Add error handling for the installation command

While the command execution is correct, consider adding error handling to catch and report installation failures more gracefully.

+ set +e
  "${install_cmd_args[@]}"
+ install_status=$?
+ set -e
+ if [ $install_status -ne 0 ]; then
+   echo "Error: Installation failed with status $install_status"
+   exit $install_status
+ fi
components/core/tools/scripts/lib_install/lz4.sh (1)

86-89: Consider adding error handling for installation command

While the array expansion is implemented correctly, consider adding error handling to capture and report installation failures more gracefully.

+set +e
 "${install_cmd_args[@]}"
+install_status=$?
+set -e
+if [ $install_status -ne 0 ]; then
+  echo "Installation failed with status $install_status"
+  exit $install_status
+fi
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 329edf6 and 7564ff5.

📒 Files selected for processing (8)
  • components/core/tools/scripts/lib_install/fmtlib.sh (2 hunks)
  • components/core/tools/scripts/lib_install/libarchive.sh (2 hunks)
  • components/core/tools/scripts/lib_install/lz4.sh (2 hunks)
  • components/core/tools/scripts/lib_install/mariadb-connector-c.sh (2 hunks)
  • components/core/tools/scripts/lib_install/mongocxx.sh (1 hunks)
  • components/core/tools/scripts/lib_install/msgpack.sh (2 hunks)
  • components/core/tools/scripts/lib_install/spdlog.sh (2 hunks)
  • components/core/tools/scripts/lib_install/zstandard.sh (2 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
components/core/tools/scripts/lib_install/mariadb-connector-c.sh

[warning] 44-44: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)

🔇 Additional comments (15)
components/core/tools/scripts/lib_install/mongocxx.sh (1)

88-90: Verify the impact of disabling filesystem translation.

Let's ensure that disabling filesystem translation doesn't cause issues with package installation paths.

✅ Verification successful

Disabling filesystem translation is a consistent pattern across library installations

The --fstrans=no flag is consistently used across multiple library installation scripts in the codebase, including spdlog, zstandard, mariadb-connector-c, lz4, msgpack, libarchive, fmtlib, and mongocxx. This standardized approach suggests it's a deliberate design choice for the build system. No installation path issues related to this flag were found in the logs or codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any existing filesystem translation issues or related bugs
# in the MongoDB C++ driver installation

# Search for related issues in the codebase
rg -i "fstrans|filesystem.translation" 

# Check if other packages use filesystem translation
fd -t f . components/core/tools/scripts/lib_install/ -x grep -l "fstrans"

# Look for any installation path related issues
rg -i "installation.path|install.prefix|prefix" components/core/tools/scripts/lib_install/

Length of output: 1784

components/core/tools/scripts/lib_install/fmtlib.sh (1)

41-44: LGTM: Improved command construction using array

The refactoring to use an array for command construction is a good practice. It's more maintainable and safer than string concatenation, especially when dealing with arguments that might contain spaces.

components/core/tools/scripts/lib_install/libarchive.sh (3)

40-43: Excellent improvement in privilege handling!

The transition to using an array for command construction is a robust improvement over string concatenation. The privilege check is properly implemented with a fallback mechanism.


89-92: Well-structured command execution!

The array-based command construction and execution using proper expansion syntax "${install_cmd_args[@]}" is a robust approach that correctly handles arguments with spaces.


78-87: Verify documentation requirements and filesystem translation impact

The addition of --fstrans=no aligns with the PR objective to disable filesystem translation. However, two points need verification:

  1. The --nodoc flag skips documentation installation. Please verify this complies with your project's packaging guidelines.
  2. Ensure disabling filesystem translation doesn't affect package installation on systems with non-standard filesystem layouts.

Run this verification script:

✅ Verification successful

Checkinstall configuration is consistent across the codebase

The --nodoc and --fstrans=no flags are used consistently across all library installation scripts in the codebase, including zstandard, spdlog, msgpack, mongocxx, lz4, fmtlib, mariadb-connector-c, and libarchive. This demonstrates a standardized approach to package creation where:

  1. Documentation is consistently omitted across all packages
  2. Filesystem translation is disabled uniformly
  3. The same checkinstall configuration pattern is followed project-wide

Since this is an established pattern across the entire codebase, both flags align with the project's packaging standards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if any other packages in the repository use different checkinstall flags
# or handle documentation differently

rg -g '*.sh' 'checkinstall.*--nodoc' .
rg -g '*.sh' 'checkinstall.*--fstrans' .

Length of output: 83


Script:

#!/bin/bash
# Let's try a broader search for checkinstall usage patterns
rg -g '*.sh' 'checkinstall' -B 2 -A 5 .

# Also search for any package installation or documentation related patterns
rg -g '*.sh' 'install.*doc' -B 2 -A 2 .

Length of output: 14212

components/core/tools/scripts/lib_install/zstandard.sh (2)

41-44: Excellent improvement to command handling!

The transition from string-based command prefix to array-based command construction is a robust improvement. The privilege check is well-implemented with proper fallback to id -u.


78-87: Verify the impact of disabling filesystem translation

The addition of --fstrans=no to checkinstall addresses the core issue. The command construction is well-organized using array append operations.

Let's verify if this change is consistent across other library installation scripts:

✅ Verification successful

The --fstrans=no flag is consistently implemented across all installation scripts

The verification shows that all library installation scripts that use checkinstall have been updated with the --fstrans=no flag, including:

  • fmtlib.sh
  • libarchive.sh
  • lz4.sh
  • mariadb-connector-c.sh
  • mongocxx.sh
  • msgpack.sh
  • spdlog.sh
  • zstandard.sh

The command construction is identical across all scripts, ensuring consistent behaviour.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other installation scripts also disable filesystem translation
rg --type bash "checkinstall.*--fstrans" components/core/tools/scripts/lib_install/

Length of output: 114


Script:

#!/bin/bash
# Search for checkinstall usage in installation scripts
rg "checkinstall" components/core/tools/scripts/lib_install/

Length of output: 3626


Script:

#!/bin/bash
# Let's examine the checkinstall command construction in other library installation scripts
for file in components/core/tools/scripts/lib_install/*.sh; do
  echo "=== $file ==="
  rg -A 10 "install_cmd_args\+=" "$file" || true
done

Length of output: 8080

components/core/tools/scripts/lib_install/msgpack.sh (2)

39-42: LGTM: Improved command construction approach

The switch to an array-based command construction is a more robust approach, properly handling privilege elevation while maintaining security checks.


70-79: Verify the impact of disabling filesystem translation

The addition of --fstrans=no aligns with the PR objective. The array-based command construction improves readability and maintainability.

Let's verify this change doesn't affect other dependent packages:

✅ Verification successful

The --fstrans=no flag is consistently used across all installation scripts

The verification shows that all library installation scripts in the codebase use the same --fstrans=no flag with checkinstall. This consistent usage across fmtlib, spdlog, msgpack, mongocxx, mariadb-connector-c, libarchive, lz4, and zstandard installations indicates this is an established pattern and the change aligns with the existing codebase standards.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any existing packages that might be affected by --fstrans=no

# Search for other checkinstall usage in installation scripts
rg -l 'checkinstall' --type sh

# Look for any existing .deb packages that might have been created with different fstrans settings
fd -e deb . | xargs -I {} dpkg -I {} | grep -B2 'msgpack'

Length of output: 886


Script:

#!/bin/bash
# Let's check the usage of checkinstall in other installation scripts to see if they handle fstrans differently

# Check the content of other installation scripts that use checkinstall
for file in $(rg -l 'checkinstall' --type sh); do
  echo "=== $file ==="
  rg -A 5 'checkinstall' "$file"
done

Length of output: 6342

components/core/tools/scripts/lib_install/mariadb-connector-c.sh (1)

82-91: LGTM! Verify documentation for --fstrans flag

The addition of --fstrans=no aligns with the PR objective to disable filesystem translation. The command construction is clean and well-structured.

Let's verify if this flag is documented:

components/core/tools/scripts/lib_install/spdlog.sh (2)

48-51: LGTM: Robust privilege checking and command array initialization

The implementation uses a clean array-based approach for command construction and includes a reliable privilege check with proper fallback.


88-88: Verify consistent --fstrans=no usage across installation scripts

Let's ensure this change is applied consistently across all library installation scripts.

✅ Verification successful

Let me check the actual usage of checkinstall in these scripts to verify if they need the --fstrans=no flag.


The --fstrans=no flag is already consistently used across all installation scripts

The verification shows that all library installation scripts that use checkinstall already include the --fstrans=no flag:

  • zstandard.sh
  • mongocxx.sh
  • mariadb-connector-c.sh
  • lz4.sh
  • libarchive.sh
  • fmtlib.sh
  • msgpack.sh
  • spdlog.sh
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if other installation scripts need similar changes
echo "Checking other installation scripts for checkinstall usage..."
rg -l 'checkinstall' components/core/tools/scripts/lib_install/

Length of output: 800


Script:

#!/bin/bash
# Check checkinstall command usage in installation scripts
echo "Checking checkinstall command usage in installation scripts..."
rg -B2 -A2 'checkinstall' --type sh components/core/tools/scripts/lib_install/ | grep -v "ubuntu-.*install-prebuilt-packages.sh"

Length of output: 8450

components/core/tools/scripts/lib_install/lz4.sh (3)

41-44: Excellent improvement to privilege handling!

The switch from string concatenation to an array-based approach for command construction is a solid improvement. This makes the code more maintainable and less prone to shell injection issues.


75-84: Verify impact of checkinstall flags

The addition of --fstrans=no aligns with the PR objective. However, let's verify the implications of using --default with these other flags.

✅ Verification successful

Checkinstall configuration is consistent across the codebase

The checkinstall flags used in lz4.sh (--default, --fstrans=no, --nodoc) are consistently used across all installation scripts in the codebase, including zstandard, mariadb-connector-c, libarchive, mongocxx, spdlog, fmtlib, and msgpack. This standardized approach confirms that the configuration is well-established and safe to use.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if any other installation scripts in the codebase use different checkinstall flags
# that might conflict with or complement our configuration

# Search for checkinstall usage patterns
rg --type bash 'checkinstall.*--' components/core/tools/scripts/lib_install/

Length of output: 107


Script:

#!/bin/bash
# Let's try without specifying file type since rg doesn't recognize 'bash'
rg 'checkinstall.*--' components/core/tools/scripts/lib_install/

# Also search for any other shell scripts that might contain checkinstall configurations
fd . components/core/tools/scripts/lib_install/ -e sh -x grep -l "checkinstall"

Length of output: 750


Script:

#!/bin/bash
# Let's examine the checkinstall configurations in these files
for file in zstandard.sh mariadb-connector-c.sh libarchive.sh mongocxx.sh spdlog.sh fmtlib.sh msgpack.sh; do
    echo "=== $file ==="
    grep -A 5 -B 5 "checkinstall" "components/core/tools/scripts/lib_install/$file"
done

Length of output: 4456


Line range hint 1-89: Verify security considerations

The script performs several sensitive operations. Let's verify:

  1. The integrity of downloaded content
  2. The safety of make commands
  3. The implications of disabling filesystem translation

Comment on lines +40 to +44
install_cmd_args=()
if [ ${EUID:-$(id -u)} -ne 0 ] ; then
sudo echo "Script can elevate privileges."
privileged_command_prefix="${privileged_command_prefix} sudo"
privileged_command_prefix="sudo"
install_cmd_args+=(${privileged_command_prefix})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor privilege handling for consistency

The privilege handling needs improvement:

  1. The script still uses privileged_command_prefix variable in multiple places (e.g., lines 78 and 102) after switching to install_cmd_args
  2. There's a potential word splitting vulnerability when adding sudo to the array

Apply these changes:

 install_cmd_args=()
 if [ ${EUID:-$(id -u)} -ne 0 ] ; then
   sudo echo "Script can elevate privileges."
-  privileged_command_prefix="sudo"
-  install_cmd_args+=(${privileged_command_prefix})
+  install_cmd_args+=("sudo")

Then replace remaining ${privileged_command_prefix} usages with "${install_cmd_args[@]}".

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 44-44: Quote to prevent word splitting/globbing, or split robustly with mapfile or read -a.

(SC2206)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant