#!/bin/bash
echo "This script will set up the environment on your local Linux system."
echo "Is this installation for:"
echo "1) Normal Linux (Ubuntu/Debian)"
echo "2)
Raspberry Pi"
read -p "Enter 1 or 2: " SYSTEM_TYPE
if [[ "$SYSTEM_TYPE" == "1" ]]; then
IS_RASPI=false
elif [[ "$SYSTEM_TYPE" == "2" ]]; then
IS_RASPI=true
else
echo "Invalid selection. Exiting."
exit 1
fi
# Aktualisiere Paketliste
echo "Updating package list..."
apt update
# Installiere benötigte Pakete
echo "Installing sudo and cron..."
apt install -y sudo cron
# Starte und aktiviere Cron-Dienst
echo "Starting cron service..."
service cron start
systemctl enable cron 2>/dev/null || true
# Konfiguriere www-data für sudo ohne Passwort
echo "Configuring www-data sudo permissions..."
echo 'www-data ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/www-data
chmod 440 /etc/sudoers.d/www-data
# Stelle sicher, dass Crontab-Verzeichnisse korrekt berechtigt sind
echo "Setting correct permissions for cron directories..."
chown -R www-data:www-data /var/spool/cron 2>/dev/null || true
chown -R www-data:www-data /var/spool/cron/crontabs 2>/dev/null || true
chmod -R 755 /var/spool/cron 2>/dev/null || true
chmod -R 755 /var/spool/cron/crontabs 2>/dev/null || true
# Finde die installierte PHP-Version (8.2 oder 8.3)
echo "Detecting PHP version..."
PHP_VERSION=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;' 2>/dev/null)
# Falls PHP nicht gefunden, suche in /etc/php
if [[ -z "$PHP_VERSION" ]] || ! [[ "$PHP_VERSION" =~ ^(8\.2|8\.3)$ ]]; then
echo "PHP version not found via CLI, checking /etc/php directory..."
if [[ -d "/etc/php" ]]; then
PHP_VERSION=$(ls /etc/php | grep -E '8\.[2-3]' | sort -r | head -n 1)
fi
fi
if [[ -z "$PHP_VERSION" ]] || ! [[ "$PHP_VERSION" =~ ^(8\.2|8\.3)$ ]]; then
echo "Error: No valid PHP version (8.2 or 8.3) found!"
exit 1
fi
echo "Using PHP version: $PHP_VERSION"
# Passe PHP-Konfiguration für Apache an
PHP_INI_PATH="/etc/php/$PHP_VERSION/apache2/php.ini"
if [[ -f "$PHP_INI_PATH" ]]; then
echo "Adjusting PHP settings in $PHP_INI_PATH..."
sed -i -E \
-e 's/^post_max_size = [0-9]+M/post_max_size = 100M/' \
-e 's/^upload_max_filesize = [0-9]+M/upload_max_filesize = 100M/' \
"$PHP_INI_PATH"
else
echo "Warning: PHP config file not found at $PHP_INI_PATH"
fi
# Installiere Python und benötigte Bibliotheken
echo "Installing Python and required packages..."
if [ "$IS_RASPI" = true ]; then
apt-get install -y python3 python3-venv python3-pip
python3 -m venv /opt/venv
/opt/venv/bin/pip install --upgrade pip
/opt/venv/bin/pip install requests aiohttp tqdm
# Stelle sicher, dass der virtuelle Umgebungspfad systemweit verfügbar ist
echo 'export PATH=/opt/venv/bin:$PATH' > /etc/profile.d/python-venv.sh
chmod +x /etc/profile.d/python-venv.sh
else
apt-get install -y python3 python3-pip
pip3 install --no-cache-dir requests aiohttp tqdm
fi
# Prüfe auf verfügbare Systemaktualisierungen
UPGRADE_LIST=$(apt list --upgradable 2>/dev/null | grep -Eo '^[^/]+' | head -10)
if [[ -n "$UPGRADE_LIST" ]]; then
echo -e "\nThe following packages can be upgraded:"
echo "$UPGRADE_LIST"
read -p "Do you want to upgrade them? (y/n): " UPGRADE_CONFIRM
if [[ "$UPGRADE_CONFIRM" =~ ^[Yy]$ ]]; then
apt upgrade -y
fi
fi
echo "Setup completed successfully on this system."