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

until mkdir "${user_config}.lock"
do
    sleep 1
done

if [[ -n "${ib_raw}" ]]
then
    ib_dfield5="${ib_login_file}=$(< "${login_file}")"
    ib_dfield6="${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

rmdir "${user_config}.lock"