使用mc-tool实现empathy的自动登录与处理密钥环问题

项目中使用empathy来实现一个远程协助的功能,需要自动帮客户端登录empathy,为了处理这个问题,找到了mc-tool来设置帐号。

例如添加帐号:

mc-tool add gabble/jabber 10.1.82.165@10.1.122.173 string:account=10.1.82.165@10.1.122.173 string:password=qwer1234 bool:require-encryption=true bool:ignore-ssl-errors=true

查看帐号:

mc-tool list

使用mc-tool remove可以删除。
因此做了个脚本,实现系统启动时候,自动添加好empathy的帐号。但首次执行会报 选择新密钥环的密码
设置新密钥环密码
若点击ESC取消,则设置仍会出这个。若点击取消按钮或确定,倒是可以。
一开始以为.local/share/keyring/下设置Default密钥环,后来试了发现是还是不行。
最后才找到应该在路径.config/mate/keyring/下设置,即OK了

附带脚本如下:

#!/bin/sh

# Jabber服务器地址(ip地址或域名)
server=10.1.122.173

# 账户ID(为方便处理,id名称请使用字母和数字,不要包含任何其它字符和符号)
id=10.1.82.165

jid=${id}@${server}

# 账户密码
jid_pw=10.1.82.165

cat >/usr/local/bin/do_jid_action.sh <<FOE
#!/bin/sh

keyring_init() {
	# 预置一个不加密的缺省keyring,从而避免用户交互
	[ ! -d ~/.config/mate/keyrings ] && mkdir -p ~/.config/mate/keyrings && chmod 700 ~/.config/mate/keyrings
	cat > ~/.config/mate/keyrings/Default_keyring.keyring << EOF
[keyring]
display-name=Default keyring
ctime=\$(date +%s)
mtime=0
lock-on-idle=false
lock-after=false

EOF

	echo "Default_keyring" > ~/.config/mate/keyrings/default
	chmod 600 ~/.config/mate/keyrings/Default_keyring.keyring
	chmod 600 ~/.config/mate/keyrings/default
}

jid_add() {
	# 检查要创建的账户是否已经存在,如存在则删除
	account_id=$(echo ${jid}|sed 's/\./_2e/g'|sed 's/\@/_40/g')
	for i in \$(mc-tool list |grep \${account_id});
	do
	    mc-tool remove \$i
	done

	# 创建账户
	account=\$(mc-tool add gabble/jabber ${jid} string:account=${jid} string:password=${jid_pw} bool:require-encryption=true bool:ignore-ssl-errors=true)
	echo account=${account}

	# set Icon=im-jabber
	mc-tool icon \${account} im-jabber

	# set Enabled=true
	mc-tool enable \${account}

}

if [ ! -f ~/.jid_init_done ];
then
	[ -s ~/.config/mate/keyrings/default ] || keyring_init
	jid_add
	[ "$?" -eq 0 ] && touch ~/.jid_init_done
fi
FOE

chmod a+x /usr/local/bin/do_jid_action.sh

# 增加自启动服务,用户登录时建立账户
#grep "/usr/local/bin/do_jid_action.sh" /etc/bashrc
#[ "$?" -ne 0 ] && echo "/usr/local/bin/do_jid_action.sh" >> /etc/bashrc
if [ ! -f /etc/xdg/autostart/xdg-jid-init.desktop ];
then
	cat > /etc/xdg/autostart/xdg-jid-init.desktop << EOF
[Desktop Entry]
Type=Application
Name=JID INIT
Exec=/usr/local/bin/do_jid_action.sh
OnlyShowIn=GNOME;MATE;

EOF

fi

参考:
empathy
https://wiki.gnome.org/action/show/Apps/Empathy?action=show&redirect=Empathy
mc-tool
http://telepathy.freedesktop.org/wiki/Mission_Control/
Telepathy Developer’s Manual
http://telepathy.freedesktop.org/doc/book/index.html
Components
http://telepathy.freedesktop.org/wiki/Components/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

day walker

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值