To do this, begin by installing apt-mirror on your Ubuntu system.
sudo apt-get update
sudo apt-get install apt-mirror
Then edit the mirror.list (/etc/apt/mirror.list) file so that the ROS repositories will be mirrored, here is an example for both x86 and amd64 systems.
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
# set mirror_path $base_path/mirror
# set skel_path $base_path/skel
# set var_path $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads 20
set _tilde 0
#
############# end config ##############
#deb http://packages.ros.org/ros/ubuntu jaunty main
deb http://packages.ros.org/ros/ubuntu karmic main
deb http://packages.ros.org/ros/ubuntu lucid main
deb http://packages.ros.org/ros/ubuntu maverick main
#deb-i386 http://packages.ros.org/ros/ubuntu jaunty main
deb-i386 http://packages.ros.org/ros/ubuntu karmic main
deb-i386 http://packages.ros.org/ros/ubuntu lucid main
deb-i386 http://packages.ros.org/ros/ubuntu maverick main
Once apt-mirror is set up, you can mirror the repository by running the command:
sudo su - apt-mirror -c apt-mirror
This may take a while the first time that you run it. This will download a copy of the ROS repository to /var/spool/apt-mirror by default.
You can now set up Apache to point to the mirror so that it is accessible through http.
As an example, here is my Apache configuration (/etc/apache2/sites-available/mirror.<+YOURDOMAIN+>.com)
<VirtualHost *:80>
ServerName mirror.<+YOURDOMAIN+>.com
ServerAlias www.mirror.<+YOURDOMAIN+>.com
ServerAdmin XXXXXXX@ieee.org
DocumentRoot "/var/www/mirror.<+YOURDOMAIN+>.com"
ErrorLog /var/log/apache2/mirror.<+YOURDOMAIN+>.com/error_log
<Directory "/var/www/mirror.<+YOURDOMAIN+>.com">
Options +Indexes
Order allow,deny
Allow from all
</Directory>
<IfModule log_config_module>
TransferLog /var/log/apache2/mirror.<+YOURDOMAIN+>.com/access_log
</IfModule>
</VirtualHost>
Then you may enable the site and create a symlink to the apt-mirror directory:
sudo a2ensite mirror.<+YOURDOMAIN+>.com
sudo ln -s /var/spool/apt-mirror/mirror/code.ros.org /var/www/mirror.<+YOURDOMAIN+>.com/archive-ros
Your mirror will be available at http://mirror.<+YOURDOMAIN+>.com/archive-ros/
You can add it to your local apt repository using the following command:
sudo sh -c '. /etc/lsb-release && echo "deb http://mirror.<+YOURDOMAIN+>.com/archive-ros/packages/ros/ubuntu $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
And then follow the rest of the ROS install guide.
It also helps to set up a cron task to keep the repository synced, do this by uncommenting the line in /etc/cron.d/apt-mirror
#
# Regular cron jobs for the apt-mirror package
#
0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log