-
Notifications
You must be signed in to change notification settings - Fork 4
/
vacuum-fastladder-db.sh
executable file
·79 lines (68 loc) · 2.58 KB
/
vacuum-fastladder-db.sh
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/sh
########################################################################
# vacuum-fastladder-db.sh: Optimize Fastladder SQLite Database
#
# Description:
# This script is used to vacuum and optimize the Fastladder SQLite database.
# It creates a new database file from the existing database after running the vacuum command.
#
# Author: id774 (More info: http://id774.net)
# Source Code: https://github.com/id774/scripts
# License: LGPLv3 (Details: https://www.gnu.org/licenses/lgpl-3.0.html)
# Contact: [email protected]
#
# Version History:
# v1.3 2024-01-22
# Integrated check_commands function for dependency checks.
# v1.2 2023-12-08
# Added file and directory existence checks for the Fastladder database.
# v1.1 2023-12-07
# Added check for sqlite3 program and updated documentation.
# v1.0 2019-03-18
# Initial release.
#
# Usage:
# Run the script from the command line:
# ./vacuum-fastladder-db.sh
#
# Notes:
# - Ensure that the Fastladder application is not actively using the database when this script is run.
# - This script should be run from the root directory of the Fastladder installation.
# - Backup the existing database before running this script as a safety precaution.
# - The script requires sqlite3 to be installed on the system.
#
########################################################################
check_commands() {
for cmd in "$@"; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: Command '$cmd' is not installed. Please install $cmd and try again."
exit 127
elif ! [ -x "$(command -v "$cmd")" ]; then
echo "Error: Command '$cmd' is not executable. Please check the permissions."
exit 126
fi
done
}
# Check for required commands
check_commands sqlite3
# Define the Fastladder database directory and file path
DB_DIR="$HOME/fastladder/db"
DB_PATH="$DB_DIR/fastladder.db"
# Check if the database directory exists
if [ ! -d "$DB_DIR" ]; then
echo "Error: Fastladder database directory does not exist. Please check the path and try again."
exit 2
fi
# Check if the database file exists
if [ ! -f "$DB_PATH" ]; then
echo "Error: Fastladder database file does not exist. Please check the path and try again."
exit 1
fi
# Navigate to the Fastladder database directory
cd "$DB_DIR"
# Remove existing temporary database file if it exists
test -f new.db && rm -vf new.db
# Vacuum the Fastladder SQLite database
sqlite3 "$DB_PATH" vacuum
# Dump the current database and create a new optimized database
sqlite3 fastladder.db .dump | sqlite3 new.db