From d9358fc0afeb7cef0f6faa831acfc87ff3f08d03 Mon Sep 17 00:00:00 2001 From: Spine Date: Sun, 16 Jul 2023 20:58:50 +0000 Subject: [PATCH] merge .bin/ and scripts/ into a common bin/ --- .docker/web/bootstrap-base.sh | 8 ++++---- .docker/web/crontab | 2 +- .docker/web/entrypoint.sh | 6 +++--- .gitlab-ci.yml | 4 ++-- Makefile | 8 ++++---- app/Manager/SSLHost.php | 2 +- {scripts => bin}/create-collaborative-collages | 0 {scripts => bin}/fix-leech-status.php | 0 {scripts => bin}/generate-storage-dirs | 0 {scripts => bin}/getconf | 0 {scripts => bin}/local-patch | 0 {scripts => bin}/migrate-logs.php | 5 +++-- {scripts => bin}/migrate-torrent-files.php | 0 {scripts => bin}/migrate-warning | 0 {.bin => bin}/phpcbf | 0 {.bin => bin}/phpcs | 0 {scripts => bin}/preview_base.html | 0 {scripts => bin}/process-monero-donation | 0 {scripts => bin}/rebuild-invite-trees.php | 0 {scripts => bin}/rebuild-votes | 0 {scripts => bin}/recheck-file-storage.php | 2 +- {scripts => bin}/regen-filelists.php | 0 {scripts => bin}/remove-upload | 0 {scripts => bin}/render_styles_preview.js | 0 {scripts => bin}/scheduler | 0 {scripts => bin}/ssl-check | 0 {scripts => bin}/twig-parse | 0 {scripts => bin}/upload-wiki.php | 0 {scripts => bin}/ut-garbage-collect | 0 docs/03-Voting.txt | 2 +- docs/crontab | 2 +- lib/config.php | 2 +- misc/phpstan-baseline.neon | 15 --------------- misc/phpstan.neon | 4 ++-- package.json | 8 ++++---- 35 files changed, 28 insertions(+), 42 deletions(-) rename {scripts => bin}/create-collaborative-collages (100%) rename {scripts => bin}/fix-leech-status.php (100%) rename {scripts => bin}/generate-storage-dirs (100%) rename {scripts => bin}/getconf (100%) rename {scripts => bin}/local-patch (100%) rename {scripts => bin}/migrate-logs.php (90%) rename {scripts => bin}/migrate-torrent-files.php (100%) rename {scripts => bin}/migrate-warning (100%) rename {.bin => bin}/phpcbf (100%) rename {.bin => bin}/phpcs (100%) rename {scripts => bin}/preview_base.html (100%) rename {scripts => bin}/process-monero-donation (100%) rename {scripts => bin}/rebuild-invite-trees.php (100%) rename {scripts => bin}/rebuild-votes (100%) rename {scripts => bin}/recheck-file-storage.php (98%) rename {scripts => bin}/regen-filelists.php (100%) rename {scripts => bin}/remove-upload (100%) rename {scripts => bin}/render_styles_preview.js (100%) rename {scripts => bin}/scheduler (100%) rename {scripts => bin}/ssl-check (100%) rename {scripts => bin}/twig-parse (100%) rename {scripts => bin}/upload-wiki.php (100%) rename {scripts => bin}/ut-garbage-collect (100%) diff --git a/.docker/web/bootstrap-base.sh b/.docker/web/bootstrap-base.sh index 05b478fa5..9042f14bf 100755 --- a/.docker/web/bootstrap-base.sh +++ b/.docker/web/bootstrap-base.sh @@ -38,7 +38,7 @@ do done composer --version && composer install --no-progress -scripts/local-patch +bin/local-patch echo "Create postgres database..." #hostname:port:database:username:password @@ -88,9 +88,9 @@ fi if [ ! -d /var/lib/gazelle/torrent ]; then echo "Generate file storage directories..." time ( - perl "${CI_PROJECT_DIR}/scripts/generate-storage-dirs" /var/lib/gazelle/torrent 2 100 - perl "${CI_PROJECT_DIR}/scripts/generate-storage-dirs" /var/lib/gazelle/riplog 2 100 - perl "${CI_PROJECT_DIR}/scripts/generate-storage-dirs" /var/lib/gazelle/riploghtml 2 100 + perl "${CI_PROJECT_DIR}/bin/generate-storage-dirs" /var/lib/gazelle/torrent 2 100 + perl "${CI_PROJECT_DIR}/bin/generate-storage-dirs" /var/lib/gazelle/riplog 2 100 + perl "${CI_PROJECT_DIR}/bin/generate-storage-dirs" /var/lib/gazelle/riploghtml 2 100 ) chown -R gazelle /var/lib/gazelle fi diff --git a/.docker/web/crontab b/.docker/web/crontab index d3d76132d..158102e43 100644 --- a/.docker/web/crontab +++ b/.docker/web/crontab @@ -1,2 +1,2 @@ -PATH=$PATH:/var/www/scripts +PATH=$PATH:/var/www/bin */15 * * * * scheduler >> /tmp/schedule.log diff --git a/.docker/web/entrypoint.sh b/.docker/web/entrypoint.sh index 3e1d64357..452cf1613 100644 --- a/.docker/web/entrypoint.sh +++ b/.docker/web/entrypoint.sh @@ -52,9 +52,9 @@ fi if [ ! -d /var/lib/gazelle/torrent ]; then echo "Generate file storage directories..." - perl /var/www/scripts/generate-storage-dirs /var/lib/gazelle/torrent 2 100 - perl /var/www/scripts/generate-storage-dirs /var/lib/gazelle/riplog 2 100 - perl /var/www/scripts/generate-storage-dirs /var/lib/gazelle/riploghtml 2 100 + perl /var/www/bin/generate-storage-dirs /var/lib/gazelle/torrent 2 100 + perl /var/www/bin/generate-storage-dirs /var/lib/gazelle/riplog 2 100 + perl /var/www/bin/generate-storage-dirs /var/lib/gazelle/riploghtml 2 100 chown -R gazelle /var/lib/gazelle fi diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7d2e66091..afc8f8ed0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -45,7 +45,7 @@ phpstan: - .composer script: - composer install --no-progress - - /bin/sh scripts/local-patch + - /bin/sh bin/local-patch - phpstan analyse --no-progress --configuration misc/phpstan.neon e2e-tests: @@ -102,7 +102,7 @@ e2e-tests: coverage: /^\s*Lines:\s*\d+.\d+\%/ script: - /bin/bash "${CI_PROJECT_DIR}/.docker/web/bootstrap-base.sh" - - su gazelle -c "scripts/twig-parse \$(find templates -type f)" + - su gazelle -c "bin/twig-parse \$(find templates -type f)" - /bin/bash "${CI_PROJECT_DIR}/.docker/web/start-services.sh" - su gazelle -c "composer exec -- phpunit --configuration misc/phpunit.xml --coverage-php /tmp/coverage/phpunit.cov --exclude-group no-ci" - /bin/bash "${CI_PROJECT_DIR}/.docker/web/bootstrap-yarn.sh" diff --git a/Makefile b/Makefile index 29cbb8301..1b0a07106 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ .DEFAULT_GOAL := help NOW := $(shell date +'%Y%m%d-%H%M%S') -STORAGE_PATH_RIPLOG := $(shell scripts/getconf STORAGE_PATH_RIPLOG) -STORAGE_PATH_RIPLOGHTML := $(shell scripts/getconf STORAGE_PATH_RIPLOGHTML) -STORAGE_PATH_TORRENT := $(shell scripts/getconf STORAGE_PATH_TORRENT) +STORAGE_PATH_RIPLOG := $(shell bin/getconf STORAGE_PATH_RIPLOG) +STORAGE_PATH_RIPLOGHTML := $(shell bin/getconf STORAGE_PATH_RIPLOGHTML) +STORAGE_PATH_TORRENT := $(shell bin/getconf STORAGE_PATH_TORRENT) .SILENT: help .PHONY: help @@ -63,7 +63,7 @@ lint-php: .PHONY: lint-twig lint-twig: - scripts/twig-parse $(find templates -type f) + bin/twig-parse $(find templates -type f) .PHONY: mysqldump mysqldump: diff --git a/app/Manager/SSLHost.php b/app/Manager/SSLHost.php index 1659fd3eb..54743df17 100644 --- a/app/Manager/SSLHost.php +++ b/app/Manager/SSLHost.php @@ -15,7 +15,7 @@ public function lookup(string $hostname, int $port): array { } $notBefore = null; $notAfter = null; - $output = explode("\n", trim((string)shell_exec(SERVER_ROOT . "/scripts/ssl-check $hostname $port"))); + $output = explode("\n", trim((string)shell_exec(SERVER_ROOT . "/bin/ssl-check $hostname $port"))); if (count($output) != 2) { return []; } diff --git a/scripts/create-collaborative-collages b/bin/create-collaborative-collages similarity index 100% rename from scripts/create-collaborative-collages rename to bin/create-collaborative-collages diff --git a/scripts/fix-leech-status.php b/bin/fix-leech-status.php similarity index 100% rename from scripts/fix-leech-status.php rename to bin/fix-leech-status.php diff --git a/scripts/generate-storage-dirs b/bin/generate-storage-dirs similarity index 100% rename from scripts/generate-storage-dirs rename to bin/generate-storage-dirs diff --git a/scripts/getconf b/bin/getconf similarity index 100% rename from scripts/getconf rename to bin/getconf diff --git a/scripts/local-patch b/bin/local-patch similarity index 100% rename from scripts/local-patch rename to bin/local-patch diff --git a/scripts/migrate-logs.php b/bin/migrate-logs.php similarity index 90% rename from scripts/migrate-logs.php rename to bin/migrate-logs.php index a79764061..e23cd85a6 100644 --- a/scripts/migrate-logs.php +++ b/bin/migrate-logs.php @@ -14,6 +14,7 @@ define('CHUNK', 100); $offset = 0; +$last = 0; $processed = 0; $newLog = 0; $errLog = 0; @@ -40,8 +41,8 @@ while (list($logId, $torrentId, $log) = $db->next_record(MYSQLI_NUM, false)) { $last = $logId; ++$processed; - if (file_exists($logFiler->pathLegacy([$torrentId, $logId])) && !file_exists($logFiler->path([$torrentId, $logId]))) { - if (!copy($logFiler->pathLegacy([$torrentId, $logId]), $logFiler->path([$torrentId, $logId]))) { + if (file_exists($logFiler->pathLegacy([$torrentId, $logId])) && !file_exists($logFiler->path([$torrentId, $logId]))) { /** @phpstan-ignore-line */ + if (!copy($logFiler->pathLegacy([$torrentId, $logId]), $logFiler->path([$torrentId, $logId]))) { /** @phpstan-ignore-line */ ++$errLog; } ++$newLog; diff --git a/scripts/migrate-torrent-files.php b/bin/migrate-torrent-files.php similarity index 100% rename from scripts/migrate-torrent-files.php rename to bin/migrate-torrent-files.php diff --git a/scripts/migrate-warning b/bin/migrate-warning similarity index 100% rename from scripts/migrate-warning rename to bin/migrate-warning diff --git a/.bin/phpcbf b/bin/phpcbf similarity index 100% rename from .bin/phpcbf rename to bin/phpcbf diff --git a/.bin/phpcs b/bin/phpcs similarity index 100% rename from .bin/phpcs rename to bin/phpcs diff --git a/scripts/preview_base.html b/bin/preview_base.html similarity index 100% rename from scripts/preview_base.html rename to bin/preview_base.html diff --git a/scripts/process-monero-donation b/bin/process-monero-donation similarity index 100% rename from scripts/process-monero-donation rename to bin/process-monero-donation diff --git a/scripts/rebuild-invite-trees.php b/bin/rebuild-invite-trees.php similarity index 100% rename from scripts/rebuild-invite-trees.php rename to bin/rebuild-invite-trees.php diff --git a/scripts/rebuild-votes b/bin/rebuild-votes similarity index 100% rename from scripts/rebuild-votes rename to bin/rebuild-votes diff --git a/scripts/recheck-file-storage.php b/bin/recheck-file-storage.php similarity index 98% rename from scripts/recheck-file-storage.php rename to bin/recheck-file-storage.php index af8cc644c..848efa04d 100644 --- a/scripts/recheck-file-storage.php +++ b/bin/recheck-file-storage.php @@ -84,7 +84,7 @@ continue; } $db_digest = md5($db->scalar($config['MD5'], ...array_slice($match, 1)) . ($config['NEWLN'] ? "\n" : '')); - $file_digest = md5(file_get_contents($file)); + $file_digest = md5((string)file_get_contents($file)); if ($db_digest != $file_digest) { echo "$file contents $file_digest does not match db $db_digest\n"; ++$mismatch; diff --git a/scripts/regen-filelists.php b/bin/regen-filelists.php similarity index 100% rename from scripts/regen-filelists.php rename to bin/regen-filelists.php diff --git a/scripts/remove-upload b/bin/remove-upload similarity index 100% rename from scripts/remove-upload rename to bin/remove-upload diff --git a/scripts/render_styles_preview.js b/bin/render_styles_preview.js similarity index 100% rename from scripts/render_styles_preview.js rename to bin/render_styles_preview.js diff --git a/scripts/scheduler b/bin/scheduler similarity index 100% rename from scripts/scheduler rename to bin/scheduler diff --git a/scripts/ssl-check b/bin/ssl-check similarity index 100% rename from scripts/ssl-check rename to bin/ssl-check diff --git a/scripts/twig-parse b/bin/twig-parse similarity index 100% rename from scripts/twig-parse rename to bin/twig-parse diff --git a/scripts/upload-wiki.php b/bin/upload-wiki.php similarity index 100% rename from scripts/upload-wiki.php rename to bin/upload-wiki.php diff --git a/scripts/ut-garbage-collect b/bin/ut-garbage-collect similarity index 100% rename from scripts/ut-garbage-collect rename to bin/ut-garbage-collect diff --git a/docs/03-Voting.txt b/docs/03-Voting.txt index 6b6332cb4..83792fdca 100644 --- a/docs/03-Voting.txt +++ b/docs/03-Voting.txt @@ -16,7 +16,7 @@ will be 5 rows (from the five voters) in the users_votes table, and the torrents_votes table will contain one row with Total = 5, Ups = 3. If the `torrents_votes` is ever corrupted, it may be recreated with -`scripts/rebuild-votes`. There is some discrepancy in the code between the +`bin/rebuild-votes`. There is some discrepancy in the code between the above formula and the use of binomial_ci(Ups, Total). The user and group vote information are both cached. As the user object can diff --git a/docs/crontab b/docs/crontab index 38db814c4..a3cba46d5 100644 --- a/docs/crontab +++ b/docs/crontab @@ -1,7 +1,7 @@ # These are the cron jobs. # Adjust PATH according to where the repository is checked out on the filesystem -PATH=$PATH:/var/www/scripts +PATH=$PATH:/var/www/bin 0,15,30,45 * * * * scheduler >> /tmp/schedule.log * * * * * /usr/bin/indexer -c /etc/sphinx/sphinx.conf --rotate delta requests_delta log_delta > /dev/null diff --git a/lib/config.php b/lib/config.php index 2fa1b5ff7..35c080ae8 100644 --- a/lib/config.php +++ b/lib/config.php @@ -62,7 +62,7 @@ // Path for storing temporary files (should be moved out of the root partition) defined('TMPDIR') or define('TMPDIR', '/tmp'); -// Paths for storing uploaded assets outside the database. See scripts/generate-storage-dirs +// Paths for storing uploaded assets outside the database. See bin/generate-storage-dirs // Should also be moved out of the root partition. defined('STORAGE_PATH_TORRENT') or define('STORAGE_PATH_TORRENT', '/var/lib/gazelle/torrent'); defined('STORAGE_PATH_RIPLOG') or define('STORAGE_PATH_RIPLOG', '/var/lib/gazelle/riplog'); diff --git a/misc/phpstan-baseline.neon b/misc/phpstan-baseline.neon index d7ad2f9fb..e931610cb 100644 --- a/misc/phpstan-baseline.neon +++ b/misc/phpstan-baseline.neon @@ -2180,21 +2180,6 @@ parameters: count: 1 path: ../classes/view.class.php - - - message: "#^Call to an undefined method Gazelle\\\\File\\\\RipLog\\:\\:pathLegacy\\(\\)\\.$#" - count: 2 - path: ../scripts/migrate-logs.php - - - - message: "#^Variable \\$last might not be defined\\.$#" - count: 2 - path: ../scripts/migrate-logs.php - - - - message: "#^Parameter \\#1 \\$string of function md5 expects string, string\\|false given\\.$#" - count: 1 - path: ../scripts/recheck-file-storage.php - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" count: 1 diff --git a/misc/phpstan.neon b/misc/phpstan.neon index dd3aa7fae..d1cfc1e41 100644 --- a/misc/phpstan.neon +++ b/misc/phpstan.neon @@ -22,9 +22,9 @@ parameters: paths: - ../lib/util.php - ../app + - ../bin - ../classes - ../misc/phinx - - ../scripts - ../tests - ../sections parallel: @@ -92,7 +92,7 @@ parameters: - message: '/^Variable \$(?:Cache|DB|Debug|SessionID|Twig|Viewer) might not be defined\.$/' paths: - - ../scripts/* + - ../bin/* - ../sections/* - message: '/^Variable \$Router might not be defined\.$/' diff --git a/package.json b/package.json index f1db98c1a..e3cabb5b0 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,14 @@ "prod": "cross-env NODE_ENV=production yarn build", "build": "yarn build:scss && yarn build:previews", "build:scss": "webpack --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", - "build:previews": "node scripts/render_styles_preview.js", + "build:previews": "node bin/render_styles_preview.js", "start": "yarn build:scss -- --watch", "lint:css": "stylelint \"sass/**/*.scss\" || exit 0", "lint:css-checkstyle": "stylelint \"sass/**/*.scss\" --custom-formatter ./node_modules/stylelint-checkstyle-formatter/index.js || exit 0", "lint:php:internal": "find . -path './vendor' -prune -o -path ./node_modules -prune -o -path './.docker' -prune -o -type f -name '*.php' -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v \"No syntax errors detected\" )", "lint:php:phpcs": "vendor/bin/phpcs -p --report-width 1000", "lint:php": "yarn lint:php:internal && yarn lint:php:phpcs", - "lint:php:fix": "./.bin/phpcbf", + "lint:php:fix": "bin/phpcbf", "pre-commit": "yarn lint:php:fix", "prepare": "husky install" }, @@ -44,8 +44,8 @@ "lint-staged": { "*.php": [ "vendor/bin/phpstan analyze --no-progress --configuration=misc/phpstan.neon --memory-limit 512M", - ".bin/phpcs", - ".bin/phpcbf" + "bin/phpcs", + "bin/phpcbf" ] }, "browserslist": [