db fully handeled by python
This commit is contained in:
@ -3,12 +3,11 @@
|
||||
|
||||
# Function to display usage
|
||||
usage() {
|
||||
echo "Usage: $0 [-i] [-v] [-x] -d /path/to/drive_records.db [-a 'serial,model,flavor,capacity,TBW,smart' OR -u 'serial,TBW,smart'] "
|
||||
echo "Options - choose only one of a, u, or i, v and x are optional and not exclusive, and always provide the d"
|
||||
echo "Usage: $0 [-v] [-x] -d /path/to/drive_records.db [-a 'serial,model,flavor,capacity,TBW,smart' OR -u 'serial,TBW,smart'] "
|
||||
echo "Options - choose only one of a or u, v and x are optional and not exclusive, and always provide the d"
|
||||
echo " -d /path/to/drive_records.db Specify path to DB, required"
|
||||
echo " -a 'serial,model,flavor,capacity,TBW,smart' Add new drive to sqlite db"
|
||||
echo " -u 'serial,TBW,smart' Update drive data in sqlite db"
|
||||
echo " -i Initialize database if not present"
|
||||
echo " -v Output verbose information"
|
||||
echo " -x Output debug information"
|
||||
exit 1
|
||||
@ -60,7 +59,7 @@ CREATE_TABLE="CREATE TABLE drive_records (
|
||||
);"
|
||||
|
||||
# Parse command line options
|
||||
while getopts ":d:a:u:ivx" opt; do
|
||||
while getopts ":d:a:u:vx" opt; do
|
||||
case ${opt} in
|
||||
v ) # process option v
|
||||
echo "Be Verbose"
|
||||
@ -95,13 +94,6 @@ while getopts ":d:a:u:ivx" opt; do
|
||||
VALID_FLAGS=true
|
||||
DRIVE_DATA=$OPTARG
|
||||
;;
|
||||
i ) # process option i
|
||||
if [ "$BE_VERBOSE" == "true" ] ; then
|
||||
echo "initialize database"
|
||||
fi
|
||||
VALID_FLAGS=true
|
||||
init_db
|
||||
;;
|
||||
\? ) usage
|
||||
;;
|
||||
esac
|
||||
@ -158,11 +150,9 @@ if [ "$ADD_DRIVE" == "true" ]; then
|
||||
fi
|
||||
DRIVE_EXISTS=$(curl -s http://0.0.0.0:5000/check?serial_lookup=${data[0]} | jq .serial_number_exists)
|
||||
if [ "$DRIVE_EXISTS" == "false" ]; then
|
||||
# Insert the values into the database
|
||||
sqlite3 "$DB_FILE" <<EOF
|
||||
INSERT INTO drive_records (serial, model, flavor, capacity, TBW, smart)
|
||||
VALUES ('${data[0]}', '${data[1]}', '${data[2]}', '${data[3]}', '${data[4]}', '${data[5]}');
|
||||
EOF
|
||||
# Insert the values into the database
|
||||
echo "http://0.0.0.0:5000/add_drive?serial='${data[0]}'&model='${data[1]}'&flavor='${data[2]}'&capacity='${data[3]}'&TBW='${data[4]}'&smart='${data[5]}'"
|
||||
curl -s "http://0.0.0.0:5000/add_drive?serial='${data[0]}'&model='${data[1]}'&flavor='${data[2]}'&capacity='${data[3]}'&TBW='${data[4]}'&smart='${data[5]}'"
|
||||
else
|
||||
if [ "$BE_VERBOSE" == "true" ] ; then
|
||||
echo "Drive already exists, skipping"
|
||||
@ -196,11 +186,8 @@ if [ "$UPDATE_DRIVE" == "true" ]; then
|
||||
DRIVE_EXISTS=$(curl -s http://0.0.0.0:5000/check?serial_lookup=${data[0]} | jq .serial_number_exists)
|
||||
if [ "$DRIVE_EXISTS" == "true" ]; then
|
||||
# Update the values in the database
|
||||
sqlite3 "$DB_FILE" <<EOF
|
||||
UPDATE drive_records
|
||||
SET TBW = '${data[1]}', smart = '${data[2]}'
|
||||
WHERE serial = '${data[0]}';
|
||||
EOF
|
||||
echo "http://0.0.0.0:5000/update_drive?serial='${data[0]}'&TBW='${data[1]}'&smart='${data[2]}"
|
||||
curl -s "http://0.0.0.0:5000/update_drive?serial='${data[0]}'&TBW='${data[1]}'&smart='${data[2]}"
|
||||
else
|
||||
if [ "$BE_VERBOSE" == "true" ] ; then
|
||||
echo "Drive does not exist, skipping"
|
||||
|
||||
Reference in New Issue
Block a user