-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall_mac.sh
More file actions
executable file
·150 lines (137 loc) · 5.28 KB
/
install_mac.sh
File metadata and controls
executable file
·150 lines (137 loc) · 5.28 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
set -e
BINARY_NAME="tsc-bridge"
APP_NAME="TSC Bridge.app"
INSTALL_DIR="/Applications"
PLIST_NAME="com.tsc-bridge.plist"
LAUNCH_AGENTS="$HOME/Library/LaunchAgents"
HOSTNAME="myprinter.com"
CONFIG_DIR="$HOME/.tsc-bridge"
CERT_DIR="$CONFIG_DIR/certs"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo ""
echo "╔══════════════════════════════════════╗"
echo "║ TSC Bridge — Instalador macOS ║"
echo "╚══════════════════════════════════════╝"
echo ""
# --- Kill existing instance ---
echo "[1/6] Deteniendo instancias previas..."
pkill -f "$BINARY_NAME" 2>/dev/null && echo " Detenido" || echo " Ninguna encontrada"
if launchctl list 2>/dev/null | grep -q "com.tsc-bridge"; then
launchctl unload "$LAUNCH_AGENTS/$PLIST_NAME" 2>/dev/null || true
echo " LaunchAgent descargado"
fi
sleep 1
# --- Install .app bundle or raw binary ---
echo ""
echo "[2/6] Instalando aplicación..."
if [ -d "$SCRIPT_DIR/$APP_NAME" ]; then
# Install .app bundle to /Applications
rm -rf "$INSTALL_DIR/$APP_NAME"
cp -R "$SCRIPT_DIR/$APP_NAME" "$INSTALL_DIR/$APP_NAME"
BINARY_PATH="$INSTALL_DIR/$APP_NAME/Contents/MacOS/$BINARY_NAME"
echo " ✓ $APP_NAME instalado en $INSTALL_DIR"
elif [ -f "$SCRIPT_DIR/$BINARY_NAME" ]; then
# Fallback: install raw binary to ~/bin
mkdir -p "$HOME/bin"
cp "$SCRIPT_DIR/$BINARY_NAME" "$HOME/bin/$BINARY_NAME"
chmod +x "$HOME/bin/$BINARY_NAME"
BINARY_PATH="$HOME/bin/$BINARY_NAME"
echo " ✓ Binario instalado en $HOME/bin/$BINARY_NAME"
else
echo " ✗ No se encontró $APP_NAME ni $BINARY_NAME"
exit 1
fi
# --- Add hostname to /etc/hosts ---
echo ""
echo "[3/6] Configurando hostname..."
if grep -q "$HOSTNAME" /etc/hosts 2>/dev/null; then
echo " ✓ $HOSTNAME ya está en /etc/hosts"
else
echo " Agregando $HOSTNAME a /etc/hosts (requiere sudo)..."
echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts > /dev/null
echo " ✓ $HOSTNAME agregado"
fi
# --- Generate certs ---
echo ""
echo "[4/6] Generando certificados SSL..."
mkdir -p "$CERT_DIR"
"$BINARY_PATH" --headless &
BRIDGE_PID=$!
sleep 3
kill $BRIDGE_PID 2>/dev/null || true
wait $BRIDGE_PID 2>/dev/null || true
# --- Trust CA certificate ---
CA_CERT="$CERT_DIR/ca.pem"
if [ -f "$CA_CERT" ]; then
echo " Instalando certificado CA (requiere sudo)..."
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$CA_CERT" 2>/dev/null \
&& echo " ✓ Certificado CA instalado" \
|| echo " ⚠ No se pudo instalar — HTTPS puede mostrar advertencias"
else
echo " ⚠ Certificado CA no encontrado — HTTPS puede mostrar advertencias"
fi
# --- Install LaunchAgent ---
echo ""
echo "[5/6] Configurando inicio automático..."
mkdir -p "$LAUNCH_AGENTS"
cat > "$LAUNCH_AGENTS/$PLIST_NAME" << PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.tsc-bridge</string>
<key>ProgramArguments</key>
<array>
<string>${BINARY_PATH}</string>
<string>--headless</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/tsc-bridge.log</string>
<key>StandardErrorPath</key>
<string>/tmp/tsc-bridge.err</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/opt/homebrew/bin</string>
</dict>
</dict>
</plist>
PLIST
echo " ✓ LaunchAgent creado"
launchctl load "$LAUNCH_AGENTS/$PLIST_NAME"
echo " ✓ LaunchAgent cargado"
# --- Start service ---
echo ""
echo "[6/6] Iniciando servicio..."
launchctl start com.tsc-bridge 2>/dev/null || true
sleep 2
# Verify
if curl -s http://127.0.0.1:9638/status >/dev/null 2>&1 || curl -s http://127.0.0.1:9271/status >/dev/null 2>&1; then
echo " ✓ TSC Bridge está corriendo"
else
echo " ⚠ Servicio iniciado pero no responde aún — puede tardar unos segundos"
fi
echo ""
echo "╔══════════════════════════════════════════════╗"
echo "║ ✓ Instalación Completa ║"
echo "╠══════════════════════════════════════════════╣"
echo "║ App: $INSTALL_DIR/$APP_NAME"
echo "║ Servicio: Auto-start al login (LaunchAgent)"
echo "║ Tray icon: Aparece en la barra de menú ║"
echo "║ Dashboard: Clic en icono → Abrir Dashboard ║"
echo "║ HTTPS: https://$HOSTNAME:9272/ ║"
echo "╚══════════════════════════════════════════════╝"
echo ""
echo "Para desinstalar:"
echo " launchctl unload ~/Library/LaunchAgents/$PLIST_NAME"
echo " rm ~/Library/LaunchAgents/$PLIST_NAME"
echo " rm -rf '/Applications/$APP_NAME'"
echo " sudo sed -i '' '/$HOSTNAME/d' /etc/hosts"
echo " sudo security delete-certificate -c 'TSC Bridge Local CA' /Library/Keychains/System.keychain"
echo ""