Исправление работы с правами каталогов + скрипт установки
This commit is contained in:
34
main.go
34
main.go
@@ -142,6 +142,20 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// Создаем директорию для базы данных, если её нет
|
||||
dbDir := filepath.Dir(*dbPath)
|
||||
if _, err := os.Stat(dbDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(dbDir, 0o755)
|
||||
if err != nil {
|
||||
log.Fatal("Error creating database directory").
|
||||
Err(err).
|
||||
Str("path", dbDir).
|
||||
Str("hint", "Run as root or create directory manually: sudo mkdir -p "+dbDir+" && sudo chown alr-updater:alr-updater "+dbDir).
|
||||
Send()
|
||||
}
|
||||
log.Info("Created database directory").Str("path", dbDir).Send()
|
||||
}
|
||||
|
||||
db, err := bbolt.Open(*dbPath, 0o644, nil)
|
||||
if err != nil {
|
||||
log.Fatal("Error opening database").Err(err).Send()
|
||||
@@ -155,8 +169,13 @@ func main() {
|
||||
if _, err := os.Stat(cfg.ReposBaseDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(cfg.ReposBaseDir, 0o755)
|
||||
if err != nil {
|
||||
log.Fatal("Error creating repositories base directory").Err(err).Send()
|
||||
log.Fatal("Error creating repositories base directory").
|
||||
Err(err).
|
||||
Str("path", cfg.ReposBaseDir).
|
||||
Str("hint", "Run as root or create directory manually: sudo mkdir -p "+cfg.ReposBaseDir+" && sudo chown alr-updater:alr-updater "+cfg.ReposBaseDir).
|
||||
Send()
|
||||
}
|
||||
log.Info("Created repositories base directory").Str("path", cfg.ReposBaseDir).Send()
|
||||
} else if err != nil {
|
||||
log.Fatal("Cannot stat configured repos base directory").Err(err).Send()
|
||||
}
|
||||
@@ -194,6 +213,19 @@ func main() {
|
||||
log.Fatal("No repositories configured. At least one repository is required.").Send()
|
||||
}
|
||||
|
||||
// Создаем директорию для плагинов, если её нет
|
||||
if _, err := os.Stat(*pluginDir); os.IsNotExist(err) {
|
||||
err = os.MkdirAll(*pluginDir, 0o755)
|
||||
if err != nil {
|
||||
log.Fatal("Error creating plugin directory").
|
||||
Err(err).
|
||||
Str("path", *pluginDir).
|
||||
Str("hint", "Run as root or create directory manually: sudo mkdir -p "+*pluginDir+" && sudo chown root:alr-updater "+*pluginDir).
|
||||
Send()
|
||||
}
|
||||
log.Info("Created plugin directory").Str("path", *pluginDir).Send()
|
||||
}
|
||||
|
||||
starFiles, err := filepath.Glob(filepath.Join(*pluginDir, "*.star"))
|
||||
if err != nil {
|
||||
log.Fatal("Error finding plugin files").Err(err).Send()
|
||||
|
123
scripts/install.sh
Normal file
123
scripts/install.sh
Normal file
@@ -0,0 +1,123 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Цвета для вывода
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}ALR Updater Installation Script${NC}"
|
||||
echo "==============================="
|
||||
|
||||
# Проверка прав root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo -e "${RED}This script must be run as root${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Переменные
|
||||
BINARY_PATH="/usr/local/bin/alr-updater"
|
||||
SERVICE_NAME="alr-updater"
|
||||
SERVICE_USER="alr-updater"
|
||||
SERVICE_GROUP="alr-updater"
|
||||
CONFIG_DIR="/etc/alr-updater"
|
||||
DATA_DIR="/var/lib/alr-updater"
|
||||
CACHE_DIR="/var/cache/alr-updater"
|
||||
PLUGIN_DIR="${CONFIG_DIR}/plugins"
|
||||
|
||||
# Создание пользователя и группы
|
||||
echo -e "${YELLOW}Creating user and group...${NC}"
|
||||
if ! id -u ${SERVICE_USER} >/dev/null 2>&1; then
|
||||
useradd -r -s /bin/false -d /var/lib/${SERVICE_USER} ${SERVICE_USER}
|
||||
echo -e "${GREEN}User ${SERVICE_USER} created${NC}"
|
||||
else
|
||||
echo -e "${GREEN}User ${SERVICE_USER} already exists${NC}"
|
||||
fi
|
||||
|
||||
# Создание директорий
|
||||
echo -e "${YELLOW}Creating directories...${NC}"
|
||||
mkdir -p ${CONFIG_DIR}
|
||||
mkdir -p ${DATA_DIR}
|
||||
mkdir -p ${CACHE_DIR}
|
||||
mkdir -p ${PLUGIN_DIR}
|
||||
|
||||
# Установка прав доступа
|
||||
echo -e "${YELLOW}Setting permissions...${NC}"
|
||||
chown -R ${SERVICE_USER}:${SERVICE_GROUP} ${DATA_DIR}
|
||||
chown -R ${SERVICE_USER}:${SERVICE_GROUP} ${CACHE_DIR}
|
||||
chown -R root:${SERVICE_GROUP} ${CONFIG_DIR}
|
||||
chmod 755 ${CONFIG_DIR}
|
||||
chmod 755 ${PLUGIN_DIR}
|
||||
chmod 755 ${DATA_DIR}
|
||||
chmod 755 ${CACHE_DIR}
|
||||
|
||||
# Копирование бинарника
|
||||
if [ -f "./alr-updater" ]; then
|
||||
echo -e "${YELLOW}Installing binary...${NC}"
|
||||
cp ./alr-updater ${BINARY_PATH}
|
||||
chmod 755 ${BINARY_PATH}
|
||||
echo -e "${GREEN}Binary installed to ${BINARY_PATH}${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Binary not found in current directory, skipping binary installation${NC}"
|
||||
fi
|
||||
|
||||
# Создание примера конфигурации, если не существует
|
||||
if [ ! -f "${CONFIG_DIR}/config.toml" ]; then
|
||||
if [ -f "./alr-updater.example.toml" ]; then
|
||||
echo -e "${YELLOW}Creating example configuration...${NC}"
|
||||
cp ./alr-updater.example.toml ${CONFIG_DIR}/config.toml
|
||||
chown root:${SERVICE_GROUP} ${CONFIG_DIR}/config.toml
|
||||
chmod 640 ${CONFIG_DIR}/config.toml
|
||||
echo -e "${GREEN}Configuration created at ${CONFIG_DIR}/config.toml${NC}"
|
||||
echo -e "${YELLOW}Please edit the configuration file before starting the service${NC}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Создание systemd service файла
|
||||
echo -e "${YELLOW}Creating systemd service...${NC}"
|
||||
cat > /etc/systemd/system/${SERVICE_NAME}.service << EOF
|
||||
[Unit]
|
||||
Description=ALR Updater Service
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=${SERVICE_USER}
|
||||
Group=${SERVICE_GROUP}
|
||||
ExecStart=${BINARY_PATH}
|
||||
Restart=on-failure
|
||||
RestartSec=30
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
SyslogIdentifier=${SERVICE_NAME}
|
||||
|
||||
# Безопасность
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=${DATA_DIR} ${CACHE_DIR}
|
||||
ReadOnlyPaths=${CONFIG_DIR}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Перезагрузка systemd
|
||||
echo -e "${YELLOW}Reloading systemd...${NC}"
|
||||
systemctl daemon-reload
|
||||
|
||||
# Включение сервиса
|
||||
echo -e "${YELLOW}Enabling service...${NC}"
|
||||
systemctl enable ${SERVICE_NAME}.service
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}Installation completed!${NC}"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo "1. Edit configuration: nano ${CONFIG_DIR}/config.toml"
|
||||
echo "2. Add plugins to: ${PLUGIN_DIR}/"
|
||||
echo "3. Start service: systemctl start ${SERVICE_NAME}"
|
||||
echo "4. Check status: systemctl status ${SERVICE_NAME}"
|
||||
echo "5. View logs: journalctl -u ${SERVICE_NAME} -f"
|
Reference in New Issue
Block a user