mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-06 19:32:22 +08:00
aptss支持在安装软件的同时使用download功能
Signed-off-by: shenmo <jifengshenmo@outlook.com>
This commit is contained in:
parent
3dc2c3ab42
commit
1b68ec3622
@ -20,6 +20,13 @@ shopt -s nullglob
|
|||||||
# third argument are piped to stderr.
|
# third argument are piped to stderr.
|
||||||
|
|
||||||
THREADS=$(nproc 2>/dev/null || echo 4)
|
THREADS=$(nproc 2>/dev/null || echo 4)
|
||||||
|
|
||||||
|
# Set color variables.
|
||||||
|
cGreen='\e[0;32m'
|
||||||
|
cRed='\e[0;31m'
|
||||||
|
cBlue='\e[0;34m'
|
||||||
|
endColor='\e[0m'
|
||||||
|
|
||||||
msg(){
|
msg(){
|
||||||
msg_options=()
|
msg_options=()
|
||||||
case "$2" in
|
case "$2" in
|
||||||
@ -36,6 +43,51 @@ msg(){
|
|||||||
echo -e "${msg_options[@]}" "${aptfast_prefix}${beginColor}$1${endColor}" >&2
|
echo -e "${msg_options[@]}" "${aptfast_prefix}${beginColor}$1${endColor}" >&2
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
msg_already_running()
|
||||||
|
{
|
||||||
|
msg "Other aptss is running. Waited $timer senconds..." "normal"
|
||||||
|
msg "有其他的aptss正在运行。已经等待了$timer秒" "normal"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if a lock file exists.
|
||||||
|
#if [ -f "$LCK_FILE.lock" ]; then
|
||||||
|
# msg_already_running
|
||||||
|
# exit 1
|
||||||
|
#fi
|
||||||
|
|
||||||
|
LCK_FD=99
|
||||||
|
# create the lock file and lock it, die on failure
|
||||||
|
_create_lock()
|
||||||
|
{
|
||||||
|
eval "exec $LCK_FD>\"$LCK_FILE.lock\""
|
||||||
|
|
||||||
|
# 设置 trap 来清理资源
|
||||||
|
trap "cleanup_aptfast" EXIT
|
||||||
|
trap "cleanup_aptfast; exit 1" INT TERM
|
||||||
|
|
||||||
|
timer=0
|
||||||
|
max_wait=180 # 最大等待时间为180秒(3分钟)
|
||||||
|
|
||||||
|
until $(flock -xn $LCK_FD); do
|
||||||
|
msg_already_running
|
||||||
|
sleep 1
|
||||||
|
let timer+=1
|
||||||
|
|
||||||
|
if [ $timer -ge $max_wait ]; then
|
||||||
|
echo "timeout"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
unset timer
|
||||||
|
}
|
||||||
|
|
||||||
|
# unlock and remove the lock file
|
||||||
|
_remove_lock()
|
||||||
|
{
|
||||||
|
flock -u "$LCK_FD" 2>/dev/null
|
||||||
|
rm -f "$LCK_FILE.lock"
|
||||||
|
}
|
||||||
|
|
||||||
# Search for known options and decide if root privileges are needed.
|
# Search for known options and decide if root privileges are needed.
|
||||||
root=$#
|
root=$#
|
||||||
@ -44,6 +96,7 @@ for argument in "$@"; do
|
|||||||
case "$argument" in
|
case "$argument" in
|
||||||
upgrade | full-upgrade | install | dist-upgrade | build-dep)
|
upgrade | full-upgrade | install | dist-upgrade | build-dep)
|
||||||
option="install"
|
option="install"
|
||||||
|
_create_lock
|
||||||
;;
|
;;
|
||||||
clean | autoclean)
|
clean | autoclean)
|
||||||
option="clean"
|
option="clean"
|
||||||
@ -122,7 +175,7 @@ LCK_FILE="/tmp/apt-fast-in-container.lock"
|
|||||||
else
|
else
|
||||||
LCK_FILE="/tmp/apt-fast.lock"
|
LCK_FILE="/tmp/apt-fast.lock"
|
||||||
fi
|
fi
|
||||||
LCK_FD=99
|
|
||||||
|
|
||||||
# Set default package manager, APT cache, temporary download dir,
|
# Set default package manager, APT cache, temporary download dir,
|
||||||
# temporary download list file, and maximal parallel downloads
|
# temporary download list file, and maximal parallel downloads
|
||||||
@ -145,11 +198,9 @@ if [ -f "$NETRC" ]; then
|
|||||||
fi
|
fi
|
||||||
APTAUTHFILES+=("$NETRCDIR"*)
|
APTAUTHFILES+=("$NETRCDIR"*)
|
||||||
|
|
||||||
if [ "$IS_ACE_ENV" != "" ];then
|
LISTTEMP=$(mktemp -d)
|
||||||
DLLIST="/tmp/apt-fast-in-container.list"
|
DLLIST="${LISTTEMP}/apt-fast.list"
|
||||||
else
|
|
||||||
DLLIST="/tmp/apt-fast.list"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -164,11 +215,7 @@ MIRRORS=()
|
|||||||
aptfast_prefix=
|
aptfast_prefix=
|
||||||
# aptfast_prefix="$(date '+%b %_d %T.%N') apt-fast: "
|
# aptfast_prefix="$(date '+%b %_d %T.%N') apt-fast: "
|
||||||
|
|
||||||
# Set color variables.
|
|
||||||
cGreen='\e[0;32m'
|
|
||||||
cRed='\e[0;31m'
|
|
||||||
cBlue='\e[0;34m'
|
|
||||||
endColor='\e[0m'
|
|
||||||
|
|
||||||
# Set timout value for apt-fast download confirmation dialog.
|
# Set timout value for apt-fast download confirmation dialog.
|
||||||
# Value is in seconds.
|
# Value is in seconds.
|
||||||
@ -240,51 +287,7 @@ if [ ! -t 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
msg_already_running()
|
|
||||||
{
|
|
||||||
msg "Other aptss is running. Waited $timer senconds..." "normal"
|
|
||||||
msg "有其他的aptss正在运行。已经等待了$timer秒" "normal"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Check if a lock file exists.
|
|
||||||
#if [ -f "$LCK_FILE.lock" ]; then
|
|
||||||
# msg_already_running
|
|
||||||
# exit 1
|
|
||||||
#fi
|
|
||||||
|
|
||||||
|
|
||||||
# create the lock file and lock it, die on failure
|
|
||||||
_create_lock()
|
|
||||||
{
|
|
||||||
eval "exec $LCK_FD>\"$LCK_FILE.lock\""
|
|
||||||
|
|
||||||
# 设置 trap 来清理资源
|
|
||||||
trap "cleanup_aptfast" EXIT
|
|
||||||
trap "cleanup_aptfast; exit 1" INT TERM
|
|
||||||
|
|
||||||
timer=0
|
|
||||||
max_wait=180 # 最大等待时间为180秒(3分钟)
|
|
||||||
|
|
||||||
until $(flock -xn $LCK_FD); do
|
|
||||||
msg_already_running
|
|
||||||
sleep 1
|
|
||||||
let timer+=1
|
|
||||||
|
|
||||||
if [ $timer -ge $max_wait ]; then
|
|
||||||
echo "timeout"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
unset timer
|
|
||||||
}
|
|
||||||
|
|
||||||
# unlock and remove the lock file
|
|
||||||
_remove_lock()
|
|
||||||
{
|
|
||||||
flock -u "$LCK_FD" 2>/dev/null
|
|
||||||
rm -f "$LCK_FILE.lock"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Move download file away so missing permissions won't stop usage.
|
# Move download file away so missing permissions won't stop usage.
|
||||||
CLEANUP_STATE=0
|
CLEANUP_STATE=0
|
||||||
@ -294,7 +297,7 @@ cleanup_dllist()
|
|||||||
then
|
then
|
||||||
if ! mv -- "$DLLIST{,.old}" 2>/dev/null
|
if ! mv -- "$DLLIST{,.old}" 2>/dev/null
|
||||||
then
|
then
|
||||||
if ! rm -f -- "$DLLIST" 2>/dev/null
|
if ! rm -fr -- "${LISTTEMP}" 2>/dev/null
|
||||||
then
|
then
|
||||||
msg "Could not clean up download list file." "warning"
|
msg "Could not clean up download list file." "warning"
|
||||||
msg "无法清除下载列表文件." "warning"
|
msg "无法清除下载列表文件." "warning"
|
||||||
@ -608,7 +611,7 @@ display_downloadfile(){
|
|||||||
|
|
||||||
# Create and insert a PID number to lockfile.
|
# Create and insert a PID number to lockfile.
|
||||||
|
|
||||||
_create_lock
|
|
||||||
|
|
||||||
# Make sure aria2c (in general first parameter from _DOWNLOADER) is available.
|
# Make sure aria2c (in general first parameter from _DOWNLOADER) is available.
|
||||||
CMD="$(echo "$_DOWNLOADER" | sed 's/^\s*\([^ ]\+\).*$/\1/')"
|
CMD="$(echo "$_DOWNLOADER" | sed 's/^\s*\([^ ]\+\).*$/\1/')"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user