From d74153f706009b5e93f3fb6aa62b78e9273e9498 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 19 Apr 2018 12:35:41 +0200 Subject: [PATCH] Initial commit --- debian/changelog | 5 +++++ debian/compat | 1 + debian/control | 17 ++++++++++++++ debian/copyright | 24 ++++++++++++++++++++ debian/cron.d | 2 ++ debian/install | 6 +++++ debian/postinst | 14 ++++++++++++ debian/postrm | 14 ++++++++++++ debian/rules | 5 +++++ deploy | 5 +++++ git-hooks/post-receive | 20 +++++++++++++++++ vn-branch | 21 ++++++++++++++++++ vn-debuild | 50 ++++++++++++++++++++++++++++++++++++++++++ vn-deploy | 35 +++++++++++++++++++++++++++++ vn-rcheck | 21 ++++++++++++++++++ vn-repo.conf | 8 +++++++ 16 files changed, 248 insertions(+) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100755 debian/cron.d create mode 100644 debian/install create mode 100755 debian/postinst create mode 100755 debian/postrm create mode 100755 debian/rules create mode 100755 deploy create mode 100755 git-hooks/post-receive create mode 100755 vn-branch create mode 100755 vn-debuild create mode 100755 vn-deploy create mode 100755 vn-rcheck create mode 100644 vn-repo.conf diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..5e74615 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +vn-repo (2.0.2) stable; urgency=low + + * Initial Release. + + -- Juan Ferrer Toribio Wed, 19 Aug 2015 12:00:00 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..f11c82a --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +9 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..ed20fb4 --- /dev/null +++ b/debian/control @@ -0,0 +1,17 @@ +Source: vn-repo +Priority: optional +Maintainer: Juan Ferrer Toribio +Build-Depends: build-essential, debhelper +Standards-Version: 3.9.3 +Section: misc +Homepage: https://www.verdnatura.es +Vcs-Git: https://git.verdnatura.es/vn-repo + +Package: vn-repo +Architecture: all +Depends: reprepro, git, sudo, devscripts +Suggests: apache2 | httpd, git, gitweb, gitweb-theme, nodejs +Section: vcs +Priority: optional +Description: Helper to set up a repository + Prepares the system to host a Git and APT repository. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..77f926c --- /dev/null +++ b/debian/copyright @@ -0,0 +1,24 @@ +Format: http://dep.debian.net/deps/dep5 +Name: vn-repo +Source: https://git.verdnatura.es/vn-repo + +Files: * +Copyright: 2011-2015 Juan Ferrer Toribio +License: GPL-3.0+ + +License: GPL-3.0+ + This package is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + . + You should have received a copy of the GNU General Public License + along with this program. If not, see . + . + On Debian systems, the complete text of the GNU General Public + License can be found in "/usr/share/common-licenses/GPL-3". diff --git a/debian/cron.d b/debian/cron.d new file mode 100755 index 0000000..c660534 --- /dev/null +++ b/debian/cron.d @@ -0,0 +1,2 @@ +MAILTO=hostmaster +#*/1 * * * * vn-repo (cd && vn-rcheck) diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..bed4e9c --- /dev/null +++ b/debian/install @@ -0,0 +1,6 @@ +vn-repo.conf etc/apache2/conf-available +git-hooks/post-receive usr/bin +vn-branch usr/bin +vn-deploy usr/bin +vn-debuild usr/bin +vn-rcheck usr/bin \ No newline at end of file diff --git a/debian/postinst b/debian/postinst new file mode 100755 index 0000000..74d6443 --- /dev/null +++ b/debian/postinst @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +# Adds the repository user + +useradd --shell /bin/bash --home-dir /var/cache/reprepro --create-home vn-repo + +# Enables Apache configuration + +if [ -e /usr/share/apache2/apache2-maintscript-helper ] +then + . /usr/share/apache2/apache2-maintscript-helper + apache2_invoke enconf vn-repo.conf +fi diff --git a/debian/postrm b/debian/postrm new file mode 100755 index 0000000..1f4ec9d --- /dev/null +++ b/debian/postrm @@ -0,0 +1,14 @@ +#!/bin/bash +set -e + +# Removes the repository user + +userdel vn-repo + +# Enables Apache configuration + +if [ -e /usr/share/apache2/apache2-maintscript-helper ] +then + . /usr/share/apache2/apache2-maintscript-helper + apache2_invoke disconf vn-repo.conf +fi diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..abde6ef --- /dev/null +++ b/debian/rules @@ -0,0 +1,5 @@ +#!/usr/bin/make -f + +%: + dh $@ + diff --git a/deploy b/deploy new file mode 100755 index 0000000..25af650 --- /dev/null +++ b/deploy @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +vn-debuild +vn-deploy www1.static www2.static diff --git a/git-hooks/post-receive b/git-hooks/post-receive new file mode 100755 index 0000000..692205d --- /dev/null +++ b/git-hooks/post-receive @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +while read oldrev newrev ref +do + if [[ ! $ref =~ .*/master$ ]] + then + continue + fi + + myHost=$(hostname) + repoDir=$(dirname "$0")/.. + projectName=$(basename "$(realpath "$repoDir")") + + echo "Ref $ref received. It will be deployed automatically." + echo "Host $myHost" + + echo "$projectName" "master" > /tmp/vn-repo.changes + #nohup sudo -u vn-repo "vn-branch $projectName" &> /dev/null & +done diff --git a/vn-branch b/vn-branch new file mode 100755 index 0000000..2b00cef --- /dev/null +++ b/vn-branch @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +if [ "$#" -eq "0" ]; then + exit 1 +fi + +projectName=$1 +repoDir="/var/lib/git/$projectName" +srcDir="/tmp/vn-repo/$projectName/src" +logFile="/var/cache/reprepro/logs/$projectName.out" + +rm -f "$logFile" + +mkdir -p "$srcDir" +git --work-tree="$srcDir" --git-dir="$repoDir" checkout -f + +if [ -f "$srcDir/deploy" ] +then + (cd "$srcDir" && "$srcDir/deploy" >> "$logFile") +fi diff --git a/vn-debuild b/vn-debuild new file mode 100755 index 0000000..483b332 --- /dev/null +++ b/vn-debuild @@ -0,0 +1,50 @@ +#!/bin/bash +set -e + +if [ "$#" -eq "0" ]; then + srcDir="$PWD" +else + srcDir="$1" +fi + +buildDir="$srcDir/.." +repreproDir="/var/cache/reprepro" +codename="stable" + +echo "Building source code." +echo " * Directory $buildDir" + +if [ -f "$srcDir/package.json" ] +then + echo "Installing Node dependencies." + (cd "$srcDir" && npm --silent install) +fi + +if [ -f "$srcDir/debian/changelog" ] +then + echo "Cleaning last build." + rm -f $buildDir/*.deb + rm -f $buildDir/*.changes + rm -f $buildDir/*.build + (cd "$srcDir" && debian/rules clean) + + echo "Building Debian packages." + (cd "$srcDir" && debuild -uc -us -b) + + echo "Adding packages to repository." + + cut -d" " -f1 "$srcDir/debian/files" | + while read debFile + do + if [[ ! "$debFile" =~ .*\.deb$ ]] + then + continue + fi + + echo " * Adding $debFile" + reprepro -b "$repreproDir" includedeb $codename "$buildDir/$debFile" + done +else + echo "$0: Invalid source directory: $srcDir" + exit 2 +fi diff --git a/vn-deploy b/vn-deploy new file mode 100755 index 0000000..8203d3d --- /dev/null +++ b/vn-deploy @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +hosts=$1 + +if [ -z "$hosts" ] +then + echo "Usage: $(basename $0) host1 [host2]..." + exit 1 +fi + +packages="" + +cut -d" " -f1 "$srcDir/debian/files" | +while read debFile +do + packageName=$(echo $debFile | cut -d"_" -f1) + packages="$packages $packageName" +done + +if [ -z "$packages" ] +then + echo "No packages found to install" + exit 1 +fi + +# FIXME: Packages are not upgraded when config files are changed + +echo "Upgrading servers." + +for host in $hosts +do + echo " * Upgrading $host" + ssh root@$host "update-repo vn && apt-get install $packages" +done diff --git a/vn-rcheck b/vn-rcheck new file mode 100755 index 0000000..264352f --- /dev/null +++ b/vn-rcheck @@ -0,0 +1,21 @@ +#!/bin/bash +set -e + +changesFile="/tmp/vn-repo.changes" + +( + flock -n 200 || exit + + if [ -f "$changesFile" ] + then + while read -r line + do + projectName=$(echo $line | cut -d" " -f1) + branch=$(echo $line | cut -d" " -f2) + + vn-branch $projectName + done < "$changesFile" + + rm $changesFile + fi +) 200> /var/lock/vn-repo.lock diff --git a/vn-repo.conf b/vn-repo.conf new file mode 100644 index 0000000..c58c159 --- /dev/null +++ b/vn-repo.conf @@ -0,0 +1,8 @@ +#Alias /apt /var/cache/reprepro/ + + + Options Indexes + Options +FollowSymLinks + AllowOverride None + Require all granted +