12 lines
994 B
Bash
Executable file
12 lines
994 B
Bash
Executable file
#!/bin/zsh
|
|
|
|
# Get all files so we can delete them later
|
|
files=$(sudo -iu postgres psql -d e2net-staging -c "SELECT \"url\" FROM \"public\".\"drive_file\" WHERE \"isLink\" = 'FALSE' AND \"storedInternal\" = 'FALSE' AND \"userHost\" IS NOT NULL AND \"userHost\" <> 'estrogen.network'" -t -A --csv | sed 's/https:\/\/e2net-staging.cdn.ztn.sh\/drive\///g' | awk NF | sort)
|
|
miniofiles=$(mcli ls garage/e2net-staging/drive | grep -Po '[^\s]*$' | grep -Pv '^webpublic-' | sort)
|
|
deadlinks=$(comm -13 <(echo "$miniofiles") <(echo "$files") | grep -P '.{16,}' | sed 's/^/https:\/\/e2net-staging.cdn.ztn.sh\/drive\//g')
|
|
|
|
while IFS= read -r file ; do
|
|
cleanup_query="UPDATE \"public\".\"drive_file\" SET \"isLink\" = 'TRUE', \"thumbnailUrl\" = NULL, \"url\" = \"uri\", \"accessKey\" = replace(\"accessKey\", 'drive/', ''), \"thumbnailAccessKey\" = replace(\"thumbnailAccessKey\", 'drive/', '') WHERE \"url\" = '$file'"
|
|
echo "$cleanup_query" | sudo -iu postgres psql -d e2net-staging
|
|
done <<< "$deadlinks"
|