-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
100 lines (86 loc) · 2.62 KB
/
Copy pathinstall.sh
File metadata and controls
100 lines (86 loc) · 2.62 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
#!/bin/bash
set -e
# Configuration
REPO="codaea/simpleprint"
SERVICE_NAME="simpleprint"
INSTALL_DIR="/usr/bin"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
WORK_DIR="$HOME/.simpleprint"
# Detect architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
ARCH=amd64
;;
aarch64)
ARCH=arm64
;;
armv7l)
ARCH=armv7
;;
armv6l)
ARCH=armv6
;;
*)
echo "Unsupported architecture: $ARCH"
exit 1
;;
esac
# Get latest release tag
TAG=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | grep 'tag_name' | cut -d '"' -f4)
if [ -z "$TAG" ]; then
echo "Failed to fetch latest release tag."
exit 1
fi
# Download binary
BINARY_URL="https://github.com/${REPO}/releases/download/${TAG}/${SERVICE_NAME}_${TAG#v}_linux_${ARCH}"
TMP_BIN="/tmp/${SERVICE_NAME}"
echo "Downloading $BINARY_URL ..."
curl -L "$BINARY_URL" -o "$TMP_BIN"
chmod +x "$TMP_BIN"
# If binary exists, backup and replace
if [ -f "$INSTALL_DIR/$SERVICE_NAME" ]; then
echo "Existing binary detected at $INSTALL_DIR/$SERVICE_NAME. Updating..."
sudo mv "$INSTALL_DIR/$SERVICE_NAME" "$INSTALL_DIR/${SERVICE_NAME}.bak.$(date +%s)"
fi
sudo mv "$TMP_BIN" "$INSTALL_DIR/$SERVICE_NAME"
sudo chmod +x "$INSTALL_DIR/$SERVICE_NAME"
# Ensure service file exists, download if missing
SERVICE_SRC="$WORK_DIR/sample.service"
if [ ! -d "$WORK_DIR" ]; then
mkdir -p "$WORK_DIR"
fi
if [ ! -f "$SERVICE_SRC" ]; then
echo "sample.service not found locally. Downloading from GitHub..."
RAW_URL="https://raw.githubusercontent.com/${REPO}/${TAG}/sample.service"
curl -L "$RAW_URL" -o "$SERVICE_SRC"
fi
sudo cp "$SERVICE_SRC" "/etc/systemd/system/simpleprint.service"
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl restart "$SERVICE_NAME"
# Ensure .env file exists in /home/coda/simpleprint
# Use /etc/simpleprint/.env for environment
ENV_DIR="/etc/simpleprint"
ENV_FILE="$ENV_DIR/.env"
if [ ! -d "$ENV_DIR" ]; then
sudo mkdir -p "$ENV_DIR"
fi
if [ ! -f "$ENV_FILE" ]; then
echo ".env not found in $ENV_DIR. Creating a default .env file..."
RAW_ENV_URL="https://raw.githubusercontent.com/${REPO}/${TAG}/lib/example.env"
if curl --output /dev/null --silent --head --fail "$RAW_ENV_URL"; then
sudo curl -L "$RAW_ENV_URL" -o "$ENV_FILE"
else
sudo tee "$ENV_FILE" > /dev/null <<EOF
# Default environment for simpleprint
PRINTER_DEVICE=/dev/usb/lp0
LOG_LEVEL=info
PORT=8080
EOF
fi
fi
# Update systemd service to use new env file location
sudo sed -i "s|^EnvironmentFile=.*|EnvironmentFile=$ENV_FILE|" /etc/systemd/system/simpleprint.service
echo "Installation complete. Service status:"
systemctl status "$SERVICE_NAME" --no-pager