如何修改apt-axel脚本

发布时间:2021-12-20 09:20:03 作者:小新
来源:亿速云 阅读:155

这篇文章给大家分享的是有关如何修改apt-axel脚本的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

我把apt-axel脚本更改了一下,以适合自己的使用: 修改如下:

下面是apt-axel文件

#!/bin/bash

###########################################################################
#
# Authors: Jes鷖 Espino Garc韆 & Lucas Garc韆
# Email: jespino@imap.cc
# Date: 31/05/2004
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
###########################################################################

# If the config file not exist, load the default parameters

VERSION="0.1"
CONFIG_FILE="/etc/apt-axel.conf";

if [ -f $CONFIG_FILE ]; then
. $CONFIG_FILE
else
# Verbose TRUE or FALSE
VERBOSE="FALSE"

# Conections
CONNECTIONS=8

# Servers
server1="ftp://ftp.de.debian.org/debian/"
server2="ftp://ftp.es.debian.org/debian/"
server3="ftp://ftp.fr.debian.org/debian/"
server4="ftp://ftp.it.debian.org/debian/"
server5="ftp://ftp.fi.debian.org/debian/"
server6="ftp://ftp.uk.debian.org/debian/"
server7="ftp://ftp.tk.debian.org/debian/"
server8="ftp://ftp.us.debian.org/debian/"
fi

# Set the package variable to be global
package="";

# Show the help
mostrar_ayuda() {
echo "Usage: apt-axel  ";
echo "";
echo "Options:";
echo "  install - Install new packages (paquete es libc6 y no libc6.deb)";
echo "  upgrade - Do a software upgrade";
echo "  dist-upgrade - Do a distribution upgrade, see apt-get(8)";
echo "  --version - Print the current version of apt-axel";
echo "  --help - Show this help";
echo "";
}

# Get a package from the ftp server
get_package() {
descargar() {
# Check the $VERBOSE variable and the filesize, if the filesize is lower than 200K will use only 4 conections
# And if the $VERBOSE variable is TRUE, then print the axel output
if [ $VERBOSE == "TRUE" ]; then
if [ $size -gt 200000 ]; then
echo $server1$url
axel -a -n $CONNECTIONS $server1$url -o /tmp/$archivo -S $mirror1
else
axel -a -n 4 $server1$url -o /tmp/$archivo -S $mirror1
fi
else
echo -n "Geting $package package: "
if [ $size -gt 200000 ]; then
axel -a -n $CONNECTIONS $server1$url -o /tmp/$archivo -S $mirror1 > /dev/null
else
axel -a -n 4 $server1$url -o /tmp/$archivo -S $mirror1 > /dev/null
fi
echo "Done"
fi
}

# Getting data
url=$(apt-cache show $package | grep ^Filename: | sed s/^Filename: //)
archivo=$(echo "$url" | sed s/^.*$package/$package/)
pkgstatus=$(dpkg -s $package 2> /dev/null | grep ^Status: | grep -v "not-installed")
md5sum=$(apt-cache show $package | grep ^MD5sum: | sed s/^MD5sum: //)
size=$(apt-cache show $package | grep ^Size: | sed s/^Size: //)

# Downloading the package
if [ -f /var/cache/apt/archives/$archivo ]; then
echo -n "Package already downloaded. Checking md5sum of $package package: "
while [ $md5sum != $(md5sum /var/cache/apt/archives/$archivo | sed s/ .*$//) ]; do
echo "incorrect"
echo "Downloading again $package package."
rm -f /var/cache/apt/archives/$archivo
descargar
done
echo "correct"
else
descargar
fi

# Move the file to /var/cache/apt/archives
if [ -f /tmp/$archivo ]; then
if [ $md5sum == $(md5sum /tmp/$archivo | sed s/ .*$//) ]; then
mv -f /tmp/$archivo /var/cache/apt/archives/
fi
fi
}

pkg_install() {
for package in $(apt-get -s install $1 | grep ^Inst | sed s/^Inst // | sed s/ .*$//); do
get_package
done
apt-get -y install $1
}

upgrade() {
for package in $(apt-get -s upgrade | grep ^Inst | sed s/^Inst // | sed s/ .*$//); do
get_package
done
apt-get -y upgrade
}

dist_upgrade() {
for package in $(apt-get -s dist-upgrade | grep ^Inst | sed s/^Inst // | sed s/ .*$//); do
get_package
done
apt-get -y dist-upgrade
}

#
# Main program
#
if [ `id -u` != 0 ]; then
echo "You must be root to run this command."
else
case $1 in
install) pkg_install $2;;
upgrade) upgrade;;
dist-upgrade) dist_upgrade;;
(--version) echo "Current Version: $VERSION";;
(--help | -h) mostrar_ayuda;;
*) mostrar_ayuda;;
esac
fi

配置文件: GNU nano 1.3.12 File: /etc/apt-axel.conf

# Verbose TRUE or FALSE
VERBOSE="TRUE"

# Conections
CONNECTIONS=20

# Servers
server1="http://ubuntu.cnsite.org/ubuntu/"
mirror1="http://ubuntu.cn99.com/ubuntu/"

[download id=“24”]

感谢各位的阅读!关于“如何修改apt-axel脚本”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. 批量修改主机名脚本
  2. windows下使用脚本修改网络配置

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

上一篇:websphere内存增长且占用过大怎么办

下一篇:怎么进行WebSphere远程代码执行漏洞CVE-2020-4450分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》