Skip to content

Instantly share code, notes, and snippets.

@cemtopkaya
Forked from awesomebytes/simple_debian_repository.md
Last active April 10, 2021 20:07
Show Gist options
  • Save cemtopkaya/69c6094a423741497f2da7f78b236e67 to your computer and use it in GitHub Desktop.
Save cemtopkaya/69c6094a423741497f2da7f78b236e67 to your computer and use it in GitHub Desktop.
How to create a simple debian repository with minimal dependences
# docker build -t my-debrepo -f Dockerfile.deb .
# Bulunduğu dizinde latest ve packages adından iki dizin oluşturulur.
# latest en güncel paketim tutulduğu dizin jenkins tarafımndan otomatik kullanılacaktır.
# packages ise tüm deb paketlerinin tutulduğu dizin.
# docker run --privileged -dit --name debrepo -p 8080:80 -v $(pwd)/latest:/usr/local/apache2/htdocs/latest/debs/amd64 -v $(pwd)/packages:/usr/local/apache2/htdocs/debs/amd64 -v "$(pwd)"/httpd.conf:/usr/local/apache2/httpdconf my-debrepo
# docker exec -it debianrepo nohup bash -c "/usr/local/apache2/htdocs/updaterepo.sh &" && sleep 4 ile repo'yu otomatik scan edecek script çalıştırılır.
FROM httpd:2.4
RUN echo "root:root" | chpasswd
RUN apt-get update && \
apt-get install -y cron openssh-server dpkg-dev rsync inotify-tools && \
useradd -m -G sudo -p sagWlIWIC4dLo -s /bin/bash ubuntu && \
echo "ubuntu ALL=(ALL:ALL) NOPASSWD:ALL" >> /etc/sudoers && \
mkdir /var/run/sshd && \
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd && \
echo "export VISIBLE=now" >> /etc/profile
#latest hızlı paket guncelleme için jenkins hattı tarafından kullanılacaktır.
RUN mkdir -p /usr/local/apache2/htdocs/latest/debs/amd64 && \
mkdir -p /usr/local/apache2/htdocs/debs/amd64 && \
echo "/usr/local/apache2/htdocs/latest/debs/amd64/" > /etc/default/inotifywait && \
echo "/usr/local/apache2/htdocs/debs/amd64/" >> /etc/default/inotifywait
COPY ./updaterepo.sh /usr/local/apache2/htdocs/updaterepo.sh
RUN chmod +x /usr/local/apache2/htdocs/updaterepo.sh
EXPOSE 80
EXPOSE 22

Simple debian repository

How to have a simple debian repository to offer your packages.

Requirements

You probably have them already installed

  • Python (I used 2.7).
  • dpkg-scanpackages: sudo apt-get install dpkg-dev
  • gzip: sudo apt-get install gzip

Create your debian hosting folder structure

mkdir simple_debian_repo
cd simple_debian_repo
mkdir debian

Add your .deb files to the debian folder

cp my_awesome_thing.deb simple_debian_repo/debian

Create Packages.gz file

You'll need to do this every time you add/update a .deb.

dpkg-scanpackages debian /dev/null | gzip -9c > debian/Packages.gz

You'll get an output similar to:

dpkg-scanpackages: warning: Packages in archive but missing from override file:
dpkg-scanpackages: warning:   my_awesome_thing.deb
dpkg-scanpackages: info: Wrote 1 entries to output Packages file.

Run a webserver to host it

Any will do, for simplicity I used Python one.

python -m SimpleHTTPServer 8000

Configure any machine to point to your new debian repository

For testing in your own machine (for other machines just use your IP address).

echo "deb [trusted=yes] http://127.0.0.1:8000 debian/" > /etc/apt/sources.list

Note that the packages will be non authenticated, so if you want to stop having warnings you'll need to add the [trusted=yes]

Tips

How to generate a Debian from a ROS Package

Follow instructions in this gist.

How to generate a Debian from a Python script

Nice instructions in this stack overflow answer.

#!/bin/bash
monitor() {
while inotifywait -e attrib -e modify -e create /usr/local/apache2/htdocs/latest/debs/amd64/
do
sleep 5
rsync -avz /usr/local/apache2/htdocs/latest/debs/amd64/ /usr/local/apache2/htdocs/latest/debs/
cd /usr/local/apache2/htdocs/latest/debs/amd64/
dpkg-scanpackages -m . /dev/null | gzip -9c > Packages.gz
sleep 20
rsync -avz /usr/local/apache2/htdocs/debs/amd64/ /usr/local/apache2/htdocs/debs/
sleep 5
cd /usr/local/apache2/htdocs/debs/amd64/
dpkg-scanpackages -m . /dev/null | gzip -9c > Packages.gz
done
}
monitor &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment