diff --git a/backend/src/routes/updates.rs b/backend/src/routes/updates.rs index 6488d299..b287db7d 100644 --- a/backend/src/routes/updates.rs +++ b/backend/src/routes/updates.rs @@ -144,28 +144,36 @@ pub async fn install_update( } // Find the update script - try multiple locations - let mut possible_paths: Vec = - vec![std::path::PathBuf::from("/opt/csf-core/scripts/update.sh")]; + let mut possible_paths: Vec = vec![ + // Production path (daemon service) + std::path::PathBuf::from("/opt/csf-core/scripts/update.sh"), + ]; + // Development paths if let Ok(dir) = std::env::current_dir() { + // When running from /opt/csf-core/backend possible_paths.push(dir.join("../scripts/update.sh")); + // When running from project root possible_paths.push(dir.join("scripts/update.sh")); + // When running from backend directory + possible_paths.push(dir.join("../../scripts/update.sh")); } tracing::debug!("Searching for update script in: {:?}", possible_paths); - let script_path = possible_paths - .iter() - .find(|&p: &&std::path::PathBuf| p.exists()) - .ok_or_else(|| { + let script_path = match possible_paths.iter().find(|&p| p.exists()) { + Some(path) => path.clone(), + None => { let error_msg = format!( - "Update script not found in any expected location. Searched paths: {:?}", + "Update script not found in any expected location. Searched paths: {:?}. Note: Updates can only be performed in production installations, not during local development.", possible_paths ); tracing::error!("{}", error_msg); - AppError::InternalError(error_msg) - })? - .clone(); + return Err(AppError::InternalError( + "Update functionality is only available in production installations. The update script was not found on this system.".to_string() + )); + } + }; tracing::info!("Found update script at: {:?}", script_path); diff --git a/scripts/install.sh b/scripts/install.sh index bad4de17..466fc59a 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -424,6 +424,18 @@ download_release() { return fi + # Download update script + local update_script_url="https://raw.githubusercontent.com/${GITHUB_REPO}/main/scripts/update.sh" + print_step "Download Update Script..." + + mkdir -p "$INSTALL_DIR/scripts" + if curl -L -f "$update_script_url" -o "$INSTALL_DIR/scripts/update.sh" 2>/dev/null; then + chmod +x "$INSTALL_DIR/scripts/update.sh" + print_success "Update Script heruntergeladen" + else + print_warning "Update Script konnte nicht heruntergeladen werden" + fi + cd - > /dev/null rm -rf "$temp_dir" @@ -635,6 +647,18 @@ EOF return fi + # Copy update script + cd "$temp_dir/csf-core" + print_step "Kopiere Update Script..." + mkdir -p "$INSTALL_DIR/scripts" + if [ -f "scripts/update.sh" ]; then + cp scripts/update.sh "$INSTALL_DIR/scripts/" + chmod +x "$INSTALL_DIR/scripts/update.sh" + print_success "Update Script kopiert" + else + print_warning "Update Script nicht gefunden" + fi + cd - > /dev/null rm -rf "$temp_dir"