Skip to content

Commit

Permalink
aria2-install: Optimize details
Browse files Browse the repository at this point in the history
  • Loading branch information
P3TERX committed May 2, 2020
1 parent 4b2f0f3 commit 8a317f3
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions aria2-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# File name: aria2-install.sh
# Description: Install latest version Aria2
# System Required: Debian/Ubuntu or other
# Version: 1.4
# Version: 1.5
# Lisence: GPLv3
# Author: P3TERX
# Blog: https://p3terx.com (chinese)
Expand All @@ -24,10 +24,10 @@ Font_color_suffix="\033[0m"
INFO="[${Green_font_prefix}INFO${Font_color_suffix}]"
ERROR="[${Red_font_prefix}ERROR${Font_color_suffix}]"
ARCH=$(uname -m)
[ $(command -v dpkg) ] \
&& dpkgARCH=$(dpkg --print-architecture | awk -F- '{ print $NF }')
[ $(command -v dpkg) ] &&
dpkgARCH=$(dpkg --print-architecture | awk -F- '{ print $NF }')

echo -e "${INFO} Check the architecture ..."
echo -e "${INFO} Check CPU architecture ..."
if [[ $ARCH == i*86 || $dpkgARCH == i*86 ]]; then
ARCH="i386"
elif [[ $ARCH == "x86_64" || $dpkgARCH == "amd64" ]]; then
Expand All @@ -41,32 +41,36 @@ else
exit 1
fi

echo -e "${INFO} Check the version of Aria2 ..."
ARIA2_VER=$(curl -fsSL https://api.github.com/repos/P3TERX/aria2-builder/releases | grep -o '"tag_name": ".*"' | head -n 1 | sed 's/"//g' | sed 's/tag_name: //g')
[ -z $ARIA2_VER ] && {
echo -e "${ERROR} Unable to check the version, network failure or API error."
echo -e "${INFO} Get Aria2 download link ..."
TAG_NAME=$(curl -fsSL https://api.github.com/repos/P3TERX/aria2-builder/releases/latest | grep -o '"tag_name": ".*"' | head -n 1 | cut -d'"' -f4)
[ -z $TAG_NAME ] && {
echo -e "${ERROR} Unable to get Aria2 download link, network failure or API error."
exit 1
}
[ $(command -v aria2c) ] && {
[[ $(aria2c -v | grep $ARIA2_VER) ]] && {
echo -e "${INFO} The latest version Aria2 $ARIA2_VER is installed."
exit 0
} || {
echo -e "${INFO} Uninstall the old version ..."
$SUDO rm -rf $(command -v aria2c)
}
}
ARIA2_VER=${TAG_NAME%_*}
BUILD_DATE=${TAG_NAME#*_}

echo -e "${INFO} Download Aria2 ${ARIA2_VER} ${ARCH} ..."
curl -LS "https://github.com/P3TERX/aria2-builder/releases/download/${ARIA2_VER}/aria2-${ARIA2_VER}-static-linux-${ARCH}.tar.gz" | tar -zxC . || {
echo -e "${INFO} Download Aria2 ${ARIA2_VER} (build ${BUILD_DATE} ${ARCH}) ..."
curl -L "https://github.com/P3TERX/aria2-builder/releases/download/${TAG_NAME}/aria2-${ARIA2_VER}-static-linux-${ARCH}.tar.gz" | tar -xz
[ ! -s aria2c ] && {
echo -e "${ERROR} Unable to download aria2, network failure or other error."
exit 1
}

echo -e "${INFO} Installation Aria2 ${ARIA2_VER} ..."
$SUDO mv aria2c /usr/local/bin \
&& echo -e "${INFO} Aria2 successful installation !" \
|| {
while [ $(command -v aria2c) ]; do
echo -e "${INFO} Remove old version ..."
$SUDO rm -rf $(command -v aria2c) || {
echo -e "${ERROR} Unable to remove old version aria2 !"
exit 0
}
done

echo -e "${INFO} Installing Aria2 ${ARIA2_VER} (build ${BUILD_DATE} ${ARCH}) ..."
$SUDO mv aria2c /usr/local/bin &&
echo -e "${INFO} Aria2 installed successfully !" ||
{
echo -e "${ERROR} Aria2 installation failed !"
exit 1
}

exit 0

0 comments on commit 8a317f3

Please sign in to comment.