summarylogtreecommitdiffstats
path: root/ferron.install
blob: 4ec3efa29b740d53424dd0e3e76cd665658f05cd (plain)
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
pre_install() {
    if [ -f "/usr/bin/ferron" ] || [ -f "/usr/bin/ferron-updater" ]; then
        echo "ERROR: Ferron is already installed on this system."
        echo "Please uninstall the existing Ferron installation first."
        return 1
    fi
}

post_install() {
    echo "Creating ferron user and group..."
    systemd-sysusers
    echo "Setting up directories and permissions..."
    systemd-tmpfiles --create
    chown -R ferron:ferron /var/log/ferron
    chown -R ferron:ferron /var/www/ferron
    find /var/log/ferron -type d -exec chmod 755 {} \;
    find /var/log/ferron -type f -exec chmod 644 {} \;
    find /var/www/ferron -type d -exec chmod 755 {} \;
    find /var/www/ferron -type f -exec chmod 644 {} \;
    restoreconutil=$(whereis -b -B $(echo $PATH | sed 's|:| |g') -f restorecon | awk '{ print $2}' | xargs)
    if [ "$restoreconutil" != "" ]; then
        echo "Fixing SELinux context..."
        restorecon -r /usr/sbin/ferron{,-*} /usr/bin/ferron-updater /etc/ferron.yaml /var/www/ferron /var/log/ferron
    fi
    echo "Enabling ferron.service..."
    systemctl daemon-reload
    systemctl enable ferron.service
    echo "==> Ferron is now installed. Start it with: systemctl start ferron"
}

post_upgrade() {
    echo "Updating permissions..."
    chown -R ferron:ferron /var/log/ferron
    chown -R ferron:ferron /var/www/ferron
    find /var/log/ferron -type d -exec chmod 755 {} \;
    find /var/log/ferron -type f -exec chmod 644 {} \;
    find /var/www/ferron -type d -exec chmod 755 {} \;
    find /var/www/ferron -type f -exec chmod 644 {} \;
    if systemctl is-active --quiet ferron; then
        echo "Restarting ferron.service..."
        systemctl restart ferron
    fi
}

post_remove() {
    systemctl disable --now ferron.service
    echo "==> Ferron configuration and data directories are preserved."
    echo "==> Remove them manually if they are no longer needed:"
    echo "==> /etc/ferron.yaml"
    echo "==> /var/www/ferron"
    echo "==> /var/log/ferron"
}