-
Notifications
You must be signed in to change notification settings - Fork 0
/
kb-query.upgrade
executable file
·105 lines (74 loc) · 2.08 KB
/
kb-query.upgrade
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
#
# kb-query installation
#
set -euo pipefail
# Require root for install to /usr/share/kb-query
if ((EUID)); then
sudo -ln &>/dev/null || { >&2 echo "Requires root, or non-interactive sudo privileges."; exit 1; }
exec sudo -n "$0" "$@"
exit 1
fi
readonly PRG0="$(readlink -en -- "$0")"
readonly PRGDIR="${PRG0%/*}" PRG="${PRG0##*/}"
# Help
if [[ "${1:-}" == '-h' || "${1:-}" == '--help' ]]; then
echo "kb-query install/upgrade program"
echo "usage: $PRG"
exit 0
fi
welcome_and_exit() {
# Welcome message
echo
printf '%*s\n' "${COLUMNS:-78}" '' | tr ' ' '-'
cat <<EOT
# Welcome ${1:-}to kb-query
- a simple interface into YaTTI knowledgebases
- https://yatti.id/
## Useful starter commands:
- Help for kb-query utility
kb-query --help
- Overview YaTTI knowledgebase (accesses API)
kb-query help
- List YaTTI knowledgebases (accesses API)
kb-query list
- Query knowledgebase (accesses API)
kb-query appliedanthropology "Concisely define 'applied anthropology'."
- Query knowledgebase for context (accesses API)
kb-query appliedanthropology -c "Concisely define 'applied anthropology'."
EOT
if [[ -d "$BACKUP_DIR" ]]; then
echo
echo "Backup of kb-query is available at $BACKUP_DIR."
fi
echo
echo 'kb-query --version'
kb-query --version
echo
echo "kb-query ${2:-install} complete."
exit 0
}
INSTALL_DIR="/usr/share/kb-query"
BACKUP_DIR="/var/backups/kb-query"
# Change to /usr/share
cd /usr/share
if [[ -d "$INSTALL_DIR" ]]; then
echo "'$INSTALL_DIR' already exists."
# Make backup
rm -rf "$BACKUP_DIR"
cp -a "$INSTALL_DIR" "$BACKUP_DIR"
echo "Backup created at $BACKUP_DIR."
# Upgrade using git pull
cd "$INSTALL_DIR"
git pull origin main
echo
welcome_and_exit 'back ' upgrade
fi
# Dependencies
apt -yqq install git curl jq gridsite-clients
# Clone the repository
git clone -q https://github.com/Open-Technology-Foundation/kb-query.git "$INSTALL_DIR"
# Create symlink in /usr/local/bin
ln -sf "$INSTALL_DIR/kb-query" /usr/local/bin/
welcome_and_exit '' install
# fin