fix(cloudron) add autoclean log for yt-dlp logs

This commit is contained in:
SansGuidon 2025-04-28 11:09:50 +00:00
parent 64a2d28957
commit e0b85a0825

View File

@ -1,30 +1,38 @@
#!/bin/bash
set -euo pipefail
read -rsp "Set password for admin (HTTP basic auth) user: " pass1; echo
read -rsp "Set password for admin (HTTP Basic Auth): " pass1; echo
read -rsp "Confirm password: " pass2; echo
[ "$pass1" != "$pass2" ] && echo "Passwords do not match." && exit 1
read -rp "Enter downloads directory [/app/data/downloads]: " downloads_dir
downloads_dir=${downloads_dir:-/app/data/downloads}
mkdir -p /app/data/public/bin "$downloads_dir"
/bin/rm -f /app/data/public/bin/yt-dlp
curl -sSL https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /app/data/public/bin/yt-dlp
chmod +x /app/data/public/bin/yt-dlp
if command -v htpasswd >/dev/null 2>&1; then
htpasswd -cb /app/data/.htpasswd admin "$pass1"
else
echo "admin:$(openssl passwd -apr1 "$pass1")" > /app/data/.htpasswd
fi
cat > /app/data/public/.htaccess <<'EOF'
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /app/data/.htpasswd
Require valid-user
EOF
set +u
{
echo "[settings]"
echo "downloads_dir=$downloads_dir"
} > /app/data/config.ini
set -u
cat > /app/data/public/index.php <<'EOF'
<?php
$config = parse_ini_file("/app/data/config.ini");
@ -106,13 +114,19 @@ foreach ($success as $entry) {
</body>
</html>
EOF
cat > /app/data/public/log.php <<'EOF'
<?php
if (file_exists("/tmp/yt-dlp.log") && filesize("/tmp/yt-dlp.log") > 5 * 1024 * 1024) {
@unlink("/tmp/yt-dlp.log");
}
header("Refresh: 3");
echo "<pre>";
system("tail -n 100 /tmp/yt-dlp.log 2>&1");
echo "</pre>";
?>
EOF
chown -R www-data:www-data /app/data/public
echo "Done. Access via your LAMP app URL (protected)."
echo "Done. Access via your LAMP app URL (protected)."