Apply shellcheck recommendations

This commit is contained in:
Benoit S 2021-08-29 09:10:46 +09:00
parent 63477444b9
commit add2815b6d

View file

@ -29,37 +29,37 @@ PREV_ERRORS_LOG=/tmp/tootpaste_prev_errors
accounts_cull() {
$DRY_RUN && $TOOTCTL accounts cull --dry-run --concurrency $DB_POOL > $CULL_LOG
$DRY_RUN || $TOOTCTL accounts cull --concurrency $DB_POOL > $CULL_LOG
$DRY_RUN && $TOOTCTL accounts cull --dry-run --concurrency "$DB_POOL" > "$CULL_LOG"
$DRY_RUN || $TOOTCTL accounts cull --concurrency "$DB_POOL" > "$CULL_LOG"
# Remove instances that have an expired certificate from more than
# TLS_EXPIRED_MAX_SEC
grep 'certificate has expired' $CULL_LOG \
grep 'certificate has expired' "$CULL_LOG" \
| awk '{print $NF}' \
| cut -d'/' -f3 \
| sort -u \
> $TLS_EXPIRED_LOG
> "$TLS_EXPIRED_LOG"
while read instance; do
while read -r instance; do
TLS_EXPIRED_TS=$(
date -d "$(
echo Q \
| openssl s_client \
-servername $instance \
-connect ${instance}:443 \
-servername "$instance" \
-connect "${instance}":443 \
2>/dev/null \
| openssl x509 -noout -dates \
| grep 'notAfter' \
| cut -d'=' -f2
)" +%s
)
DATE_DIFF=$(($(date +%s) - $TLS_EXPIRED_TS))
DATE_DIFF=$(($(date +%s) - TLS_EXPIRED_TS))
if [[ $DATE_DIFF -gt $TLS_EXPIRED_MAX_SEC ]]; then
echo "${instance} has a certificate expired for more than TLS_EXPIRED_MAX_SEC, purging..."
$DRY_RUN && $TOOTCTL domains purge --concurrency $DB_POOL --dry-run $instance
$DRY_RUN || $TOOTCTL domains purge --concurrency $DB_POOL $instance
$DRY_RUN && $TOOTCTL domains purge --concurrency "$DB_POOL" --dry-run "$instance"
$DRY_RUN || $TOOTCTL domains purge --concurrency "$DB_POOL" "$instance"
fi
done < $TLS_EXPIRED_LOG
done < "$TLS_EXPIRED_LOG"
# Log other instances errors, then if they were already in the log, purge
# them
@ -68,48 +68,48 @@ accounts_cull() {
-e 'timed out' \
-e 'sslv3 alert handshake failure' \
-e 'TooManyRedirectsError' \
$CULL_LOG \
"$CULL_LOG" \
| awk '{print $NF}' \
| cut -d'/' -f3 \
| sort -u \
> $OTHER_ERRORS_LOG
> "$OTHER_ERRORS_LOG"
while read instance; do
if grep -q $instance $PREV_ERRORS_LOG; then
while read -r instance; do
if grep -q "$instance" $PREV_ERRORS_LOG; then
error=false
echo "${instance} was already in error last time your ran tootpaste, trying access..."
curl \
--silent \
--show-error \
--max-time $INSTANCE_LAST_CHANCE_TIMEOUT \
https://${instance} \
https://"${instance}" \
|| error=true
if $error; then
echo "${instance} still cannot be accessed, purging..."
$DRY_RUN && $TOOTCTL domains purge --concurrency $DB_POOL --dry-run $instance
$DRY_RUN || $TOOTCTL domains purge --concurrency $DB_POOL $instance
$DRY_RUN && $TOOTCTL domains purge --concurrency "$DB_POOL" --dry-run "$instance"
$DRY_RUN || $TOOTCTL domains purge --concurrency "$DB_POOL" "$instance"
fi
fi
done < $OTHER_ERRORS_LOG
cat $OTHER_ERRORS_LOG >> $PREV_ERRORS_LOG
done < "$OTHER_ERRORS_LOG"
cat "$OTHER_ERRORS_LOG" >> $PREV_ERRORS_LOG
}
cache_recount(){
$DRY_RUN && echo 'Not running cache recount in dry run.'
$DRY_RUN || $TOOTCTL cache recount accounts --concurrency $DB_POOL
$DRY_RUN || $TOOTCTL cache recount statuses --concurrency $DB_POOL
$DRY_RUN || $TOOTCTL cache recount accounts --concurrency "$DB_POOL"
$DRY_RUN || $TOOTCTL cache recount statuses --concurrency "$DB_POOL"
}
media_remove(){
$DRY_RUN && $TOOTCTL media remove --days $MEDIA_REMOVE_DAYS --concurrency $DB_POOL --dry-run
$DRY_RUN || $TOOTCTL media remove --days $MEDIA_REMOVE_DAYS --concurrency $DB_POOL
$DRY_RUN && $TOOTCTL media remove --days $MEDIA_REMOVE_DAYS --concurrency "$DB_POOL" --dry-run
$DRY_RUN || $TOOTCTL media remove --days $MEDIA_REMOVE_DAYS --concurrency "$DB_POOL"
$DRY_RUN && $TOOTCTL media remove-orphans --dry-run
$DRY_RUN || $TOOTCTL media remove-orphans
$DRY_RUN && $TOOTCTL preview_cards remove --days $MEDIA_REMOVE_DAYS --concurrency $DB_POOL --dry-run
$DRY_RUN || $TOOTCTL preview_cards remove --days $CARDS_REMOVE_DAYS --concurrency $DB_POOL --link
$DRY_RUN && $TOOTCTL preview_cards remove --days $MEDIA_REMOVE_DAYS --concurrency "$DB_POOL" --dry-run
$DRY_RUN || $TOOTCTL preview_cards remove --days $CARDS_REMOVE_DAYS --concurrency "$DB_POOL" --link
}
statuses_remove(){