diff options
author | neodarz <neodarz@neodarz.net> | 2019-05-25 17:35:13 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-05-25 17:35:13 +0200 |
commit | 8f7214761ad57142c26d31ff6564ef69410963dc (patch) | |
tree | 399aa967287edbcce2550d3b1e328e33180ed1e8 | |
download | tools_git_perso-8f7214761ad57142c26d31ff6564ef69410963dc.tar.xz tools_git_perso-8f7214761ad57142c26d31ff6564ef69410963dc.zip |
Initial commit
Diffstat (limited to '')
-rwxr-xr-x | gitrc_conf_gen.sh | 62 | ||||
-rwxr-xr-x | make_repo.sh | 22 |
2 files changed, 84 insertions, 0 deletions
diff --git a/gitrc_conf_gen.sh b/gitrc_conf_gen.sh new file mode 100755 index 0000000..cb41fd2 --- /dev/null +++ b/gitrc_conf_gen.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +GITROOT="/home/git/pub_repo" + +if [ $USER != $(stat -c %U ${GITROOT}) ] && [ $USER != "root" ] ; then + echo "Sorry you cannot write in ${GITROOT}." + echo "You must be the $(stat -c %U ${GITROOT}) user or the root user." + exit +fi + + +pushd ${GITROOT} > /dev/null + +echo "=== Generate config ===" +find . -mindepth 1 -maxdepth 5 -type d \( ! -iname ".*" \) \( ! -iname "refs" \) \( ! -iname "hooks" \) \( ! -iname "info" \) \( ! -iname "branches" \) \( ! -iname "objects" \) \( -iname "*.git" \)| sed 's|^\./||g' | +while read filename +do + echo "repo.url=$filename" + echo "repo.path=${GITROOT}/$filename" + echo "repo.readme=${GITROOT}/$filename/info/web/about.html" + echo "repo.desc=$(cat ${GITROOT}/$filename/description)" + echo "repo.owner=neodarz" + echo "" +done > cgitrepos + +echo "=== Generate post-receive ===" +find . -mindepth 1 -maxdepth 5 -type d \( ! -iname ".*" \) \( ! -iname "refs" \) \( ! -iname "hooks" \) \( ! -iname "info" \) \( ! -iname "branches" \) \( ! -iname "objects" \) \( -iname "*.git" \)| sed 's|^\./||g' | +while read filename +do +cat << EOF > ${GITROOT}/$filename/hooks/post-receive +#!/bin/bash + +agefile="\$(git rev-parse --git-dir)"/info/web/last-modified +aboutfile="\$(git rev-parse --git-dir)"/info/web/about.html + +echo "Generating $filename project about page..." +mkdir -p "\$(dirname "\$agefile")" && git for-each-ref --sort=-authordate --count=1 --format='%(authordate:iso8601)' > "\$agefile" +mkdir -p "\$(dirname "\$aboutfile")" && git show master:README.md | pandoc -f markdown > "\$aboutfile" + +if [[ \$(wc -c < \$(git rev-parse --git-dir)/info/web/about.html) -gt 1 && \$(cat ${GITROOT}/cgitrepos | grep "repo.readme=.*$filename.*" | wc -l) -eq 0 ]]; then + echo "=> About page generated, update configuration..." + sed -i "s repo.path.*$filename.*$ &\nrepo.readme=${GITROOT}/$filename/info/web/about.html g" ${GITROOT}/cgitrepos +fi + +EOF + +chmod +x ${GITROOT}/$filename/hooks/post-receive + +pushd ${GITROOT}/$filename/hooks/ > /dev/null +./post-receive +popd > /dev/null + +sudo chown -R git:git ${GITROOT} + + +if [ ! $(wc -c < ${GITROOT}/$filename/info/web/about.html) -gt 1 ]; then + sed -i "\ repo.readme=${GITROOT}/$filename/info/web/about.html d" cgitrepos +fi + +done + +echo "done !" diff --git a/make_repo.sh b/make_repo.sh new file mode 100755 index 0000000..98be45f --- /dev/null +++ b/make_repo.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +GITROOT="/home/git/pub_repo" + +if [ $USER != $(stat -c %U ${GITROOT}) ] && [ $USER != "root" ] ; then + echo "Sorry you cannot write in ${GITROOT}." + echo "You must be the $(stat -c %U ${GITROOT}) user or the root user." + exit +fi + +if [ "$1" ]; then + pushd ${GITROOT} > /dev/null + mkdir -p $1 + chown -R neodarz:neodarz $1 + pushd $1 > /dev/null + git init --bare --share=group + popd > /dev/null + chown -R git:git $1 +else + echo "You must specify a repo name like:" + echo "$0 myproject.git" +fi |