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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
#! /bin/bash
# Nyckel (nyckel) is Copyright (C) 2026 Paolo Lulli, Kevwe Technology AB
#
# This file is part of nyckel.
#
# nyckel is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# nyckel is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
SECRETS_DIR=$HOME/.config/nyckel-secrets
CONFIG_DIR=$HOME/.config/nyckel
GLOBAL_CONFIG=${CONFIG_DIR}/config
DEPENDENCIES="keepassxc-cli"
test -d $CONFIG_DIR || mkdir -p $CONFIG_DIR
dependencies_check()
{
for d in $DEPENDENCIES; do
CHK=$(which $d)
if [ "$CHK" = "" ]; then
echo "missing deps: [$d]";
exit 1
fi
done
}
create_profile(){
echo "SETUP PROFILE"
profile_name=$1
test -d $CONFIG_DIR/$profile_name && echo "Profile [${profile_name}] exists, exiting."
test -d $CONFIG_DIR/$profile_name && exit 1
mkdir -p $SECRETS_DIR/$profile_name
mkdir -p $CONFIG_DIR/$profile_name
cat <<__EOL__ > $CONFIG_DIR/$profile_name/config
KEEPASS_KEY=""
KEEPASS_FILE="$SECRETS_DIR/$profile_name/key-$profile_name.keyx"
KEEPASS_DB="$CONFIG_DIR/$profile_name/$profile_name.kdbx"
INTERACTIVE=false
__EOL__
source "$CONFIG_DIR/$profile_name/config"
keepassxc-cli db-create --set-key-file ${KEEPASS_FILE} ${KEEPASS_DB}
}
list_secrets(){
profile=$1
source "$CONFIG_DIR/$profile/config"
echo "Secrets in profile: [${profile}]"
echo "--------"
keepassxc-cli ls --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB}
}
add_secret(){
profile=$1
entry=$2
source "$CONFIG_DIR/$profile/config"
#echo "Secret Name"
#read entry
echo "Username"
read entry_user
keepassxc-cli add --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB} -u ${entry_user} ${entry} --password-prompt
}
delete_secret(){
profile=$1
entry=$2
source "$CONFIG_DIR/$profile/config"
keepassxc-cli rm --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB} ${entry}
}
update_secret(){
profile=$1
entry=$2
source "$CONFIG_DIR/$profile/config"
echo "Username"
read entry_user
keepassxc-cli edit --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB} -u ${entry_user} ${entry} --password-prompt
}
add_random_secret(){
profile=$1
entry=$2
source "$CONFIG_DIR/$profile/config"
#echo "Secret Name"
#read entry
echo "Username"
read entry_user
keepassxc-cli add --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB} -u ${entry_user} --generate ${entry}
}
show_secret(){
profile=$1
entry=$2
source "$CONFIG_DIR/$profile/config"
keepassxc-cli show -s --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB} ${entry}
}
clip_secret(){
profile=$1
entry=$2
source "$CONFIG_DIR/$profile/config"
keepassxc-cli clip --key-file ${KEEPASS_FILE} --no-password ${KEEPASS_DB} ${entry}
}
list_profiles(){
echo "Profiles"
echo "--------"
for i in $(ls $CONFIG_DIR | sed -e s/config//); do echo ${i}; done
}
usage(){
program=$(basename $0)
echo " _ _ _ _ "
echo "| \ | |_ _ ___| | _____| |"
echo "| \| | | | |/ __| |/ / _ \ |"
echo "| |\ | |_| | (__| < __/ |"
echo "|_| \_|\__, |\___|_|\_\___|_|"
echo " |___/ "
echo " "
echo " (C) Paolo Lulli 2026 "
echo " "
echo "${program} -C <profile> : Create db <profile>"
echo "${program} -L : List profiles"
echo "${program} <profile> -l : List keys in db <profile>"
echo "${program} <profile> -W <secret> : Write <secret> into <profile> db"
echo "${program} <profile> -D <secret> : Delete <secret> from <profile> db"
echo "${program} <profile> -U <secret> : Update <secret> into <profile> db"
echo "${program} <profile> -G <secret> : Generate a random secret and write as <secret> into <profile> db"
echo "${program} <profile> -s <secret> : Show <secret> from <profile> db"
echo "${program} <profile> -c <secret> : Copy to clipboard <secret> from <profile> db"
}
dependencies_check
if [ "$#" -gt 3 ]; then
usage
exit
fi
if [ "$#" -eq 0 ]; then
usage
exit
fi
if [ "$#" -eq 1 ]; then
if [ "$1" == "-L" ]; then
list_profiles
exit
fi
usage
fi
if [ "$#" -eq 2 ]; then
profile=$1
if [ "$1" == "-C" ]; then
profile=$2
create_profile "${profile}"
exit
fi
if [ "$2" == "-l" ]; then
list_secrets "${profile}"
exit
fi
usage
fi
if [ "$#" -eq 3 ]; then
profile_name=$1
entryname=$3
if [ "$2" == "-W" ]; then
add_secret "${profile_name}" "${entryname}"
exit
fi
if [ "$2" == "-D" ]; then
delete_secret "${profile_name}" "${entryname}"
exit
fi
if [ "$2" == "-U" ]; then
update_secret "${profile_name}" "${entryname}"
exit
fi
if [ "$2" == "-G" ]; then
add_random_secret "${profile_name}" "${entryname}"
exit
fi
if [ "$2" == "-s" ]; then
show_secret "${profile_name}" "${entryname}"
exit
fi
if [ "$2" == "-c" ]; then
clip_secret "${profile_name}" "${entryname}"
exit
fi
usage
fi
|