安全的免密码安装

This commit is contained in:
2022-12-12 15:11:48 +08:00
parent 382b2de5ca
commit 79d12f2409
4 changed files with 46 additions and 61 deletions

View File

@@ -1,12 +1,20 @@
#!/bin/bash
#将来可能可以换成apt-metalink来直接用种子/链接下载
apt-fast(){
/opt/durapps/spark-store/bin/apt-fast/ss-apt-fast "$@"
}
echo "Spark Store Install script.星火商店安装脚本"
function pkexec_as_current_user() {
#Detect the name of the display in use
local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
#Detect the user using such display
local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1)
#Detect the id of the user
local uid=$(id -u $user)
sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus pkexec "$@"
}
#################检测文件是否存在
if [ $# -eq 0 ];then
echo "没有接收到参数,退出"
@@ -19,39 +27,38 @@ then
echo "文件不存在"
exit 1
fi
#################root校验+要密码
if [ "$(id -u)" != "0" ]
then
echo "ssinstall需要在root下运行";
uname=`whoami`
echo "Now input the password of $uname"
read -e upass
################检查密码对不对
echo "$upass" | sudo -S echo "i love amber forever"
passcheck=`echo "$upass" | sudo -S echo "i love amber forever"`
if [ "$passcheck" != "i love amber forever" ];then
echo "-----------------------------------------------------"
echo "E:密码错误,退出脚本!"
exit 1
fi
fi
##############判断是否是root运行如果是则正常走如果不是则代输密码
if [ "$(id -u)" != "0" ];then
#############################无root权限时
----------------------------------------------------------------------------------
echo "$upass" | sudo -S dpkg -i $1 || sudo aptss install -yf
echo "请使用root启动ssinstall"
exit 1
fi
###
if [ ! -e "/var/lib/apt/lists/d.store.deepinos.org.cn_Packages" ];then
echo "接收星火仓库软件信息中..."
aptss ssupdate
fi
echo "正在计算hash并与星火仓库匹配..."
DEB_MD5SUM=`md5sum "$1" | cut -c -32`
IS_MD5SUM_CHECKD=`cat /var/lib/apt/lists/d.store.deepinos.org.cn_Packages | grep $DEB_MD5SUM`
if [ ! -z "$IS_MD5SUM_CHECKD" ];then
echo "校验成功,开始安装"
echo ----------------------------------------------------------------------------------
dpkg -i "$1" || aptss install -yf
else
###########################有root权限时
echo ----------------------------------------------------------------------------------
dpkg -i $1 || aptss install -yf
echo "校验失败该deb不是星火已经上架的软件包这可能是因为你正在尝试安装一个尚未上架的软件包"
echo "如果你是审核人员,这是正常的"
echo "为确保安全,将会询问密码"
pkexec_as_current_user bash -c "dpkg -i "$1" || aptss install -yf "
fi