update
This commit is contained in:
107
installation.sh
107
installation.sh
@@ -61,9 +61,33 @@ check_sudo() {
|
|||||||
print_success "Sudo privileges confirmed"
|
print_success "Sudo privileges confirmed"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Pre-configure packages to avoid prompts
|
||||||
|
pre_configure_packages() {
|
||||||
|
print_step "Pre-configuring packages to avoid prompts..."
|
||||||
|
|
||||||
|
# Pre-configure common package questions
|
||||||
|
|
||||||
|
# For any package that uses debconf
|
||||||
|
echo 'debconf debconf/frontend select Noninteractive' | sudo debconf-set-selections
|
||||||
|
|
||||||
|
# For timezone data (if tzdata gets updated)
|
||||||
|
echo 'tzdata tzdata/Areas select Europe' | sudo debconf-set-selections
|
||||||
|
echo 'tzdata tzdata/Zones/Europe select Paris' | sudo debconf-set-selections
|
||||||
|
|
||||||
|
# For keyboard configuration
|
||||||
|
echo 'keyboard-configuration keyboard-configuration/layoutcode string us' | sudo debconf-set-selections
|
||||||
|
|
||||||
|
# For any service restart prompts
|
||||||
|
echo '* libraries/restart-without-asking boolean true' | sudo debconf-set-selections
|
||||||
|
|
||||||
|
print_success "Package pre-configuration completed"
|
||||||
|
}
|
||||||
|
|
||||||
# System update
|
# System update
|
||||||
update_system() {
|
update_system() {
|
||||||
print_step "Updating system packages..."
|
print_step "Updating system packages..."
|
||||||
|
# Set non-interactive mode for apt
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
sudo apt update -y
|
sudo apt update -y
|
||||||
print_success "System packages updated"
|
print_success "System packages updated"
|
||||||
}
|
}
|
||||||
@@ -72,6 +96,9 @@ update_system() {
|
|||||||
install_dependencies() {
|
install_dependencies() {
|
||||||
print_step "Installing system dependencies..."
|
print_step "Installing system dependencies..."
|
||||||
|
|
||||||
|
# Ensure non-interactive mode
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
local packages=(
|
local packages=(
|
||||||
"git"
|
"git"
|
||||||
"apache2"
|
"apache2"
|
||||||
@@ -94,7 +121,7 @@ install_dependencies() {
|
|||||||
|
|
||||||
for package in "${packages[@]}"; do
|
for package in "${packages[@]}"; do
|
||||||
print_status "Installing $package..."
|
print_status "Installing $package..."
|
||||||
if sudo apt install -y "$package"; then
|
if sudo DEBIAN_FRONTEND=noninteractive apt install -y -q "$package"; then
|
||||||
print_success "$package installed"
|
print_success "$package installed"
|
||||||
else
|
else
|
||||||
print_error "Failed to install $package"
|
print_error "Failed to install $package"
|
||||||
@@ -124,7 +151,7 @@ install_python_packages() {
|
|||||||
|
|
||||||
for package in "${pip_packages[@]}"; do
|
for package in "${pip_packages[@]}"; do
|
||||||
print_status "Installing Python package: $package..."
|
print_status "Installing Python package: $package..."
|
||||||
if pip3 install "$package" --break-system-packages; then
|
if sudo pip3 install "$package" --break-system-packages; then
|
||||||
print_success "$package installed"
|
print_success "$package installed"
|
||||||
else
|
else
|
||||||
print_warning "Failed to install $package (may already be installed)"
|
print_warning "Failed to install $package (may already be installed)"
|
||||||
@@ -460,28 +487,6 @@ create_databases() {
|
|||||||
if [ -f "/var/www/moduleair_pro_4g/sqlite/create_db.py" ]; then
|
if [ -f "/var/www/moduleair_pro_4g/sqlite/create_db.py" ]; then
|
||||||
if sudo /usr/bin/python3 "/var/www/moduleair_pro_4g/sqlite/create_db.py"; then
|
if sudo /usr/bin/python3 "/var/www/moduleair_pro_4g/sqlite/create_db.py"; then
|
||||||
print_success "Databases created successfully"
|
print_success "Databases created successfully"
|
||||||
|
|
||||||
# Set proper permissions on database files
|
|
||||||
print_status "Setting database permissions..."
|
|
||||||
|
|
||||||
# Find all .db files in the sqlite directory and parent directory
|
|
||||||
if [ -d "/var/www/moduleair_pro_4g/sqlite" ]; then
|
|
||||||
# Set ownership and permissions for all database files
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db" -type f -exec chown www-data:www-data {} \;
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db" -type f -exec chmod 664 {} \;
|
|
||||||
|
|
||||||
# Set permissions on the sqlite directory itself
|
|
||||||
sudo chown -R www-data:www-data /var/www/moduleair_pro_4g/sqlite
|
|
||||||
sudo chmod 775 /var/www/moduleair_pro_4g/sqlite
|
|
||||||
|
|
||||||
# Also set permissions on any db-journal or db-wal files (SQLite temporary files)
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db-journal" -type f -exec chown www-data:www-data {} \;
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db-journal" -type f -exec chmod 664 {} \;
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db-wal" -type f -exec chown www-data:www-data {} \;
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db-wal" -type f -exec chmod 664 {} \;
|
|
||||||
|
|
||||||
print_success "Database permissions set"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
print_error "Failed to create databases"
|
print_error "Failed to create databases"
|
||||||
return 1
|
return 1
|
||||||
@@ -495,44 +500,23 @@ create_databases() {
|
|||||||
fix_database_permissions() {
|
fix_database_permissions() {
|
||||||
print_step "Fixing database permissions..."
|
print_step "Fixing database permissions..."
|
||||||
|
|
||||||
# Set proper ownership and permissions for all database files
|
# Set full permissions for sqlite directory
|
||||||
if [ -d "/var/www/moduleair_pro_4g" ]; then
|
if [ -d "/var/www/moduleair_pro_4g/sqlite" ]; then
|
||||||
# Find and fix all .db files
|
sudo chmod 777 /var/www/moduleair_pro_4g/sqlite/
|
||||||
local db_count=$(sudo find /var/www/moduleair_pro_4g -name "*.db" -type f | wc -l)
|
print_success "Set permissions for sqlite directory"
|
||||||
|
else
|
||||||
|
print_warning "sqlite directory not found"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$db_count" -gt 0 ]; then
|
# Set full permissions for sensors.db
|
||||||
print_status "Found $db_count database file(s)"
|
if [ -f "/var/www/moduleair_pro_4g/sqlite/sensors.db" ]; then
|
||||||
|
sudo chmod 777 /var/www/moduleair_pro_4g/sqlite/sensors.db
|
||||||
# Set ownership to www-data
|
print_success "Set permissions for sensors.db"
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db" -type f -exec chown www-data:www-data {} \;
|
else
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db-*" -type f -exec chown www-data:www-data {} \;
|
print_warning "sensors.db not found"
|
||||||
|
fi
|
||||||
# Set read/write permissions for owner and group
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db" -type f -exec chmod 664 {} \;
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db-*" -type f -exec chmod 664 {} \;
|
|
||||||
|
|
||||||
# Ensure directories containing databases are writable
|
|
||||||
sudo find /var/www/moduleair_pro_4g -name "*.db" -type f -exec dirname {} \; | sort -u | while read dir; do
|
|
||||||
sudo chown www-data:www-data "$dir"
|
|
||||||
sudo chmod 775 "$dir"
|
|
||||||
print_status "Fixed permissions for: $dir"
|
|
||||||
done
|
|
||||||
|
|
||||||
print_success "Database permissions fixed"
|
print_success "Database permissions fixed"
|
||||||
else
|
|
||||||
print_warning "No database files found"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Also ensure logs directory is writable
|
|
||||||
if [ -d "/var/www/moduleair_pro_4g/logs" ]; then
|
|
||||||
sudo chown -R www-data:www-data /var/www/moduleair_pro_4g/logs
|
|
||||||
sudo chmod -R 775 /var/www/moduleair_pro_4g/logs
|
|
||||||
print_success "Log directory permissions fixed"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
print_error "ModuleAir directory not found"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set configuration
|
# Set configuration
|
||||||
@@ -689,8 +673,13 @@ main() {
|
|||||||
print_header "MODULEAIR PRO 4G INSTALLATION"
|
print_header "MODULEAIR PRO 4G INSTALLATION"
|
||||||
print_status "Starting automated installation..."
|
print_status "Starting automated installation..."
|
||||||
|
|
||||||
|
# Set non-interactive mode globally
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
export NEEDRESTART_MODE=a
|
||||||
|
|
||||||
check_root
|
check_root
|
||||||
check_sudo
|
check_sudo
|
||||||
|
pre_configure_packages
|
||||||
update_system
|
update_system
|
||||||
install_dependencies
|
install_dependencies
|
||||||
install_python_packages
|
install_python_packages
|
||||||
|
|||||||
Reference in New Issue
Block a user