PERC-CLI-Install/install_perccli.sh

193 lines
8.2 KiB
Bash

#!/bin/bash
# ------------------------------------------------------------------------------------------------
# Script to download, extract, convert, and install the Dell PERCCLI utility.
# Optimized for Debian-based systems (like Proxmox) that need to convert the RPM package.
# Note: This script assumes execution as 'root' (no 'sudo' needed).
# ------------------------------------------------------------------------------------------------
# --- Configuration ---
PERCCLI_URL="https://dl.dell.com/FOLDER13074167M/1/PERCCLI_7.3208.0_Linux_A01.tar.gz"
ARCHIVE_NAME="PERCCLI_7.3208.0_Linux_A01.tar.gz"
TEMP_DIR="perccli_install_temp"
# Default path for the executable, will be updated dynamically if necessary
EXECUTABLE_PATH=""
SYMLINK_PATH="/usr/local/bin/perccli"
echo "Starting PERCCLI installation script..."
echo "Target URL: $PERCCLI_URL"
# --- Clean Start Logic: Remove previous temporary files/directories if they exist ---
if [ -d "$TEMP_DIR" ]; then
echo "Found old temporary directory '$TEMP_DIR'. Removing for a clean start."
rm -rf "$TEMP_DIR"
fi
if [ -f "$ARCHIVE_NAME" ]; then
echo "Found old archive '$ARCHIVE_NAME'. Removing for a clean start."
rm -f "$ARCHIVE_NAME"
fi
# ----------------------------------------------------------------------------------
# 1. Download the archive
echo "1. Downloading $ARCHIVE_NAME..."
# Using wget with User-Agent to prevent 403 errors
wget --no-check-certificate --user-agent="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1)" "$PERCCLI_URL" -O "$ARCHIVE_NAME"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to download the file. Check your network connection and ensure 'wget' is installed."
exit 1
fi
echo "Download complete."
# 2. Extract the archive
echo "2. Extracting the archive..."
mkdir -p "$TEMP_DIR"
tar -xzf "$ARCHIVE_NAME" -C "$TEMP_DIR"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to extract the archive. The file may be incomplete or corrupted."
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Extraction complete to $TEMP_DIR."
# 3. Locate the installation package (Prioritizing RPM since the official package is RPM)
PACKAGE_FILE=$(find "$TEMP_DIR" -type f \( -name "*.rpm" -o -name "*.deb" \) | head -n 1)
if [ -z "$PACKAGE_FILE" ]; then
echo "ERROR: Could not find any .deb or .rpm installation package within the archive."
echo "Please navigate to '$TEMP_DIR' and install the appropriate package manually."
exit 1
fi
echo "3. Found package file: $PACKAGE_FILE"
# 4. Install the package
echo "4. Attempting to install the package."
INSTALL_SUCCESS=1 # Default to failure
if [[ "$PACKAGE_FILE" == *.deb ]]; then
echo "Detected native DEB package. Trying to install with 'dpkg -i'..."
if command -v dpkg >/dev/null 2>&1; then
dpkg -i "$PACKAGE_FILE"
INSTALL_SUCCESS=$?
else
echo "ERROR: 'dpkg' command not found. Cannot proceed."
fi
elif [[ "$PACKAGE_FILE" == *.rpm ]]; then
echo "Detected RPM package. As this is a Debian-based system (Proxmox), we will use 'alien' to convert it to a DEB package."
if command -v dpkg >/dev/null 2>&1; then
if command -v alien >/dev/null 2>&1; then
echo "Attempting to convert $PACKAGE_FILE to .deb using 'alien --scripts' to ensure post-install setup runs..."
# CRITICAL FIX: Use --scripts to prevent skipping post-installation setup
alien -d --scripts "$PACKAGE_FILE"
if [ $? -eq 0 ]; then
echo "Conversion successful. Searching for generated .deb file..."
# Robustly search for the .deb file generated by alien
PACKAGE_NAME_ROOT=$(basename "$PACKAGE_FILE" | cut -d'-' -f1)
NEW_DEB_FILE=$(find . -maxdepth 1 -name "${PACKAGE_NAME_ROOT}_*.deb" | head -n 1)
if [ -f "$NEW_DEB_FILE" ]; then
echo "Found converted file: $NEW_DEB_FILE. Installing..."
# Using dpkg -i to install the generated package
dpkg -i "$NEW_DEB_FILE"
INSTALL_SUCCESS=$?
# Clean up the converted .deb file
rm -f "$NEW_DEB_FILE"
else
echo "ERROR: Conversion succeeded, but could not locate the newly created .deb file for installation."
fi
else
echo "ERROR: 'alien' conversion failed. Please check the 'alien' output above for details."
fi
else
echo "ERROR: 'alien' command not found. This tool is required to convert the RPM package for your system."
echo "Please run: apt update && apt install alien -y"
fi
else
echo "FATAL ERROR: 'dpkg' (Debian Package Manager) is not found. Cannot proceed with installation."
fi
fi
# 5. Final Setup and Cleanup
if [ $INSTALL_SUCCESS -eq 0 ]; then
echo ""
echo "5. Installation successful. Performing final setup and cleanup."
# --- ULTIMATE DYNAMIC PATH DISCOVERY ---
# Loop through all files installed by the 'perccli' package and stop at the first one that is executable.
echo "Attempting to find the executable by checking all files installed by 'perccli'..."
# Get the list of all files installed by the package
INSTALLED_FILES=$(dpkg -L perccli 2>/dev/null)
# Iterate and find the executable file
for FILE_PATH in $INSTALLED_FILES; do
# Check if the path is a regular file and is executable
if [ -f "$FILE_PATH" ] && [ -x "$FILE_PATH" ]; then
EXECUTABLE_PATH="$FILE_PATH"
break
fi
done
# Fallback: If no executable file was found, find the largest file that might be the binary
if [ -z "$EXECUTABLE_PATH" ]; then
echo "WARNING: No executable file found in the package list. Re-checking for common binaries and applying permissions if necessary..."
# Aggressive search for non-executable files that are likely the binary
# We search in common places for files that look like binaries and are NOT directories.
POTENTIAL_BINARY=$(find /opt /usr/local/sbin /usr/sbin /usr/bin -type f \( -name perccli -o -name storcli -o -name MegaCli \) 2>/dev/null | head -n 1)
if [ -n "$POTENTIAL_BINARY" ]; then
EXECUTABLE_PATH="$POTENTIAL_BINARY"
# Since it wasn't executable before, we assume it needs permission
echo "Found non-executable potential binary: $EXECUTABLE_PATH. Applying execute permissions."
chmod +x "$EXECUTABLE_PATH"
fi
fi
# --- END ULTIMATE DYNAMIC PATH DISCOVERY ---
# Finalize path or fail
if [ -n "$EXECUTABLE_PATH" ] && [ -f "$EXECUTABLE_PATH" ]; then
echo "Dynamically found executable at: $EXECUTABLE_PATH"
else
echo "FATAL ERROR: Could not locate *any* related binary after checking all installed files."
echo "The package installation is likely broken due to the RPM conversion process."
INSTALL_SUCCESS=1 # Set installation to fail state to skip cleanup/symlink
fi
# Proceed with cleanup and symlinking only if the executable was found
if [ $INSTALL_SUCCESS -eq 0 ]; then
# Add symbolic link to the path (Fixes 'command not found')
# Symlink is always named 'perccli' but points to the actual binary
if [ ! -L "$SYMLINK_PATH" ] || [ -L "$SYMLINK_PATH" ] && [ "$(readlink -f "$SYMLINK_PATH")" != "$EXECUTABLE_PATH" ]; then
ln -sf "$EXECUTABLE_PATH" "$SYMLINK_PATH"
echo "Created symbolic link at $SYMLINK_PATH pointing to $EXECUTABLE_PATH."
fi
rm -f "$ARCHIVE_NAME"
rm -rf "$TEMP_DIR"
echo "PERCCLI tool is installed and configured. Cleaning up temporary files."
echo "---"
echo "Verification Command:"
echo "perccli /c0 show"
echo "---"
else
# If dynamic discovery failed, we skip cleanup and leave temporary files for debugging.
echo "Installation failed due to missing files. Temporary files retained."
fi
else
echo ""
echo "5. Installation failed. The archive '$ARCHIVE_NAME' and temporary directory '$TEMP_DIR' are retained for manual debugging."
echo "The package file is located at: $PACKAGE_FILE"
fi
# ------------------------------------------------------------------------------------------------