My linux world » Repo

Repo


Contents

Objectives

Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. ##################################################
  4. # DEFINES
  5. ##################################################
  6. REPOSITORY_PATH=/var/www/html/rpm
  7.  
  8.  
  9. ##################################################
  10. # CREATE REPOSITORY
  11. ##################################################
  12.  
  13. echo "install createrepo repoview"
  14. dnf -y install createrepo repoview
  15.  
  16. echo "create repo file"
  17. mkdir -p $REPOSITORY_PATH
  18. cat > /var/www/html/rpm/myrepo.repo << "EOF"
  19. [myrepo]
  20. name=CentOS-$releasever - Base
  21. baseurl=url:192.168.184.132/rpm/$releasever/$basearch/
  22. gpgcheck=0
  23. enabled=1
  24. protect=1
  25. EOF
  26.  
  27.  
  28. echo "create repository"
  29. mkdir -p $REPOSITORY_PATH/centos/7/x86_64
  30.  
  31. echo "create script to update repo"
  32. mkdir -p /opt/rpm/scripts
  33. cat > /opt/rpm/scripts/autoupdate.sh << "EOF"
  34. #!/bin/bash
  35.  
  36. chown -R apache:apache /var/www/html/rpm/ -R
  37. createrepo --unique-md-filenames --checksum sha -d /var/www/html/rpm/centos/7/x86_64
  38. repoview /var/www/html/rpm/centos/7/x86_64
  39. EOF
  40.  
  41. echo "add autoupdate script to crontab"
  42. if ! grep -q RPM /etc/crontab; then
  43. echo "" >> /etc/crontab
  44. echo "######## RPM #######" >> /etc/crontab
  45. echo "every 1 minutes" >> /etc/crontab
  46. echo "*/1 * * * * root chmod a+x /opt/rpm/scripts/autoupdate.sh; /opt/rpm/scripts/autoupdate.sh" >> /etc/crontab
  47. echo "######## RPM #######" >> /etc/crontab
  48. fi
  49.  
  50.  
  51. ##################################################
  52. # CONFIGURE HTTPD
  53. ##################################################
  54.  
  55. echo "create /etc/httpd/conf.d/repo.conf"
  56. cat > /etc/httpd/conf.d/repo.conf << "EOF"
  57. <Directory /var/www/html/>
  58. Options Indexes
  59. Options Indexes FollowSymLinks
  60. Require all granted
  61. </Directory>
  62. EOF
  63.  
  64. echo "restart httpd"
  65. systemctl restart httpd.service
  66.  
  67. ##################################################
  68. # SIGN REPOSITORY
  69. ##################################################
  70. # echo "sign repository"
  71. # gpg --gen-key
  72. # gpg --detach-sign --armor $REPOSITORY_PATH/centos/7/x86_64/repodata/repomd.xml
  73.  
  74.  
  75. myip=`hostname -I`
  76. echo "Now meet you here: http://$myip/rpm/centos/7/x86_64/repoview/index.html"
  77.  

FAQ

How to use repository?

echo "import repository"
sudo wget -O /etc/yum.repos.d/myrepo.repo http://myrpmserver/myrepo.repo
echo "you can use it with yum"
echo "example: yum package-present-in-myrepo"

How to synchronize centos repository?

reposync

How to add rpm to my repository?

Just copy them in the directory.
The ‘autoupdate.sh’ script will update database automatically.


Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.