#/bin/bash




if  [ "$1" = "install" ] || [ "$1" = "upgrade" ] || [ "$1" = "full-upgrade" ] || [ "$1" = "download" ] ; then

###刷新apt-fast配置
mkdir -p /tmp/ss-apt-fast-conf/sources.list.d
# 创建文件夹
echo "从服务器获取配置和镜像列表..."
echo "Getting server and mirror lists..."
echo
curl --progress-bar -o /tmp/ss-apt-fast-conf/apt-fast.conf "https://gitee.com/deepin-community-store/repo_auto_update_script/raw/master/mirror-list-for-apt-fast/apt-fast.conf"
chmod -R 755 /tmp/ss-apt-fast-conf


DEPEND=`which  apt-fast`
if [ "$DEPEND" = "" ] ; then 
echo "未安装依赖：apt-fast 开始安装"
sudo ss-apt-fast ssupdate && sudo bwrap --dev-bind / / --bind '/opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list' /etc/apt/sources.list.d/sparkstore.list apt install apt-fast -y
fi
###执行安装
bwrap --dev-bind / / \
                   --bind '/tmp/ss-apt-fast-conf/apt-fast.conf' /etc/apt-fast.conf \
                   --bind '/opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list' /etc/apt/sources.list.d/sparkstore.list \
                apt-fast "$@"

rm -rf  /tmp/ss-apt-fast-conf

elif [ "$1" = "ssupdate" ];then
sudo curl --progress-bar -o /opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list "https://gitee.com/deepin-community-store/repo_auto_update_script/raw/master/mirror-list-for-apt-fast/sources.list.d/sparkstore.list"
sudo bwrap --dev-bind / / --bind '/opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list' /etc/apt/sources.list.d/sparkstore.list apt update -o Dir::Etc::sourcelist="sources.list.d/sparkstore.list"     -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"
#只更新星火源

else
	bwrap --dev-bind / / \
		   --bind '/opt/durapps/spark-store/bin/apt-fast-conf/sources.list.d/sparkstore.list' /etc/apt/sources.list.d/sparkstore.list \
                apt "$@"
fi


