feat: Add comprehensive Plex recovery validation script

- Introduced `validate-plex-recovery.sh` for validating Plex database recovery.
- Implemented checks for service status, database integrity, web interface accessibility, API functionality, and recent logs.
- Added detailed recovery summary and next steps for users.

fix: Improve Debian patching script for compatibility

- Enhanced `debian-patches.sh` to securely download and execute bootstrap scripts.
- Updated package mapping logic and ensured proper permissions for patched files.

fix: Update Docker test scripts for better permission handling

- Modified `run-docker-tests.sh` to set appropriate permissions on logs directory.
- Ensured log files have correct permissions after test runs.

fix: Enhance setup scripts for secure installations

- Updated `setup.sh` to securely download and execute installation scripts for zoxide and nvm.
- Improved error handling for failed downloads.

fix: Refine startup script for log directory permissions

- Adjusted `startup.sh` to set proper permissions for log directories and files.

chore: Revamp update-containers.sh for better error handling and logging

- Rewrote `update-containers.sh` to include detailed logging and error handling.
- Added validation for Docker image names and improved overall script robustness.
This commit is contained in:
Peter Wood
2025-06-05 07:22:28 -04:00
parent 8b514ac0b2
commit 0123fc6007
25 changed files with 4407 additions and 608 deletions

View File

@@ -85,27 +85,27 @@ echo -e "${BLUE}Applying Debian-specific patches...${NC}"
map_package() {
local ubuntu_pkg="$1"
local debian_pkg
# Look for the package in the mapping file
if [ -f "$PATCH_DIR/debian-packages.map" ]; then
debian_pkg=$(grep -v "^#" "$PATCH_DIR/debian-packages.map" | grep "^$ubuntu_pkg|" | cut -d'|' -f2)
fi
# If not found or empty, use the original name
if [ -z "$debian_pkg" ]; then
debian_pkg="$ubuntu_pkg"
fi
echo "$debian_pkg"
}
# Patch the packages.list file if it exists
if [ -f "$HOME/shell/setup/packages.list" ]; then
echo -e "${YELLOW}Patching packages.list for Debian compatibility...${NC}"
# Create a temporary patched file
temp_file=$(mktemp)
# Process each line
while IFS= read -r line; do
# Skip comments and empty lines
@@ -113,17 +113,17 @@ if [ -f "$HOME/shell/setup/packages.list" ]; then
echo "$line" >> "$temp_file"
continue
fi
# Map the package name
debian_pkg=$(map_package "$line")
echo "$debian_pkg" >> "$temp_file"
done < "$HOME/shell/setup/packages.list"
# Backup original and replace with patched version
cp "$HOME/shell/setup/packages.list" "$HOME/shell/setup/packages.list.orig"
mv "$temp_file" "$HOME/shell/setup/packages.list"
echo -e "${GREEN}Patched packages.list for Debian compatibility${NC}"
fi
@@ -135,10 +135,10 @@ if ! grep -q "contrib" /etc/apt/sources.list; then
echo -e "${YELLOW}Adding contrib and non-free repositories...${NC}"
# Create a backup of the original sources.list
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
# Add contrib and non-free to each deb line
sudo sed -i 's/main$/main contrib non-free non-free-firmware/g' /etc/apt/sources.list
echo -e "${GREEN}Added contrib and non-free repositories${NC}"
fi
@@ -171,9 +171,17 @@ if [ -x "$PATCH_DIR/apply-debian-patches.sh" ]; then
"$PATCH_DIR/apply-debian-patches.sh"
fi
# Download and run the bootstrap script
# Download and run the bootstrap script securely
echo -e "${BLUE}Running bootstrap script...${NC}"
curl -s https://raw.githubusercontent.com/acedanger/shell/main/bootstrap.sh | bash
TEMP_BOOTSTRAP=$(mktemp)
if curl -s https://raw.githubusercontent.com/acedanger/shell/main/bootstrap.sh -o "$TEMP_BOOTSTRAP"; then
echo -e "${BLUE}Bootstrap script downloaded, executing...${NC}"
bash "$TEMP_BOOTSTRAP"
rm -f "$TEMP_BOOTSTRAP"
else
echo -e "${RED}ERROR: Failed to download bootstrap script${NC}"
exit 1
fi
# Apply patches again after bootstrap (in case packages.list was just downloaded)
if [ -x "$PATCH_DIR/apply-debian-patches.sh" ]; then

