-
Notifications
You must be signed in to change notification settings - Fork 4
/
tune_password.sh
executable file
·76 lines (59 loc) · 1.94 KB
/
tune_password.sh
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
#!/bin/bash
if [ ! -r ./tune.password ]; then
echo "Error: file 'tune.password' does not exists or missing permissions" >&2
exit 1
fi
if [ -z "$(cat ./tune.password)" ]; then
echo "Error: file 'tune.password' is empty" >&2
exit 1
fi
if [ ! -f "./skuf_src/init(untuned)" ]; then
echo "Error: file 'skuf_src/init(untuned)' does not exists" >&2
exit 1
fi
if [ ! -f "./skuf_src/kinit(untuned)" ]; then
echo "Error: file 'skuf_src/kinit(untuned)' does not exists" >&2
exit 1
fi
read -r data <./tune.password
iter="${data%% *}"
if [ -z "$iter" ]; then
echo "Missing iter!" >&2
exit 1
fi
case "$iter" in
''|*[!0-9]*)
echo "iter containts something other than number!" >&2
exit 1
;;
*)
:
;;
esac
password="${data#* }"
if [ -z "$password" ]; then
echo "Missing password!" >&2
exit 1
fi
if ! echo "'$password'" | sh -n; then
echo "Password quoted incorrectly!" >&2
exit 1
fi
: > ./.tune_password_pattern_enc
: > ./.tune_password_pattern_dec
[ -f ./skuf_src/init ] || cp -a "./skuf_src/init(untuned)" "./skuf_src/init"
[ -f ./skuf_src/kinit ] || cp -a "./skuf_src/kinit(untuned)" "./skuf_src/kinit"
cat <<EOF > ./.tune_password_pattern_enc
sambaoptsx="\$(echo -n "\$sambaoptsx" | openssl enc -e -aes-256-cbc -salt -iter $iter -base64 -A -k '$password' -in - -out -)" # SKUF_OPENSSL_ENC_RM #
EOF
cat <<EOF > ./.tune_password_pattern_dec
if _sambaopts="\$(echo -n "\$_sambaopts" | openssl enc -d -aes-256-cbc -salt -iter $iter -base64 -A -k '$password' -in - -out -)"; then # SKUF_OPENSSL_DEC_RM #
EOF
sed -i "/# SKUF_OPENSSL_ENC_RM #/d" ./skuf_src/kinit
sed -i "/# SKUF_OPENSSL_DEC_RM #/d" ./skuf_src/init
sed -i "/# SKUF_OPENSSL_ENC #/r .tune_password_pattern_enc" ./skuf_src/kinit
sed -i "/# SKUF_OPENSSL_DEC #/r .tune_password_pattern_dec" ./skuf_src/init
rm ./.tune_password_pattern_enc
rm ./.tune_password_pattern_dec
echo "Done."
# vim: set ft=sh ts=4 sw=4 et: