chore: Add even more Shellcheck suggestions
This commit is contained in:
parent
06356b6d1c
commit
efe59ecfbf
6 changed files with 86 additions and 86 deletions
|
@ -3,43 +3,43 @@ db="friendica"
|
|||
tmpfile="/tmp/sitesdown.txt"
|
||||
idsdownfile="/tmp/idsdown.txt"
|
||||
loop_1() {
|
||||
sitereq=$(curl -s -L --head -m 10 --request GET "$a")
|
||||
status=$(echo "$sitereq" | grep -e "200" -e "cloudflare")
|
||||
if [[ -z $status ]]
|
||||
sitereq=$(curl -s -L --head -m 10 --request GET "${a}")
|
||||
status=$(echo "${sitereq}" | grep -e "200" -e "cloudflare")
|
||||
if [[ -z ${status} ]]
|
||||
then
|
||||
echo "$a" >> "$tmpfile"
|
||||
echo "Added $a"
|
||||
echo "${a}" >> "${tmpfile}"
|
||||
echo "Added ${a}"
|
||||
fi
|
||||
}
|
||||
loop_2() {
|
||||
echo "Finding users for $b"
|
||||
mariadb "$db" -N -B -q -e "select \`id\` from contact c where \"$b\" not in (select \`contact-id\` from group_member) and (c.baseurl = \"$b\" or c.url = \"$b\")" | sudo tee -a "$idsdownfile" &> /dev/null
|
||||
echo "Finding users for ${b}"
|
||||
mariadb "${db}" -N -B -q -e "select \`id\` from contact c where \"${b}\" not in (select \`contact-id\` from group_member) and (c.baseurl = \"${b}\" or c.url = \"${b}\")" | sudo tee -a "${idsdownfile}" &> /dev/null
|
||||
}
|
||||
|
||||
loop_3() {
|
||||
echo "Deleting user $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`contact\` where \`id\` = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`post-thread\` where \`author-id\` = $lineb or \`causer-id\` = $lineb or \`owner-id\` = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`post-thread-user\` where \`author-id\` = $lineb or \`causer-id\` = $lineb or \`owner-id\` = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`post-user\` where \`author-id\` = $lineb or \`causer-id\` = $lineb or \`owner-id\` = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`post-tag\` where cid = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`post\` where \`owner-id\` = $lineb or \`author-id\` = $lineb or \`causer-id\` = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`photo\` where \`contact-id\` = $lineb"
|
||||
mariadb "$db" -N -B -q -e "delete from \`contact\` where \`id\` = $lineb"
|
||||
echo "Deleting user ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`post-thread\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`post-thread-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`post-user\` where \`author-id\` = ${lineb} or \`causer-id\` = ${lineb} or \`owner-id\` = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`post-tag\` where cid = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`post\` where \`owner-id\` = ${lineb} or \`author-id\` = ${lineb} or \`causer-id\` = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`photo\` where \`contact-id\` = ${lineb}"
|
||||
mariadb "${db}" -N -B -q -e "delete from \`contact\` where \`id\` = ${lineb}"
|
||||
}
|
||||
|
||||
#Check if our dependencies are installed
|
||||
if [[ $(type curl) && $(type mariadb) && $(type date) ]]
|
||||
if [[ -n $(type curl) && -n $(type mariadb) && -n $(type date) ]]
|
||||
then
|
||||
date
|
||||
if [[ ! -f "$tmpfile" ]]
|
||||
if [[ ! -f "${tmpfile}" ]]
|
||||
then
|
||||
echo "Listing sites"
|
||||
sites=($(mariadb "$db" -N -B -q -e "select distinct baseurl from contact" | sort -n | uniq ))
|
||||
sites=($(mariadb "${db}" -N -B -q -e "select distinct baseurl from contact" | sort -n | uniq ))
|
||||
echo "Amount of unique sites: ${#sites[@]}"
|
||||
for a in "${sites[@]}"
|
||||
do
|
||||
loop_1 "$a" &
|
||||
loop_1 "${a}" &
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)*2) ]]
|
||||
then
|
||||
wait -n
|
||||
|
@ -49,14 +49,14 @@ then
|
|||
fi
|
||||
sitesdown=()
|
||||
while read -r line; do
|
||||
sitesdown+=($line)
|
||||
done < "$tmpfile"
|
||||
sitesdown+=(${line})
|
||||
done < "${tmpfile}"
|
||||
echo "Amount of sites down: ${#sitesdown[@]} / ${#sites[@]}"
|
||||
if [[ ! -f "$idsdownfile" ]]
|
||||
if [[ ! -f "${idsdownfile}" ]]
|
||||
then
|
||||
for b in "${sitesdown[@]}"
|
||||
do
|
||||
loop_2 "$b" &
|
||||
loop_2 "${b}" &
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)/2) ]]
|
||||
then
|
||||
wait -n
|
||||
|
@ -67,14 +67,14 @@ then
|
|||
fi
|
||||
while read -r lineb; do
|
||||
#The community no longer exists, delete
|
||||
loop_3 "$lineb" &
|
||||
loop_3 "${lineb}" &
|
||||
if [[ $(jobs -r -p | wc -l) -ge $(expr $(getconf _NPROCESSORS_ONLN)/2) ]]
|
||||
then
|
||||
wait -n
|
||||
fi
|
||||
wait
|
||||
done < "$idsdownfile"
|
||||
rm "$tmpfile" 2> /dev/null
|
||||
rm "$idsdownfile" 2> /dev/null
|
||||
done < "${idsdownfile}"
|
||||
rm "${tmpfile}" 2> /dev/null
|
||||
rm "${idsdownfile}" 2> /dev/null
|
||||
date
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue