-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
154 lines (135 loc) · 4.2 KB
/
Copy pathinstall.sh
File metadata and controls
154 lines (135 loc) · 4.2 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
151
152
153
154
#!/bin/bash
set -e # Abortar ante errores
APP_NAME="bitacora"
USER_HOME="$HOME"
APP_DIR="$USER_HOME/src/$APP_NAME"
DATA_DIR="$USER_HOME/.bitacora"
VENV_DIR="$APP_DIR/venv"
SERVICE_NAME="${APP_NAME}.service"
SYSTEMD_PATH="/etc/systemd/system/$SERVICE_NAME"
# Colores para salida amigable
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log() {
echo -e "${BLUE}[INFO]${NC} $1"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
success() {
echo -e "${GREEN}[OK]${NC} $1"
}
# === Comprobaciones iniciales ===
if [[ $EUID -eq 0 ]]; then
echo "❌ No ejecutes este script como root. Se instalará en tu usuario actual."
exit 1
fi
log "Instalando $APP_NAME en $APP_DIR..."
# === 1. Dependencias del sistema ===
log "Instalando dependencias del sistema..."
sudo apt update
sudo apt install -y python3 python3-pip python3-venv avahi-daemon libjpeg-dev zlib1g-dev
# === 2. Obtener código (clonar o usar si ya está) ===
if [ -d "$APP_DIR" ]; then
if [ -d "$APP_DIR/.git" ]; then
log "Actualizando repositorio existente con git pull..."
cd "$APP_DIR" || exit 1
git pull
else
log "Carpeta existente sin repositorio Git. Continuando sin actualizar."
cd "$APP_DIR" || exit 1
fi
else
log "Clonando repositorio desde GitHub..."
mkdir -p "$USER_HOME/src"
git clone "https://github.com/Enand-lab/bitacora.git" "$APP_DIR"
cd "$APP_DIR" || exit 1
fi
# === 3. Preguntar por el puerto ===
DEFAULT_PORT=5000
read -p "¿En qué puerto quieres que escuche Cuaderno de Bitácora? (por defecto: $DEFAULT_PORT): " USER_PORT
PORT=${USER_PORT:-$DEFAULT_PORT}
# Validar que sea un número y esté en rango válido
if ! [[ "$PORT" =~ ^[0-9]+$ ]] || [ "$PORT" -lt 1 ] || [ "$PORT" -gt 65535 ]; then
warn "Puerto inválido. Usando puerto por defecto: $DEFAULT_PORT"
PORT=$DEFAULT_PORT
fi
success "Cuaderno de Bitácora usará el puerto: $PORT"
# === 4. Entorno virtual y dependencias Python ===
log "Configurando entorno virtual..."
python3 -m venv "$VENV_DIR"
"$VENV_DIR/bin/pip" install --upgrade pip
"$VENV_DIR/bin/pip" install -r requirements.txt
success "Dependencias Python instaladas."
# === 5. Directorio de datos y configuración inicial (¡siempre sobrescribe el puerto!) ===
log "Preparando directorio de datos en $DATA_DIR..."
mkdir -p "$DATA_DIR/uploads/deleted"
# Sobrescribe config.json con el puerto elegido (incluso si ya existe)
cat > "$DATA_DIR/config.json" <<EOF
{
"port": $PORT,
"language": "es",
"setup_completed": false,
"backup_enabled": false,
"backup_path": "",
"signalk": {
"enabled": false,
"url": "",
"token": "",
"sync_resources": true,
"sync_entry_types": ["log", "navigation", "weather"],
"selected_paths": ["navigation.position", "navigation.state"]
}
}
EOF
success "Configuración inicial creada en $DATA_DIR/config.json con puerto $PORT"
# === 6. Servicio systemd ===
log "Creando servicio systemd..."
sudo tee "$SYSTEMD_PATH" > /dev/null <<EOF
[Unit]
Description=Cuaderno de Bitácora
After=network.target
[Service]
Type=simple
User=$USER
WorkingDirectory=$APP_DIR
Environment=PATH=$VENV_DIR/bin
ExecStart=$VENV_DIR/bin/python app.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable "$SERVICE_NAME"
sudo systemctl start "$SERVICE_NAME"
success "Servicio $SERVICE_NAME activado e iniciado."
# === 7. Servicio Avahi para bitacora.local ===
AVAHI_SERVICE="/etc/avahi/services/bitacora.service"
sudo tee "$AVAHI_SERVICE" > /dev/null <<EOF
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name>Cuaderno de Bitácora</name>
<service>
<type>_http._tcp</type>
<port>$PORT</port>
<txt-record>path=/</txt-record>
</service>
</service-group>
EOF
sudo systemctl restart avahi-daemon
success "Nombre local 'bitacora.local' configurado."
# === 8. Instrucciones finales ===
IP=$(hostname -I | awk '{print $1}')
echo
success "🎉 ¡Instalación completada!"
echo
echo "👉 Accede a Cuaderno de Bitácora en:"
echo " http://bitacora.local:$PORT"
echo " http://$IP:$PORT"
echo
echo "🔧 Primera vez: ve a /setup para ajustar idioma, Signal K, backup, etc."
echo