在Ubuntu一些标准化服务的部署环境中,如果能够在离线环境中获得某些软件包的安装将是非常方便的。
看了一些网上关于制作Ubuntu离线offline软件源的博文,就一个相对目录的问题就说的不清不楚。Linus大神说,Talk is Cheap,Show me The Code!
如果能够看到代码中是如何制作离线软件源,就会更容易理解这个过程。。。
注意:在事先需要利用GPG产生对软件包签名的公钥和私钥,并导出为二进制格式
见github中积累的制作脚本:Show me the Code
# !/bin/sh
# required: before excuted,please use sudo su to switch to root user!
# required: curl && gpg shell scripts
# user must be root!
usertest=`whoami`
if [ $usertest != "root" ];then
echo "you must use root to run this script!use 'sudo su' to switch to root user!"
exit 1
fi
# you can create the keys using gpg and import these in binary format
echo "use key sign..."
if [ ! -r go-private-key.sec ] ; then
echo "get private key from deploying server..."
OFFLINE_DEBS_SITE="http://192.168.31.133/"
OFFLINE_DEBS_JUMPER_URL="$OFFLINE_DEBS_SITE/go"
curl -O $OFFLINE_DEBS_JUMPER_URL/go-private-key.sec
fi
gpg --import go-private-key.sec
echo "get the needed deb resources ..."
# maybe mirror changed,so update firstly to reform indexs
apt-get update
apt-get install -y xrdp xorg openbox wish freerdp-x11 ntpdate zip unzip numlockx
rm -rf /var/debs
if [ -r /var/debs.tar ] ; then
yes | rm -f /var/debs.tar
fi
mkdir -p /var/debs
cp -r /var/cache/apt/archives/*.deb /var/debs/
echo "to form debs index file..."
cd /var/
apt-ftparchive packages debs > debs/Packages
cd debs
gzip -c Packages > Packages.gz
apt-ftparchive release . > Release
# you should use your signature user name e.g 'go'
gpg --local-user go --clearsign -o InRelease Release
gpg --local-user go -abs -o Release.gpg Release
echo "create debs tar file at /var/debs.tar ..."
cd /var/
tar cvf debs.tar debs/
echo "create debs tar file at /var/debs.tar end..."
补使用离线软件源的部分代码:
echo "use local offline debs site..."
mv /etc/apt/sources.list /etc/apt/sources.list.bak
echo "deb $OFFLINE_DEBS_SITE/jumper debs/" > /etc/apt/sources.list
echo "import deb release key..."
apt-key add ~/jumper/jumper-public-key.sec
apt-get update