Bash – How to stop and restart apt-get


I have a very slow connection (~10KB/s) because my mobile carrier throttled me. Now, they will send about 32KB, then stop.

I am trying to install packages through apt-get, and I noticed that I can stop (ctrl-c) then restart the install and it will pick up from where it left off.

Doing this, I can get a little bit of data, then stop it, start it, and I get a little more data, otherwise (not stopping and restarting) I have to wait for about 15 seconds before more data comes

Is there a way I can automate this and have a script stop apt-get and start again?

Best Answer

Here is a script that takes the package names as arguments and runs apt-get repeatedly, killing it after a few seconds. It runs apt-get in "download" mode, so it will only download, not install. You may want to tweak the sleep time depending on how quickly your provider throttles the download.


me=$(basename $0)

if (($# == 0))
    printf "Usage: %s package [package]...\n" $me
    exit 1

printf "Will install %d package(s).\n" $#
printf "This will run forever.\n"
printf "You can stop it by pressing ctrl-C when prompted.\n"
printf "If that fails, open another window and type 'killall %s'.\n" $me
read -p "Press 'Enter' to continue: "

while :
    timeout 3 apt-get -y -d install "$@"
    printf "Press ctrl-C within one second to stop\n"
    sleep 1
Related Question