summarylogtreecommitdiffstats
path: root/deadsync-git.install
blob: d2667461a720787906d4097f6779925755187a43 (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
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
_XDG_MIGRATION_VER="0.3.826"

_migrate_data_dir() {
    local _old_dir="${HOME}/.deadsync"
    local _new_dir="${XDG_DATA_HOME:-${HOME}/.local/share}/deadsync"

    if [[ -d "${_old_dir}" && ! -d "${_new_dir}" ]]; then
        echo ">>> Migrating data directory to XDG path:"
        echo ">>>   ${_old_dir} -> ${_new_dir}"
        mkdir -p "$(dirname "${_new_dir}")"
        mv "${_old_dir}" "${_new_dir}"
    elif [[ -d "${_old_dir}" && -d "${_new_dir}" ]]; then
        echo ">>> WARNING: Both old and new data directories exist."
        echo ">>>   Old: ${_old_dir}"
        echo ">>>   New: ${_new_dir}"
        echo ">>> Automatic migration skipped to prevent data loss."
        echo ">>> Please manually merge your data into the new path."
    fi
}

_disable_updater() {
    local _ini="${XDG_DATA_HOME:-${HOME}/.local/share}/deadsync/deadsync.ini"
    mkdir -p "${XDG_DATA_HOME:-${HOME}/.local/share}/deadsync"

    if [[ ! -f "${_ini}" ]]; then
        printf '[Updater]\nupdater_install_enabled = false\n' > "${_ini}"
        return
    fi

    if grep -q '^updater_install_enabled' "${_ini}" 2>/dev/null; then
        sed -i 's/^updater_install_enabled\s*=.*/updater_install_enabled = false/' "${_ini}"
    else
        printf '\n[Updater]\nupdater_install_enabled = false\n' >> "${_ini}"
    fi
}

post_install() {
    local _commit
    _commit=$(git -C /opt/deadsync rev-parse --short HEAD 2>/dev/null || true)

    echo
    echo " ╔═══════════════════════════════════════════════╗"
    echo " ║           DeadSync (git) installed            ║"
    echo " ╚═══════════════════════════════════════════════╝"
    echo
    echo "  Installed to  : /opt/deadsync"
    echo "  User data     : \$XDG_DATA_HOME (default: ~/.local/share/deadsync)"
    echo "  Songs         : \$XDG_DATA_HOME/songs (default: ~/.local/share/deadsync/songs)"
    echo
    echo "  Launch from your application menu or run:"
    echo "    \$ deadsync"
    echo
    _disable_updater
    echo "  Note: in-app updates have been disabled in \$XDG_DATA_HOME/deadsync.ini"
    echo "  Updates are managed by pacman / your AUR helper."
    echo
    echo "  Commit history:"
    echo "    https://github.com/pnn64/deadsync/commits/main/"
    [[ -n "${_commit}" ]] && \
    echo "    https://github.com/pnn64/deadsync/commit/${_commit}"
    echo
}

post_upgrade() {
    local _old_ver="$2"
    local _commit
    _commit=$(git -C /opt/deadsync rev-parse --short HEAD 2>/dev/null || true)

    echo
    echo " ╔═══════════════════════════════════════════════╗"
    echo " ║           DeadSync (git) upgraded             ║"
    echo " ╚═══════════════════════════════════════════════╝"
    echo
    echo "  Installed to  : /opt/deadsync"
    echo "  User data     : \$XDG_DATA_HOME (default: ~/.local/share/deadsync)"
    echo

    # XDG migration — the -git pkgver is a rolling r<count>.g<hash> string
    # so vercmp against a release version tag is not reliable. Check for the
    # old directory's existence instead, which is unambiguous.
    if [[ -d "${HOME}/.deadsync" ]]; then
        _migrate_data_dir
        echo
    fi

    # Updater flag — check for the key being absent rather than a version
    # comparison, for the same reason as above.
    local _ini="${XDG_DATA_HOME:-${HOME}/.local/share}/deadsync/deadsync.ini"
    if [[ ! -f "${_ini}" ]] || ! grep -q '^updater_install_enabled' "${_ini}" 2>/dev/null; then
        _disable_updater
        echo "  Note: in-app updates have been disabled in \$XDG_DATA_HOME/deadsync.ini"
        echo "  Updates are managed by pacman / your AUR helper."
        echo
    fi

    echo "  Commit history:"
    echo "    https://github.com/pnn64/deadsync/commits/main/"
    [[ -n "${_commit}" ]] && \
    echo "    https://github.com/pnn64/deadsync/commit/${_commit}"
    echo
}