summarylogtreecommitdiffstats
path: root/obsidian-bin.install
blob: 72f6f21f8274efcddf7e7e5d3c98692409ae26fd (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
#!/bin/bash

note() {
    printf "${blue}==>${yellow} NOTE:${bold} %s${all_off}\n" "${1}"
}

all_off="$(tput sgr0)"
bold="${all_off}$(tput bold)"
blue="${bold}$(tput setaf 4)"
yellow="${bold}$(tput setaf 3)"

post_install() {
    note "Custom flags should be put directly in: ~/.config/obsidian-flags.conf"

    # ln -sf '/opt/Obsidian/obsidian' '/usr/bin/obsidian'

    if ! { [[ -L /proc/self/ns/user ]] && unshare --user true; }; then
        chmod 4755 '/opt/Obsidian/chrome-sandbox' || true
    else
        chmod 0755 '/opt/Obsidian/chrome-sandbox' || true
    fi

    if hash update-mime-database 2>/dev/null; then
        update-mime-database /usr/share/mime || true
    fi

    if hash update-desktop-database 2>/dev/null; then
        update-desktop-database /usr/share/applications || true
    fi

    APPARMOR_PROFILE_SOURCE='/opt/Obsidian/resources/apparmor-profile'
    APPARMOR_PROFILE_TARGET='/etc/apparmor.d/obsidian'
    if [ -d "/etc/apparmor.d" ] && hash apparmor_parser 2>/dev/null; then
        if apparmor_parser --skip-kernel-load --debug "$APPARMOR_PROFILE_SOURCE" > /dev/null 2>&1; then
            cp -f "$APPARMOR_PROFILE_SOURCE" "$APPARMOR_PROFILE_TARGET"
            apparmor_parser --replace --write-cache --skip-read-cache "$APPARMOR_PROFILE_TARGET"
        else
            echo "Skipping the installation of the AppArmor profile as this version of AppArmor does not support the bundled profile"
        fi
    fi
}

post_remove() {
    # rm -f '/usr/bin/obsidian'

    APPARMOR_PROFILE_DEST='/etc/apparmor.d/obsidian'
    if [ -f "$APPARMOR_PROFILE_DEST" ]; then
        rm -f "$APPARMOR_PROFILE_DEST"
    fi
}