View File

@@ -33,7 +33,8 @@ fi
# Ensure the logs directory is writable
if [ ! -w "$LOGS_DIR" ]; then
echo -e "${YELLOW}Setting permissions on logs directory...${NC}"
chmod -R 777 "$LOGS_DIR" || {
chmod -R 755 "$LOGS_DIR" && \
find "$LOGS_DIR" -type f -exec chmod 644 {} \; || {
echo -e "${RED}Failed to set write permissions on logs directory!${NC}"
exit 1
}
@@ -69,32 +70,33 @@ run_ubuntu_test() {
# Create the logs directory if it doesn't exist
local log_dir="$(pwd)/logs"
mkdir -p "$log_dir" || true
# Use sudo for chmod only if necessary
if [ ! -w "$log_dir" ]; then
echo -e "${YELLOW}Attempting to fix permissions with sudo...${NC}"
sudo chmod -R 777 "$log_dir" 2>/dev/null || {
sudo chmod -R 755 "$log_dir" 2>/dev/null && \
sudo find "$log_dir" -type f -exec chmod 644 {} \; 2>/dev/null || {
echo -e "${YELLOW}Could not change permissions with sudo, continuing anyway...${NC}"
}
fi
echo -e "${YELLOW}Logs will be saved to: $log_dir${NC}"
echo -e "${YELLOW}Building Ubuntu test container...${NC}"
docker build --target ubuntu-test -t shell-test:ubuntu .
echo -e "${GREEN}Running tests with package installation...${NC}"
# Create a timestamp for this test run
TEST_TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
echo -e "${YELLOW}Test run timestamp: $TEST_TIMESTAMP${NC}"
# Run container with proper volume mount and add environment variable for timestamp
docker run --rm -it \
-e TEST_TIMESTAMP="$TEST_TIMESTAMP" \
-e CONTAINER_TYPE="ubuntu" \
-v "$log_dir:/logs:z" \
shell-test:ubuntu
# Check if logs were created
if ls "$log_dir"/setup-test-*"$TEST_TIMESTAMP"* &>/dev/null 2>&1; then
echo -e "${GREEN}Test logs successfully created in host directory${NC}"
@@ -104,7 +106,7 @@ run_ubuntu_test() {
echo -e "${YELLOW}Contents of log directory:${NC}"
ls -la "$log_dir" || echo "Cannot list directory contents"
fi
echo -e "${BLUE}Test completed. Check logs in $log_dir directory${NC}"
}
@@ -114,32 +116,33 @@ run_debian_test() {
# Create the logs directory if it doesn't exist
local log_dir="$(pwd)/logs"
mkdir -p "$log_dir" || true
# Use sudo for chmod only if necessary
if [ ! -w "$log_dir" ]; then
echo -e "${YELLOW}Attempting to fix permissions with sudo...${NC}"
sudo chmod -R 777 "$log_dir" 2>/dev/null || {
sudo chmod -R 755 "$log_dir" 2>/dev/null && \
sudo find "$log_dir" -type f -exec chmod 644 {} \; 2>/dev/null || {
echo -e "${YELLOW}Could not change permissions with sudo, continuing anyway...${NC}"
}
fi
echo -e "${YELLOW}Logs will be saved to: $log_dir${NC}"
echo -e "${YELLOW}Building Debian test container...${NC}"
docker build --target debian-test -t shell-test:debian .
echo -e "${GREEN}Running tests with package installation...${NC}"
# Create a timestamp for this test run
TEST_TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
echo -e "${YELLOW}Test run timestamp: $TEST_TIMESTAMP${NC}"
# Run container with proper volume mount and add environment variable for timestamp
docker run --rm -it \
-e TEST_TIMESTAMP="$TEST_TIMESTAMP" \
-e CONTAINER_TYPE="debian" \
-v "$log_dir:/logs:z" \
shell-test:debian
# Check if logs were created
if ls "$log_dir"/setup-test-*"$TEST_TIMESTAMP"* &>/dev/null 2>&1; then
echo -e "${GREEN}Test logs successfully created in host directory${NC}"
@@ -149,7 +152,7 @@ run_debian_test() {
echo -e "${YELLOW}Contents of log directory:${NC}"
ls -la "$log_dir" || echo "Cannot list directory contents"
fi
echo -e "${BLUE}Test completed. Check logs in $log_dir directory${NC}"
}
@@ -158,7 +161,7 @@ run_full_test() {
local distro=$1
local tag_name=$(echo $distro | sed 's/:/-/g') # Replace colon with hyphen for tag
echo -e "\n${BLUE}=== Running full bootstrap test in $distro container ===${NC}"
# Create a Dockerfile for full test
cat > Dockerfile.fulltest <<EOF
FROM $distro
@@ -198,7 +201,7 @@ EOF
mkdir -p "$(pwd)/logs"
docker build -f Dockerfile.fulltest -t shell-full-test:$tag_name .
docker run --rm -it -v "$(pwd)/logs:/logs" shell-full-test:$tag_name
# Clean up
rm Dockerfile.fulltest
}

View File

@@ -549,7 +549,15 @@ fi
# Install zoxide
echo -e "${YELLOW}Installing zoxide...${NC}"
if ! command -v zoxide &> /dev/null; then
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
TEMP_ZOXIDE=$(mktemp)
if curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh -o "$TEMP_ZOXIDE"; then
echo -e "${YELLOW}Zoxide installer downloaded, executing...${NC}"
bash "$TEMP_ZOXIDE"
rm -f "$TEMP_ZOXIDE"
else
echo -e "${RED}ERROR: Failed to download zoxide installer${NC}"
exit 1
fi
# Ensure .local/bin is in PATH
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
@@ -561,7 +569,15 @@ fi
# Install nvm (Node Version Manager)
echo -e "${YELLOW}Installing nvm...${NC}"
if [ ! -d "$HOME/.nvm" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
TEMP_NVM=$(mktemp)
if curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh -o "$TEMP_NVM"; then
echo -e "${YELLOW}NVM installer downloaded, executing...${NC}"
bash "$TEMP_NVM"
rm -f "$TEMP_NVM"
else
echo -e "${RED}ERROR: Failed to download nvm installer${NC}"
exit 1
fi
fi
# Load nvm regardless of whether it was just installed or already existed

View File

@@ -43,7 +43,9 @@ if [ -d "/logs" ]; then
echo "- Setting permissions on /logs directory..."
sudo chown -R $(whoami):$(whoami) /logs 2>/dev/null || echo -e "${YELLOW}Failed to set ownership${NC}"
sudo chmod -R 777 /logs 2>/dev/null || echo -e "${YELLOW}Failed to set permissions${NC}"
sudo chmod -R 755 /logs 2>/dev/null || echo -e "${YELLOW}Failed to set directory permissions${NC}"
# Set appropriate permissions for log files (644)
sudo find /logs -type f -exec chmod 644 {} \; 2>/dev/null || echo -e "${YELLOW}Failed to set file permissions${NC}"
# Verify permissions are correct
if [ -w "/logs" ]; then
@@ -62,8 +64,10 @@ if [ -d "/logs" ]; then
else
echo -e "- Logs directory: ${YELLOW}Not found${NC}"
echo "- Creating /logs directory..."
if sudo mkdir -p /logs && sudo chown -R $(whoami):$(whoami) /logs && sudo chmod -R 777 /logs; then
if sudo mkdir -p /logs && sudo chown -R $(whoami):$(whoami) /logs && sudo chmod -R 755 /logs; then
echo -e "- Created logs directory with proper permissions: ${GREEN}Success${NC}"
# Ensure future log files get proper permissions
sudo find /logs -type f -exec chmod 644 {} \; 2>/dev/null || true
else
echo -e "- Creating logs directory: ${RED}Failed${NC}"
echo "Warning: Logs will be saved inside container only"