-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanupBootstrapArchives.sh
More file actions
executable file
·60 lines (52 loc) · 2.07 KB
/
cleanupBootstrapArchives.sh
File metadata and controls
executable file
·60 lines (52 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# ============================================================================
#
# FILE: cleanupBootstrapArchives.sh
#
# SPDX-FileCopyrightText: © 2020 Alias Developers
# SPDX-License-Identifier: MIT
#
# DESCRIPTION: Helper script to remove outdated bootstrap archives
#
# AUTHOR: HLXEasy
# PROJECT: https://alias.cash/
# https://github.com/aliascash/bootstrap-updater
#
# ============================================================================
# Backup where we came from
callDir=$(pwd)
ownLocation="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
scriptName=$(basename $0)
currentDate=$(date +%Y-%m-%d)
cd || exit
testnetSuffix=''
# Check if testnet bootstrap should be created
if [[ $1 = '-t' ]] ; then
shift
echo "Cleanup bootstrap archives for TESTNET"
testnetSuffix='-Testnet'
else
echo "Cleanup bootstrap archives"
fi
cd /var/www/html/files/bootstrap || exit 1
#cd /tmp/bootstrap-cleanup-test || exit 1
echo "Wipe out current bootstrap content"
previousBootstrapPartsIndex=$(readlink BootstrapChainParts${testnetSuffix}.previous.txt)
latestBootstrapPartsIndex=$(readlink BootstrapChainParts${testnetSuffix}.txt)
if [[ -e ${previousBootstrapPartsIndex} ]] && [[ -e ${latestBootstrapPartsIndex} ]] ; then
if [[ $latestBootstrapPartsIndex == *"$currentDate"* ]] ; then
echo "Latest bootstrap archive is from today, nothing to cleanup"
elif [[ "${previousBootstrapPartsIndex}" = "${latestBootstrapPartsIndex}" ]] ; then
echo "Current and previous bootstrap link pointing to the same index file, nothing to cleanup"
else
# shellcheck disable=SC2162,SC2034
while read hash filename ; do
rm -f "${filename}"
done < "${previousBootstrapPartsIndex}"
rm -f "${previousBootstrapPartsIndex}"
echo "Rotating latest bootstrap"
rm -f BootstrapChainParts${testnetSuffix}.previous.txt && ln -s "${latestBootstrapPartsIndex}" BootstrapChainParts${testnetSuffix}.previous.txt
fi
else
echo "Current a/o previous bootstrap index not found, nothing to cleanup"
fi