-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
132 lines (108 loc) · 3.88 KB
/
Copy pathinstall.sh
File metadata and controls
132 lines (108 loc) · 3.88 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
set -e
REPO="Craemon/Packtools"
if [ -n "$TAG" ]; then
LATEST_TAG="$TAG"
echo "Using specified tag: $LATEST_TAG"
else
echo "Fetching latest release from GitHub ($REPO)..."
LATEST_TAG=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
if [ -z "$LATEST_TAG" ]; then
echo "Error: Could not determine release version."
exit 1
fi
echo "Installing Packtools $LATEST_TAG..."
# 1. Download CLI Binary
echo "Downloading CLI..."
sudo curl -sSL "https://github.com/$REPO/releases/download/$LATEST_TAG/packtools-linux-amd64" -o /usr/local/bin/packtools
sudo chmod 755 /usr/local/bin/packtools
# 2. Download Core Server JAR
echo "Downloading Core Server..."
sudo mkdir -p /usr/local/lib/packtools
sudo curl -sSL "https://github.com/$REPO/releases/download/$LATEST_TAG/core-all.jar" -o /usr/local/lib/packtools/core.jar
sudo chmod 644 /usr/local/lib/packtools/core.jar
# 3. Create 'packtools-server' wrapper script
cat <<'EOF' | sudo tee /usr/local/bin/packtools-server > /dev/null
#!/bin/sh
exec java -jar /usr/local/lib/packtools/core.jar "$@"
EOF
sudo chmod 755 /usr/local/bin/packtools-server
# 4. Generate default ~/.config/packtools/config.yaml if missing
CONFIG_DIR="$HOME/.config/packtools"
CONFIG_FILE="$CONFIG_DIR/config.yaml"
CURRENT_DIR="$(pwd)"
if [ ! -f "$CONFIG_FILE" ]; then
mkdir -p "$CONFIG_DIR"
# Default fallback if installer is run directly from $HOME
if [ "$CURRENT_DIR" = "$HOME" ]; then
SUGGESTED_DIR="$HOME/Projects"
else
SUGGESTED_DIR="$CURRENT_DIR"
fi
TARGET_DIR=""
# Read directly from /dev/tty to support `curl | sh` pipeline
if [ -c /dev/tty ]; then
echo ""
printf "Enter repository root path [%s]: " "$SUGGESTED_DIR"
read -r INPUT_DIR < /dev/tty
TARGET_DIR="${INPUT_DIR:-$SUGGESTED_DIR}"
else
TARGET_DIR="$SUGGESTED_DIR"
fi
# Expand tilde ~ if user entered it manually
TARGET_DIR=$(eval echo "$TARGET_DIR")
cat <<EOF > "$CONFIG_FILE"
# Packtools Configuration
repoRoot: "$TARGET_DIR"
EOF
echo "✓ Created config at $CONFIG_FILE (repoRoot: $TARGET_DIR)"
fi
# 5. Setup Background Systemd Service
SYSTEMD_ENABLED=0
if command -v systemctl >/dev/null 2>&1 && systemctl --user status >/dev/null 2>&1; then
SYSTEMD_USER_DIR="$HOME/.config/systemd/user"
mkdir -p "$SYSTEMD_USER_DIR"
cat <<EOF > "$SYSTEMD_USER_DIR/packtools.service"
[Unit]
Description=Packtools Core Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/packtools-server
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload 2>/dev/null || true
systemctl --user enable packtools.service 2>/dev/null || true
systemctl --user restart packtools.service 2>/dev/null || true
SYSTEMD_ENABLED=1
# Give server a moment to spin up before CLI completion calls the API
sleep 1
fi
# 6. Setup Bash Completion
if [ -d /etc/bash_completion.d ]; then
if /usr/local/bin/packtools completion bash > /tmp/packtools_completion 2>/dev/null; then
if [ -s /tmp/packtools_completion ]; then
sudo mv /tmp/packtools_completion /etc/bash_completion.d/packtools
sudo chmod 644 /etc/bash_completion.d/packtools
echo "Installed bash autocompletion."
else
rm -f /tmp/packtools_completion
fi
else
rm -f /tmp/packtools_completion
fi
fi
echo ""
echo "✓ Installation complete ($LATEST_TAG)!"
echo " To configure your Packs folder path, edit: $CONFIG_FILE"
if [ "$SYSTEMD_ENABLED" -eq 1 ]; then
echo " Background server automatically started/restarted via systemd (packtools.service)."
echo " Run 'packtools' to start using CLI commands immediately."
else
echo " ℹ systemd user session not detected."
echo " To run the server manually, execute: packtools-server &"
fi