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

if [[ -z "${ib_login}" ]]
then
    if [[ -f "${login_file}" ]]
    then
        ib_login="$(< "${login_file}")"
    else
        output_text="You must specify ${ib_login_word} and ${ib_key_word}"
        return 0
    fi
fi

if [[ -z "${ib_key}" ]]
then
    if [[ -f "${key_file}" ]]
    then
        ib_key="$(< "${key_file}")"
    else
        output_text="You must specify ${ib_key_word}"
        return 0
    fi
fi

if ! mkdir -p "${auth_dir}"
then
    output_text="Failed to create user config"
    return 0
fi

case "${ib_board}" in
    (a|d)
        source "${auth}/donmai.zsh"
    ;;
    (g)
        source "${auth}/gelbooru.zsh"
    ;;
    (i|s)
        source "${auth}/sankakucomplex.zsh"
    ;;
    (k|y)
        source "${auth}/moebooru.zsh"
    ;;
esac

if [[ -z "${output_text}" ]]
then
    printf "%s\n" "${ib_login}" > "${login_file}"
    printf "%s\n" "${ib_key}" > "${key_file}"
fi

auth_data=($(ls -1 "${auth_dir}"))

if [[ ${#auth_data} -eq 0 ]]
then
    rmdir "${auth_dir}"
fi