aboutsummaryrefslogtreecommitdiff
path: root/units/ib_token.zsh
blob: 00d8ce27dc2fd3651f37f78eb86cd31669d7e68b (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
# Copyright (C) 2024-2026 Maria Lisina
# Copyright (C) 2024-2026 Danil Lisin
# SPDX-License-Identifier: Apache-2.0

if [[ -n "${ib_raw}" ]]
then
    ib_dfield1="${ib_login_file}=$(< "${login_file}")"
    ib_dfield2="${ib_key_file}=$(< "${key_file}")"
fi

if [[ -f "${timestamp_file}" ]]
then
    ib_ctime=$(strftime %s)
    ib_mtime=$(< "${timestamp_file}")

    if [[ $((ib_ctime - ib_mtime)) -gt ${ib_expire} ]]
    then
        if [[ -n "${ib_lock}" ]]
        then
            source "${units}/ib_lock.zsh" &

            output_title="Refreshing ${ib_name} session..."
            output_text="Try again in a few seconds"
            notification_text="${output_title} ${output_text}"
        else
            source "${units}/ib_auth.zsh"
        fi
    fi
fi

if [[ -f "${token_file}" ]]
then
    ib_headers="${ib_header} $(< "${token_file}")"
fi