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