Skip to content

Instantly share code, notes, and snippets.

@hallazzang
Created January 6, 2021 04:19
Show Gist options
  • Save hallazzang/3b1f5c4eb13b24c1f4da053597b5f98a to your computer and use it in GitHub Desktop.
Save hallazzang/3b1f5c4eb13b24c1f4da053597b5f98a to your computer and use it in GitHub Desktop.
APT package offline installation
#!/bin/bash
if [ -z "$1" ]; then
echo "usage: ./install.sh <package name>"
exit 0
fi
echo "Installing $1..."
tar xf "$1.tar.gz"
if [ $? -ne 0 ]; then
echo "Error extracting archive"
exit 1
fi
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
if [ $? -ne 0 ]; then
echo "Error creating backup for apt source list"
exit 1
fi
echo "deb [trusted=yes allow-insecure=true] file:$(pwd)/$1 ./" | sudo tee /etc/apt/sources.list
if [ $? -ne 0 ]; then
echo "Error substituting apt source list"
exit 1
fi
sudo apt-get update
sudo apt-get install -y "$1"
sudo mv /etc/apt/sources.list.bak /etc/apt/sources.list
if [ $? -ne 0 ]; then
echo "Error restoring apt source list"
exit 1
fi
rm -r $1
#!/bin/bash
if [ -z "$1" ]; then
echo "usage: ./package.sh <package name>"
exit 0
fi
tmp_dir=$(mktemp -d -t package-XXXXXXXX)
echo "Installing inside $tmp_dir"
content_dir="$tmp_dir/$1"
mkdir -p $content_dir
pushd $content_dir
apt-get download \
$(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts \
--no-breaks --no-replaces --no-enhances $1 \
| grep "^\w" | sort -u)
if [ $? -ne 0 ]; then
echo "Error downloading packages"
exit 1
fi
dpkg-scanpackages . | gzip -9c > Packages.gz
if [ $? -ne 0 ]; then
echo "Error creating package index"
exit 1
fi
popd
pushd $tmp_dir
tar czf "$1.tar.gz" "$1"
if [ $? -ne 0 ]; then
echo "Error archiving packages"
fi
popd
cp "$tmp_dir/$1.tar.gz" .
rm -rf $tmp_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment