A tool for managing my collection of notes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

#!/usr/bin/env bash
initKnowledgeBase(){
local output
necho -e "${YELLOW}Initialising Knowledge base${NC}"
vecho "Directory: $dataDir"
if [ "$verbose" -gt 0 ]; then
output="/dev/stdout"
else
output="/dev/null"
fi
[ -e "$dataDir" ] && die "$dataDir already exists"
mkdir -p "$dataDir"
if [ "$dogit" -gt 0 ]; then
git init "$dataDir" > "$output"
# TODO: make gitignore use new sqlite file
# Datadir always has a trailing slash
echo "/knowledgebase.sqlite3" >> "${dataDir}.gitignore"
git -C "$dataDir" add .gitignore > "$output"
git -C "$dataDir" commit -m "Knowledge base initialised" > "$output"
if type -p git-lfs; then
git -C "$dataDir" lfs install > "$output"
for i in "jpg" "jpeg" "gif" "png" "pdf"; do
git -C "$dataDir" lfs track "*.$i" > "$output"
done
git -C add .gitattributes
git commit -m "Initialises Git lfs"
fi
fi
initDB
}
initDB(){
vecho "Creating Database"
echo 'CREATE TABLE items
(id integer primary key, filename text, title text, type text);
CREATE TABLE tags
(id integer primary key, name text);
CREATE TABLE links
(id integer primary key, itemID integer, tagID integer); ' |
sqlite3 "${sqliteFile}"
necho -e "${GREEN}Initialised Knowledge base${NC}"
}