Compare commits

..

No commits in common. "main" and "0.1.0" have entirely different histories.
main ... 0.1.0

3 changed files with 49 additions and 147 deletions

View file

@ -1,41 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
### Changed
### Removed
## [0.2.0] - 2022-04-22
### Added
- Test condition when there are no errors
- Log unjoinable instances
- A message when instance can be accessed
### Fixed
- Silence curl's output
## [0.1.1] - 2021-08-29
### Added
- Openssl in `check_command`
### Changed
- Wrapped more lines
## [0.1.0] - 2021-08-29
### Added
- First version

View file

@ -44,11 +44,11 @@ and date of expired certificate, default: `1210000`, 2w
- `INSTANCE_LAST_CHANCE_TIMEOUT`, integer, timeout in seconds to connect to an - `INSTANCE_LAST_CHANCE_TIMEOUT`, integer, timeout in seconds to connect to an
instance that was previously not accessible, default: `30` instance that was previously not accessible, default: `30`
- `MEDIA_REMOVE_DAYS`, integer, how old in days media attachments have to be - `MEDIA_REMOVE_DAYS`, integer, how old in days media attachments have to be
before getting removed, default: `7` before getting removed
- `CARDS_REMOVE_DAYS`, integer, how old in days cards previews have to be - `CARDS_REMOVE_DAYS`, integer, how old in days cards previews have to be
before getting removed, default: `15` before getting removed
- `STATUSES_REMOVE_DAYS`, integer, how old in days unreferenced statuses have - `STATUSES_REMOVE_DAYS`, integer, how old in days unreferenced statuses have
to be before getting removed, default: `30` to be before getting removed
Example: Example:

View file

@ -28,19 +28,11 @@ PREV_ERRORS_LOG=/tmp/tootpaste_prev_errors
accounts_cull() { accounts_cull() {
$DRY_RUN \ $DRY_RUN && $TOOTCTL accounts cull --dry-run --concurrency "$DB_POOL" > "$CULL_LOG"
&& $TOOTCTL accounts cull \ $DRY_RUN || $TOOTCTL accounts cull --concurrency "$DB_POOL" > "$CULL_LOG"
--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 # Remove instances that have an expired certificate from more than
# TLS_EXPIRED_MAX_SEC # TLS_EXPIRED_MAX_SEC
if grep -q 'certificate has expired' "$CULL_LOG"; then
grep 'certificate has expired' "$CULL_LOG" \ grep 'certificate has expired' "$CULL_LOG" \
| awk '{print $NF}' \ | awk '{print $NF}' \
| cut -d'/' -f3 \ | cut -d'/' -f3 \
@ -63,45 +55,23 @@ accounts_cull() {
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 \ $DRY_RUN && $TOOTCTL domains purge --concurrency "$DB_POOL" --dry-run "$instance"
&& $TOOTCTL domains purge \ $DRY_RUN || $TOOTCTL domains purge --concurrency "$DB_POOL" "$instance"
--concurrency "$DB_POOL" \
--dry-run \
"$instance"
$DRY_RUN \
|| $TOOTCTL domains purge \
--concurrency "$DB_POOL" \
"$instance"
fi fi
done < "$TLS_EXPIRED_LOG" done < "$TLS_EXPIRED_LOG"
fi
# Log other instances errors, then if they were already in the log, purge them # Log other instances errors, then if they were already in the log, purge
if grep -q 'https' "$CULL_LOG"; then # them
grep \ grep \
-e 'certificate verify failed' \ -e 'certificate verify failed' \
-e 'timed out' \ -e 'timed out' \
-e 'sslv3 alert handshake failure' \ -e 'sslv3 alert handshake failure' \
-e 'TooManyRedirectsError' \ -e 'TooManyRedirectsError' \
-e 'EndlessRedirectError' \
-e 'HostValidationError' \
"$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"
fi
# Log unjoinable instances, then if they were already in the log, purge them
if grep -q 'not available during the check:' "$CULL_LOG"; then
grep \
-A 9999 \
'not available during the check:' \
"$CULL_LOG" \
| tail -n +2 \
| sed -E 's/\s+//' \
> "$OTHER_ERRORS_LOG"
fi
test -f $PREV_ERRORS_LOG || touch $PREV_ERRORS_LOG test -f $PREV_ERRORS_LOG || touch $PREV_ERRORS_LOG
while read -r instance; do while read -r instance; do
@ -109,7 +79,6 @@ accounts_cull() {
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 \
--output /dev/null \
--silent \ --silent \
--show-error \ --show-error \
--max-time "$INSTANCE_LAST_CHANCE_TIMEOUT" \ --max-time "$INSTANCE_LAST_CHANCE_TIMEOUT" \
@ -117,17 +86,8 @@ accounts_cull() {
|| 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 \ $DRY_RUN && $TOOTCTL domains purge --concurrency "$DB_POOL" --dry-run "$instance"
&& $TOOTCTL domains purge \ $DRY_RUN || $TOOTCTL domains purge --concurrency "$DB_POOL" "$instance"
--concurrency "$DB_POOL" \
--dry-run \
"$instance"
$DRY_RUN \
|| $TOOTCTL domains purge \
--concurrency "$DB_POOL" \
"$instance"
else
echo "${instance} can now be accessed, not purging!"
fi fi
fi fi
done < "$OTHER_ERRORS_LOG" done < "$OTHER_ERRORS_LOG"
@ -143,30 +103,13 @@ cache_recount(){
media_remove(){ media_remove(){
$DRY_RUN \ $DRY_RUN && $TOOTCTL media remove --days "$MEDIA_REMOVE_DAYS" --concurrency "$DB_POOL" --dry-run
&& $TOOTCTL media remove \ $DRY_RUN || $TOOTCTL media remove --days "$MEDIA_REMOVE_DAYS" --concurrency "$DB_POOL"
--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
$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 \ $DRY_RUN || $TOOTCTL preview_cards remove --days "$CARDS_REMOVE_DAYS" --concurrency "$DB_POOL" --link
&& $TOOTCTL preview_cards remove \
--days "$MEDIA_REMOVE_DAYS" \
--concurrency "$DB_POOL" \
--link \
--dry-run
$DRY_RUN \
|| $TOOTCTL preview_cards remove \
--days "$CARDS_REMOVE_DAYS" \
--concurrency "$DB_POOL" \
--link
} }
statuses_remove(){ statuses_remove(){
@ -179,7 +122,7 @@ check_command(){
command -v "$1" > /dev/null command -v "$1" > /dev/null
} }
for command in $TOOTCTL curl grep awk cut sort openssl; do for command in $TOOTCTL curl grep awk cut sort; do
check_command "$command" || (echo "$command not found, exiting..."; exit 1) check_command "$command" || (echo "$command not found, exiting..."; exit 1)
done done