mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:07:03 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
174 lines
5.4 KiB
Bash
Executable File
174 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# PHP, Redis and the Nextcloud install itself.
|
|
#
|
|
# Sourced by setup_nextcloud_raspberry.sh; split out to keep nc_services.sh under the
|
|
# 250-line cap. Sourced rather than run, so it inherits the caller's
|
|
# strict mode and the variables defined above the source line.
|
|
|
|
configure_php() {
|
|
log_info "Configuring PHP..."
|
|
|
|
# Find PHP version
|
|
local php_version
|
|
php_version=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')
|
|
local php_ini="/etc/php/${php_version}/apache2/php.ini"
|
|
|
|
# Backup original
|
|
cp "$php_ini" "${php_ini}.backup"
|
|
|
|
# Apply Nextcloud recommended settings
|
|
sed -i 's/memory_limit = .*/memory_limit = 512M/' "$php_ini"
|
|
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 16G/' "$php_ini"
|
|
sed -i 's/post_max_size = .*/post_max_size = 16G/' "$php_ini"
|
|
sed -i 's/max_execution_time = .*/max_execution_time = 360/' "$php_ini"
|
|
sed -i 's/max_input_time = .*/max_input_time = 360/' "$php_ini"
|
|
sed -i 's/;date.timezone.*/date.timezone = Europe\/Warsaw/' "$php_ini"
|
|
|
|
# Configure OPcache
|
|
cat >>"$php_ini" <<'EOF'
|
|
|
|
; Nextcloud OPcache settings
|
|
opcache.enable=1
|
|
opcache.interned_strings_buffer=16
|
|
opcache.max_accelerated_files=10000
|
|
opcache.memory_consumption=128
|
|
opcache.save_comments=1
|
|
opcache.revalidate_freq=1
|
|
EOF
|
|
|
|
# Configure APCu
|
|
echo "apc.enable_cli=1" >>"/etc/php/${php_version}/mods-available/apcu.ini"
|
|
|
|
systemctl restart apache2
|
|
|
|
log_success "PHP configured"
|
|
}
|
|
|
|
configure_redis() {
|
|
log_info "Configuring Redis..."
|
|
|
|
systemctl enable redis-server
|
|
systemctl start redis-server
|
|
|
|
log_success "Redis configured"
|
|
}
|
|
|
|
install_nextcloud() {
|
|
log_info "Installing Nextcloud..."
|
|
|
|
local db_password
|
|
db_password=$(cat /root/.nextcloud_db_password)
|
|
|
|
if [[ -z $NEXTCLOUD_ADMIN_PASSWORD ]]; then
|
|
prompt_password "Enter Nextcloud admin password" NEXTCLOUD_ADMIN_PASSWORD
|
|
fi
|
|
|
|
# Create data directory
|
|
mkdir -p "$NEXTCLOUD_DATA_DIR"
|
|
chown -R www-data:www-data "$NEXTCLOUD_DATA_DIR"
|
|
|
|
# Get server IP
|
|
local server_ip
|
|
server_ip=$(hostname -I | awk '{print $1}')
|
|
|
|
# Run Nextcloud installer
|
|
cd /var/www/nextcloud || { log_error "Nextcloud is not installed at /var/www/nextcloud"; return 1; }
|
|
sudo -u www-data php occ maintenance:install \
|
|
--database "mysql" \
|
|
--database-name "nextcloud" \
|
|
--database-user "nextcloud" \
|
|
--database-pass "$db_password" \
|
|
--admin-user "$NEXTCLOUD_ADMIN_USER" \
|
|
--admin-pass "$NEXTCLOUD_ADMIN_PASSWORD" \
|
|
--data-dir "$NEXTCLOUD_DATA_DIR"
|
|
|
|
# Add trusted domain
|
|
sudo -u www-data php occ config:system:set trusted_domains 1 --value="$server_ip"
|
|
sudo -u www-data php occ config:system:set trusted_domains 2 --value="$PI_HOSTNAME"
|
|
sudo -u www-data php occ config:system:set trusted_domains 3 --value="$PI_HOSTNAME.local"
|
|
|
|
# Configure Redis caching
|
|
sudo -u www-data php occ config:system:set memcache.local --value='\OC\Memcache\APCu'
|
|
sudo -u www-data php occ config:system:set memcache.distributed --value='\OC\Memcache\Redis'
|
|
sudo -u www-data php occ config:system:set memcache.locking --value='\OC\Memcache\Redis'
|
|
sudo -u www-data php occ config:system:set redis host --value='localhost'
|
|
sudo -u www-data php occ config:system:set redis port --value='6379' --type=integer
|
|
|
|
# Set default phone region
|
|
sudo -u www-data php occ config:system:set default_phone_region --value='PL'
|
|
|
|
# Enable maintenance window
|
|
sudo -u www-data php occ config:system:set maintenance_window_start --value=1 --type=integer
|
|
|
|
log_success "Nextcloud installed"
|
|
}
|
|
|
|
setup_nextcloud_cron() {
|
|
log_info "Setting up Nextcloud background jobs..."
|
|
|
|
# Add cron job for background tasks
|
|
crontab -u www-data -l 2>/dev/null || echo "" | crontab -u www-data -
|
|
(
|
|
crontab -u www-data -l 2>/dev/null | grep -v 'nextcloud/cron.php'
|
|
echo "*/5 * * * * php -f /var/www/nextcloud/cron.php"
|
|
) | crontab -u www-data -
|
|
|
|
# Switch to cron background job mode
|
|
cd /var/www/nextcloud || { log_error "Nextcloud is not installed at /var/www/nextcloud"; return 1; }
|
|
sudo -u www-data php occ background:cron
|
|
|
|
log_success "Cron jobs configured"
|
|
}
|
|
|
|
verify_nextcloud() {
|
|
log_info "Verifying Nextcloud installation..."
|
|
|
|
local server_ip
|
|
server_ip=$(hostname -I | awk '{print $1}')
|
|
|
|
# Check if Nextcloud is responding
|
|
if curl -s -o /dev/null -w "%{http_code}" "http://${server_ip}/status.php" | grep -q "200"; then
|
|
log_success "Nextcloud is responding!"
|
|
else
|
|
log_warning "Nextcloud may not be fully ready. Check manually."
|
|
fi
|
|
|
|
# Run Nextcloud check
|
|
cd /var/www/nextcloud || { log_error "Nextcloud is not installed at /var/www/nextcloud"; return 1; }
|
|
sudo -u www-data php occ status
|
|
|
|
echo
|
|
log_success "========================================"
|
|
log_success "Nextcloud installation complete!"
|
|
log_success "========================================"
|
|
echo
|
|
log_info "Access Nextcloud at: http://${server_ip}"
|
|
log_info "Admin user: $NEXTCLOUD_ADMIN_USER"
|
|
log_info "Database password saved at: /root/.nextcloud_db_password"
|
|
echo
|
|
log_info "Recommended next steps:"
|
|
log_info "1. Set up a domain name pointing to your Pi"
|
|
log_info "2. Configure SSL with: sudo certbot --apache"
|
|
log_info "3. Install Nextcloud apps via the web interface"
|
|
log_info "4. Configure external storage if needed"
|
|
}
|
|
|
|
phase_nextcloud() {
|
|
check_root
|
|
|
|
log_info "=== Phase 3: Install Nextcloud ==="
|
|
|
|
install_nextcloud_dependencies
|
|
local db_password
|
|
db_password=$(configure_mariadb)
|
|
download_nextcloud
|
|
configure_apache
|
|
configure_php
|
|
configure_redis
|
|
install_nextcloud
|
|
setup_nextcloud_cron
|
|
verify_nextcloud
|
|
|
|
log_success "Phase 3 complete!"
|
|
}
|