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 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 read -rsp "Confirm password: " pass2; echo
[ "$pass1" != "$pass2" ] && echo "Passwords do not match." && exit 1 [ "$pass1" != "$pass2" ] && echo "Passwords do not match." && exit 1
read -rp "Enter downloads directory [/app/data/downloads]: " downloads_dir read -rp "Enter downloads directory [/app/data/downloads]: " downloads_dir
downloads_dir=${downloads_dir:-/app/data/downloads} downloads_dir=${downloads_dir:-/app/data/downloads}
mkdir -p /app/data/public/bin "$downloads_dir" mkdir -p /app/data/public/bin "$downloads_dir"
/bin/rm -f /app/data/public/bin/yt-dlp /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 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 chmod +x /app/data/public/bin/yt-dlp
if command -v htpasswd >/dev/null 2>&1; then if command -v htpasswd >/dev/null 2>&1; then
htpasswd -cb /app/data/.htpasswd admin "$pass1" htpasswd -cb /app/data/.htpasswd admin "$pass1"
else else
echo "admin:$(openssl passwd -apr1 "$pass1")" > /app/data/.htpasswd echo "admin:$(openssl passwd -apr1 "$pass1")" > /app/data/.htpasswd
fi fi
cat > /app/data/public/.htaccess <<'EOF' cat > /app/data/public/.htaccess <<'EOF'
AuthType Basic AuthType Basic
AuthName "Restricted Area" AuthName "Restricted Area"
AuthUserFile /app/data/.htpasswd AuthUserFile /app/data/.htpasswd
Require valid-user Require valid-user
EOF EOF
set +u set +u
{ {
echo "[settings]" echo "[settings]"
echo "downloads_dir=$downloads_dir" echo "downloads_dir=$downloads_dir"
} > /app/data/config.ini } > /app/data/config.ini
set -u set -u
cat > /app/data/public/index.php <<'EOF' cat > /app/data/public/index.php <<'EOF'
<?php <?php
$config = parse_ini_file("/app/data/config.ini"); $config = parse_ini_file("/app/data/config.ini");
@ -106,13 +114,19 @@ foreach ($success as $entry) {
</body> </body>
</html> </html>
EOF EOF
cat > /app/data/public/log.php <<'EOF' cat > /app/data/public/log.php <<'EOF'
<?php <?php
if (file_exists("/tmp/yt-dlp.log") && filesize("/tmp/yt-dlp.log") > 5 * 1024 * 1024) {
@unlink("/tmp/yt-dlp.log");
}
header("Refresh: 3"); header("Refresh: 3");
echo "<pre>"; echo "<pre>";
system("tail -n 100 /tmp/yt-dlp.log 2>&1"); system("tail -n 100 /tmp/yt-dlp.log 2>&1");
echo "</pre>"; echo "</pre>";
?> ?>
EOF EOF
chown -R www-data:www-data /app/data/public 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)."