Init commit

This commit is contained in:
2025-11-02 13:11:42 -08:00
commit 650b481463
16 changed files with 983 additions and 0 deletions

66
files/scripts/test.sh Normal file
View File

@ -0,0 +1,66 @@
#!/bin/bash
# Function to display usage information
usage() {
echo "Usage: $0 -a \"serial,model,capacity,TBW,smart\""
exit 1
}
# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
usage
fi
# Parse command-line arguments
while getopts ":a:" opt; do
case ${opt} in
a)
# Extract the comma-separated list of attributes
IFS=',' read -ra ATTRS <<< "$OPTARG"
;;
\?)
echo "Invalid option: $OPTARG" 1>&2
usage
;;
esac
done
shift $((OPTIND -1))
# Check if the database file exists, otherwise create it and initialize the table
DB_FILE="drive_records.db"
if [ ! -f "$DB_FILE" ]; then
sqlite3 "$DB_FILE" <<EOF
CREATE TABLE drive_records (id INTEGER PRIMARY KEY, serial TEXT NOT NULL, model TEXT NOT NULL, capacity TEXT NOT NULL, TBW TEXT NOT NULL, smart TEXT NOT NULL);
EOF
fi
# Read the input data from stdin
while read -r line; do
# Extract values for each attribute and insert into the database
VALUES=()
IFS=' ' read -ra PARTS <<< "$line"
for ((i = 0; i < ${#ATTRS[@]}; i++)); do
case "${ATTRS[i]}" in
serial)
VALUES+=("${PARTS[0]}")
;;
model)
VALUES+=("${PARTS[1]}")
;;
capacity)
VALUES+=("${PARTS[2]}")
;;
TBW)
VALUES+=("${PARTS[3]}")
;;
smart)
VALUES+=("${PARTS[4]}")
;;
esac
done
# Insert the values into the database
sqlite3 "$DB_FILE" <<EOF
INSERT INTO drive_records (serial, model, capacity, TBW, smart) VALUES ('${VALUES[0]}', '${VALUES[1]}', '${VALUES[2]}', '${VALUES[3]}', '${VALUES[4]}');
EOF
done <<< "$(cat -)"