-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
64 lines (51 loc) · 1.48 KB
/
install.sh
File metadata and controls
64 lines (51 loc) · 1.48 KB
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
#!/usr/bin/env bash
set -euo pipefail
INSTALL_DIR="$HOME/.dbviewer"
REPO_URL="https://github.com/cloudpad9/db-viewer-python.git"
echo "==> Installing DB Viewer..."
mkdir -p "$INSTALL_DIR"
TMPDIR=$(mktemp -d)
git clone --depth 1 "$REPO_URL" "$TMPDIR/src"
python3 -m venv "$INSTALL_DIR/.venv"
source "$INSTALL_DIR/.venv/bin/activate"
pip install --quiet "$TMPDIR/src"
mkdir -p "$INSTALL_DIR/bin"
cat > "$INSTALL_DIR/bin/dbviewer" << 'WRAPPER'
#!/usr/bin/env bash
source "$HOME/.dbviewer/.venv/bin/activate"
python -m dbviewer "$@"
WRAPPER
chmod +x "$INSTALL_DIR/bin/dbviewer"
for rc in "$HOME/.bashrc" "$HOME/.zshrc"; do
if [ -f "$rc" ]; then
grep -q '.dbviewer/bin' "$rc" || echo 'export PATH="$HOME/.dbviewer/bin:$PATH"' >> "$rc"
fi
done
mkdir -p "$INSTALL_DIR/data"
if [ ! -f "$INSTALL_DIR/data/users.json" ]; then
echo ""
read -p "Admin username [admin]: " ADMIN_USER
ADMIN_USER=${ADMIN_USER:-admin}
read -sp "Admin password: " ADMIN_PASS
echo ""
"$INSTALL_DIR/bin/dbviewer" --create-user "$ADMIN_USER" "$ADMIN_PASS"
fi
if [ ! -f "$INSTALL_DIR/data/connections.json" ]; then
cat > "$INSTALL_DIR/data/connections.json" << 'EOF'
[
{
"name": "Local MySQL",
"type": "mysql",
"server": "localhost",
"port": 3306,
"database": "mysql",
"user": "root",
"password": ""
}
]
EOF
fi
rm -rf "$TMPDIR"
echo ""
echo "==> DB Viewer installed successfully!"
echo " Open a new terminal and run: dbviewer"