1 |
ssuominen 10/09/30 13:48:58 |
2 |
|
3 |
Added: eselect-pinentry-0.1 |
4 |
Log: |
5 |
Initial commit. |
6 |
|
7 |
(Portage version: 2.2_rc88/cvs/Linux x86_64) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 app-admin/eselect-pinentry/files/eselect-pinentry-0.1 |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-admin/eselect-pinentry/files/eselect-pinentry-0.1?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-admin/eselect-pinentry/files/eselect-pinentry-0.1?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: eselect-pinentry-0.1 |
16 |
=================================================================== |
17 |
# Copyright 1999-2010 Gentoo Foundation |
18 |
# Distributed under the terms of the GNU General Public License v2 |
19 |
# $Id: eselect-pinentry-0.1,v 1.1 2010/09/30 13:48:58 ssuominen Exp $ |
20 |
|
21 |
# Based on select-sh by Michał Górny |
22 |
|
23 |
DESCRIPTION="Manage /usr/bin/pinentry symlink" |
24 |
MAINTAINER="ssuominen@g.o" |
25 |
VERSION="0.1" |
26 |
|
27 |
## Functions ## |
28 |
|
29 |
# find a list of pinentry symlink targets, best first |
30 |
find_targets() { |
31 |
local t |
32 |
for t in \ |
33 |
pinentry-qt \ |
34 |
pinentry-gtk-2 \ |
35 |
pinentry-qt4 \ |
36 |
pinentry-curses \ |
37 |
; do |
38 |
if [[ -x ${ROOT}/usr/bin/${t} ]]; then |
39 |
echo ${t} |
40 |
fi |
41 |
done |
42 |
} |
43 |
|
44 |
# set the pinentry symlink |
45 |
set_symlinks() { |
46 |
local target="${1}" targets |
47 |
|
48 |
[[ ! -L ${ROOT}/usr/bin/pinentry && -e ${ROOT}/usr/bin/pinentry ]] && \ |
49 |
die -q "/usr/bin/pinentry is not a symlink!" |
50 |
|
51 |
if is_number "${target}" && [[ ${target} -ge 1 ]]; then |
52 |
targets=( $(find_targets) ) |
53 |
target=${targets[target-1]} |
54 |
fi |
55 |
|
56 |
if [[ -x ${ROOT}/usr/bin/${target} ]]; then |
57 |
local tmpf="${ROOT}"/usr/bin/pinentry.new |
58 |
# we could use 'ln -f' to directly replace the symlink |
59 |
# but 'mv' is an atomic operation so it should be more fault-proof |
60 |
|
61 |
ln -s "${target}" "${tmpf}" || \ |
62 |
die -q "Unable to create temporary symlink" |
63 |
if ! mv "${tmpf}" "${ROOT}"/usr/bin/pinentry; then |
64 |
rm -f "${tmpf}" # cleanup |
65 |
die -q "Unable to replace /usr/bin/pinentry symlink with ${target}" |
66 |
fi |
67 |
else |
68 |
die -q "Target '${target}' doesn't appear to be valid!" |
69 |
fi |
70 |
} |
71 |
|
72 |
### show action ### |
73 |
|
74 |
describe_show() { |
75 |
echo "Show the current pinentry implementation" |
76 |
} |
77 |
|
78 |
do_show() { |
79 |
[[ -z ${@} ]] || die -q "Too many parameters" |
80 |
|
81 |
write_list_start "Current pinentry implementation:" |
82 |
if [[ -L ${ROOT}/usr/bin/pinentry ]]; then |
83 |
write_kv_list_entry "$(basename $(readlink ${ROOT}/usr/bin/pinentry))" "" |
84 |
elif [[ -e ${ROOT}/usr/bin/pinentry ]]; then |
85 |
write_kv_list_entry "(not a symlink)" "" |
86 |
else |
87 |
write_kv_list_entry "(unset)" "" |
88 |
fi |
89 |
} |
90 |
|
91 |
### list action ### |
92 |
|
93 |
describe_list() { |
94 |
echo "List available pinentry implementations" |
95 |
} |
96 |
|
97 |
do_list() { |
98 |
[[ -z ${@} ]] || die -q "Too many parameters" |
99 |
|
100 |
local i targets |
101 |
targets=( $(find_targets) ) |
102 |
if [[ -n ${targets[@]} ]]; then |
103 |
for (( i = 0; i < ${#targets[@]}; i++ )) ; do |
104 |
[[ ${targets[${i}]} == $(basename $(readlink ${ROOT}/usr/bin/pinentry)) ]] && \ |
105 |
targets[${i}]="${targets[${i}]} $(highlight '*')" |
106 |
done |
107 |
write_list_start "Available pinentry implementations:" |
108 |
write_numbered_list "${targets[@]}" |
109 |
else |
110 |
write_kv_list_entry "(none found)" "" |
111 |
fi |
112 |
} |
113 |
|
114 |
### set action ### |
115 |
|
116 |
describe_set() { |
117 |
echo "Set a new pinentry implementation" |
118 |
} |
119 |
|
120 |
describe_set_options() { |
121 |
echo "target : Target name or number (from 'list' action)" |
122 |
} |
123 |
|
124 |
describe_set_parameters() { |
125 |
echo "<target>" |
126 |
} |
127 |
|
128 |
do_set() { |
129 |
if [[ -z ${1} ]]; then |
130 |
die -q "Not enough parameters" |
131 |
elif [[ -n ${2} ]]; then |
132 |
die -q "Too many parameters" |
133 |
else |
134 |
set_symlinks "${1}" |
135 |
fi |
136 |
} |
137 |
|
138 |
### update action ### |
139 |
|
140 |
describe_update() { |
141 |
echo "Automatically update the pinentry implementation" |
142 |
} |
143 |
|
144 |
describe_update_options() { |
145 |
echo "ifunset : Do not override existing implementation" |
146 |
} |
147 |
|
148 |
do_update() { |
149 |
[[ -z ${1} || ( -z ${2} && ( ${1} == ifunset || ${1} == '--if-unset' ) ) ]] || \ |
150 |
die -q "Usage error" |
151 |
|
152 |
[[ ( ${1} == ifunset || ${1} == '--if-unset' ) && -L ${ROOT}/usr/bin/pinentry && -x ${ROOT}/usr/bin/pinentry ]] && \ |
153 |
return |
154 |
|
155 |
set_symlinks 1 |
156 |
} |