Last active
March 23, 2019 18:48
-
-
Save matanper/dcc998e7f8163dcc992470c03f1973ed to your computer and use it in GitHub Desktop.
Script to download packages in debian linux with all dependencies for installation in offline servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function contains() { | |
local n=$# | |
local value=${!n} | |
for ((i=1;i < $#;i++)) { | |
if [ "${!i}" == "${value}" ]; then | |
echo "y" | |
return 0 | |
fi | |
} | |
echo "n" | |
return 1 | |
} | |
download_all() { | |
# Download package itself | |
echo Download $1 | |
sudo apt-get download $1 | |
echo -e "All: ${packages[@]}" | |
# Download dependencies | |
for i in $(apt-cache depends $1 | grep -E 'Depends' | cut -d ':' -f 2,3 | sed -e s/'<'/''/ -e s/'>'/''/); do | |
# Check if package already been downloaded) | |
if [ $(contains "${packages[@]}" "$i") == "n" ]; then | |
# Add the package | |
packages+=($i); | |
# download the package + dependencies recursivly | |
download_all $i; | |
fi | |
done | |
} | |
# ==== Main ===== | |
declare -a packages | |
# TODO: add for loop here to support multi argument in the script | |
packages=($1) | |
download_all $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment