-
Notifications
You must be signed in to change notification settings - Fork 3
/
interactive-config
executable file
·112 lines (92 loc) · 2.36 KB
/
interactive-config
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
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
[[ "${TRACE}" ]] && set -x
set -eu
set -o pipefail
configure_git() {
local target=~/.gitconfig.private
[ -f "${target}" ] && return 0
local gpg_default_key
gpg_default_key=$(gpgconf --list-options gpg | awk -F: '/^default-key:/{ sub(/^"/, "", $10); print $10 }')
read -r -p "Name: " name
read -r -p "E-mail: " email
read -r -p "GPG-key [${gpg_default_key}]: " signingkey
signingkey=${signingkey:-"${gpg_default_key}"}
read -r -p "GitHub user: " gh_user
read -r -p "GitHub token: " gh_token
read -r -p "GHI token: " ghi_token
echo
echo "Writing file '${target}' with content:"
tee "${target}" <<EOM
[user]
name = ${name}
email = ${email}
signingkey = ${signingkey}
[github]
user = ${gh_user}
token = ${gh_token}
[ghi]
ghi = ${ghi_token}
EOM
}
configure_vdirsyncer_client() {
local target=~/.local/share/vdirsyncer/env
[ -f "${target}" ] && return 0
mkdir -p "${target%/*}"
read -r -p "Client ID: " client_id
read -r -p "Client Secret: " client_secret
echo
echo "Writing file '${target}' with content:"
tee "${target}" <<EOM
CLIENT_ID=${client_id}
CLIENT_SECRET=${client_secret}
EOM
}
configure_vdirsyncer() {
[ -d ~/.calendars ] && return 0
local env_file=~/.local/share/vdirsyncer/env
# shellcheck disable=SC2046
env $(xargs < "${env_file}") vdirsyncer discover
}
configure_khal() {
khal-link-calendar
}
configure_autorandr() {
local profile_path=~/.config/autorandr
local target="${profile_path}/default"
[ -L "${target}" ] && return 0
echo 'Available profiles:'
for file in "${profile_path}"/*
do
echo "${file##*/}"
done
read -r -p 'Default profile: ' profile
ln -s "${profile_path}/${profile}" "${target}"
}
configure_offlineimap_client() {
local target=~/.local/share/offlineimap/env
[ -f "${target}" ] && return 0
mkdir -p "${target%/*}"
read -r -p "Client ID: " client_id
read -r -p "Client Secret: " client_secret
echo
echo "Writing file '${target}' with content:"
tee "${target}" <<EOM
CLIENT_ID=${client_id}
CLIENT_SECRET=${client_secret}
EOM
}
main() {
echo '==> Create private git config:'
configure_git
echo '==> Configure vdirsyncer client'
configure_vdirsyncer_client
echo '==> Configure vdirsyncer'
configure_vdirsyncer
echo '==> Configure khal'
configure_khal
echo '==> Configure autorandr'
configure_autorandr
echo '==> Configure offlineimap client'
configure_offlineimap_client
}
main "$@"