All checks were successful
Deployment Verification Ubuntu / deploy-and-test (push) Successful in 2m16s
175 lines
4.6 KiB
Bash
175 lines
4.6 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# Package management module
|
|
# =============================================================================
|
|
|
|
# Set script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Source common functions and variables
|
|
source "./common.sh"
|
|
source "./custom/custom_proxy"
|
|
|
|
# Function to configure APT with proxy settings if needed
|
|
configure_apt_proxy() {
|
|
local PROXY_FILE="/etc/apt/apt.conf.d/90proxy"
|
|
local PROXY_DOC="/root/apt-proxy-documentation.txt"
|
|
|
|
log_message "INFO" "Creating APT proxy documentation at $PROXY_DOC"
|
|
|
|
cat > "$PROXY_DOC" << EOF
|
|
# APT Proxy Configuration
|
|
# To configure APT to use a proxy, edit the file /etc/apt/apt.conf.d/90proxy
|
|
# and add one of the following configurations:
|
|
|
|
# HTTP proxy
|
|
Acquire::http::Proxy "http://username:password@proxy.example.com:8080/";
|
|
|
|
# HTTPS proxy
|
|
Acquire::https::Proxy "http://username:password@proxy.example.com:8080/";
|
|
|
|
# For APT to use the system's proxy settings
|
|
Acquire::http::Proxy "http://${HTTP_PROXY}";
|
|
Acquire::https::Proxy "http://${HTTPS_PROXY}";
|
|
Acquire::ftp::proxy "ftp://${FTP_PROXY}";
|
|
|
|
# To disable proxy for specific hosts
|
|
Acquire::http::Proxy::hostname.example.com "DIRECT";
|
|
EOF
|
|
|
|
apt-get update
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_message "SUCCESS" "Package lists updated successfully"
|
|
else
|
|
cat > "$PROXY_FILE" << EOF
|
|
Acquire::http::Proxy "http://$HTTP_PROXY";
|
|
Acquire::https::Proxy "http://$HTTPS_PROXY";
|
|
Acquire::ftp::proxy "ftp://$FTP_PROXY";
|
|
EOF
|
|
apt-get update
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_message "SUCCESS" "Package lists updated successfully with proxy"
|
|
else
|
|
log_message "ERROR" "Failed to update package lists with proxy"
|
|
fi
|
|
|
|
return 1
|
|
fi
|
|
|
|
log_message "SUCCESS" "APT proxy documentation created. Edit $PROXY_FILE to configure proxies if needed"
|
|
}
|
|
|
|
# Function to update package lists and upgrade installed packages
|
|
update_upgrade_packages() {
|
|
log_message "INFO" "Updating package lists"
|
|
apt-get update
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_message "SUCCESS" "Package lists updated successfully"
|
|
else
|
|
log_message "ERROR" "Failed to update package lists"
|
|
|
|
return 1
|
|
fi
|
|
|
|
log_message "INFO" "Upgrading installed packages"
|
|
apt-get full-upgrade -y
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_message "SUCCESS" "Packages upgraded successfully"
|
|
else
|
|
log_message "ERROR" "Failed to upgrade packages"
|
|
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Function to install essential security packages
|
|
install_essential_packages() {
|
|
local PACKAGES=(
|
|
"apt-transport-https"
|
|
"ca-certificates"
|
|
"gnupg"
|
|
"software-properties-common"
|
|
"curl"
|
|
"wget"
|
|
"apt-listchanges"
|
|
)
|
|
|
|
log_message "INFO" "Installing essential security packages"
|
|
|
|
for PACKAGE in "${PACKAGES[@]}"; do
|
|
if ! is_package_installed "$PACKAGE"; then
|
|
log_message "INFO" "Installing $PACKAGE"
|
|
apt-get install -y "$PACKAGE"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_message "SUCCESS" "Installed $PACKAGE successfully"
|
|
else
|
|
log_message "ERROR" "Failed to install $PACKAGE"
|
|
fi
|
|
else
|
|
log_message "INFO" "$PACKAGE is already installed"
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Create a new package installation module
|
|
cat > "$SCRIPT_DIR/install_packages.sh" << 'EOF'
|
|
#!/bin/bash
|
|
# =============================================================================
|
|
# New package installation module
|
|
# =============================================================================
|
|
|
|
# Set script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Source common functions and variables
|
|
source "./common.sh"
|
|
|
|
# Function to install new packages safely
|
|
install_new_packages() {
|
|
if [ $# -eq 0 ]; then
|
|
log_message "ERROR" "No packages specified for installation"
|
|
return 1
|
|
fi
|
|
|
|
log_message "INFO" "Installing new packages: $*"
|
|
|
|
# Update package lists first
|
|
apt-get update
|
|
|
|
if [ $? -ne 0 ]; then
|
|
log_message "ERROR" "Failed to update package lists"
|
|
return 1
|
|
fi
|
|
|
|
# Install the specified packages
|
|
apt-get install -y "$@"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
log_message "SUCCESS" "Installed packages successfully: $*"
|
|
return 0
|
|
else
|
|
log_message "ERROR" "Failed to install packages: $*"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Usage example:
|
|
# source "$SCRIPT_DIR/install_packages.sh"
|
|
# install_new_packages package1 package2 package3
|
|
EOF
|
|
|
|
chmod +x "$SCRIPT_DIR/install_packages.sh"
|
|
|
|
log_message "INFO" "Created new package installation module at $SCRIPT_DIR/install_packages.sh"
|
|
|
|
# Main execution for package management
|
|
configure_apt_proxy
|
|
update_upgrade_packages
|
|
install_essential_packages
|
|
|
|
log_message "SUCCESS" "Package management configuration completed" |