You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.5 KiB
Bash

#!/bin/bash
# fanta <fanta@56k.es>
# Dependences: sqlite3
user=$(whoami)
dbDir="$HOME/.g"
dbName="games.db"
opt="$1"
version="0.1"
function who { if [ "$(whoami)" = "root" ]; then exit; fi }
function checkDBDir { if [ ! -d "$dbDir" ]; then mkdir -p "$dbDir"; fi }
function createDBStructure {
echo "CREATE TABLE IF NOT EXISTS GAMES (ID INTEGER PRIMARY KEY, NAME TEXT, YEAR TEXT, MONTH TEXT, PLATFORM TEXT);" | sqlite3 "$dbDir/$dbName"
}
function checkDBFile { if [ ! -f "$dbDir/$dbName" ]; then createDBStructure; fi }
function helpGames {
echo -e "g $version - fanta <fanta@56k.es>\n"
echo "-h Show this help"
echo "-l List Games"
echo "-a Add Games"
echo -e "-d Del Games\n"
}
function addGames {
read -p "Nombre del Juego: " nameGame
read -p "Nombre del Año: " anoGame
read -p "Nombre del Mes: " mesGame
read -p "Nombre del Plataforma: " plataformaGame
echo "INSERT INTO GAMES (NAME,YEAR,MONTH,PLATFORM) VALUES ('$nameGame','$anoGame','$mesGame','$plataformaGame');" | sqlite3 "$dbDir/$dbName"
}
function delGames {
read -p "ID del Juego: " idGame
echo "DELETE FROM GAMES WHERE ID = $idGame;" | sqlite3 "$dbDir/$dbName"
}
function listGames {
echo "SELECT * FROM GAMES" | sqlite3 "$dbDir/$dbName"
}
function checkOpt {
if [ -z "$opt" ]; then helpGames; fi
if [ "$opt" = "-h" ]; then helpGames; fi
if [ "$opt" = "-l" ]; then listGames; fi
if [ "$opt" = "-a" ]; then addGames; fi
if [ "$opt" = "-d" ]; then delGames; fi
}
function main() {
who
checkDBDir
checkDBFile
checkOpt
}
main