Executing system commands in N800 application

本文介绍了一种在不需要输入密码的情况下运行sudo命令的方法。通过修改deb安装包中的postinst文件,并加入特定命令,使得应用程序能够顺利执行sudo操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Basically, just use "os.system(str)". For example:

import os
cmd = 'ls'
os.system(cmd)

 

However, when we need to be root, e.g., running "sudo apt-get update", troubles come out, since a UI application started in N800 menu gives you no chance to input a password for background command "sudo" (in fact, we don't have the default password for maemo neither).

 

One way of gaining root permission in XTerminal is simply run "sudo gainroot" after install "becomeroot" package. But it does not work in UI application because an application and the command line it starts run in different processes. 

 

To solve the problem, we need to add a line to file "postinst.ex" in debian directry, and change its name into "postinst".

Line 4 is what we add. It makes the script "run-standalone.sh" which starts all applications run well without being asked any passwords even "sudo" executed.

 

case "$1" in
    configure)
        
        echo -e "\n"user ALL = NOPASSWD: /usr/bin/run-standalone.sh >> /etc/sudoers
 
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

 

Actually, whatever we want to be executed can be added into the file "postinst", and then it will run during installation. Problems that cannot be worked out by codes may be solved easily here, like modifying files as root, etc.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值