#!/bin/bash
#将来可能可以换成apt-metalink来直接用种子/链接下载

apt-fast(){
/opt/durapps/spark-store/bin/apt-fast/ss-apt-fast "$@"
}

echo "Spark Store Install script.星火商店安装脚本"

#################检测文件是否存在
if [ $# -eq 0 ];then
echo "没有接收到参数，退出"
echo "用法：$0 deb路径"
exit
fi

if [ ! -f "$1" ]
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 ----------------------------------------------------------------------------------
echo "$upass" | sudo -S dpkg -i $1 || sudo aptss install -yf 


else
###########################有root权限时

echo  ----------------------------------------------------------------------------------
dpkg -i $1 || aptss install -yf 



fi
