move old files to old directory
Signed-off-by: Václav Valíček <valicek1994@gmail.com>
This commit is contained in:
18
old/checker/cloner-lib-auth
Normal file
18
old/checker/cloner-lib-auth
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
# library made for sourcing - just to prepare git auth environment
|
||||
|
||||
function prepareGitAuth(){
|
||||
# usage
|
||||
# $1 - config directory
|
||||
confdir=$1/auth
|
||||
[ -d $confdir ] || mkdir $confdir
|
||||
[ -d $confdir/ssh ] || mkdir $confdir/ssh
|
||||
|
||||
chmod 0700 $confdir
|
||||
|
||||
# git configure http authenticator
|
||||
git config --global credential.helper "store --file=$confdir/git-credentials"
|
||||
# git configure ssh auth
|
||||
git config --global core.sshcommand "ssh -i $confdir/ssh/identity -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes -q"
|
||||
}
|
||||
|
||||
11
old/checker/cloner-lib-cfg
Normal file
11
old/checker/cloner-lib-cfg
Normal file
@@ -0,0 +1,11 @@
|
||||
# library for work with config file
|
||||
|
||||
# check directories if they exist
|
||||
[ -d $CONFIG_DIR ] || die "Config directory does not exist on volune - $CONFIG_DIR"
|
||||
[ -f $CONFIG_DIR/cloner.cfg ] || die "Config file does not exist - create please cloner.cfg"
|
||||
# load config files
|
||||
source $CONFIG_DIR/cloner.cfg
|
||||
|
||||
# check if the url is specified
|
||||
repo=${cloner_repo_url:-}
|
||||
[ -z "$repo" ] && die "No repository url is specified" || true
|
||||
11
old/checker/cloner-lib-general
Normal file
11
old/checker/cloner-lib-general
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
# configure
|
||||
export CCLONE_PATH=$BASE/repos
|
||||
export CCLONE_CACHE=$BASE/cache
|
||||
export CONFIG_DIR=$BASE/config
|
||||
|
||||
function die(){
|
||||
echo "$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
29
old/checker/detector-lib-cfg
Normal file
29
old/checker/detector-lib-cfg
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
# check if varriable is set
|
||||
[ -n "$CONFIG_DIR" ] || die "ConfigDir is not set - exit!"
|
||||
|
||||
|
||||
function detectorRunCapable(){
|
||||
if [ -f $CONFIG_DIR/detector.cfg ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function detectorLoadConfig(){
|
||||
# load config
|
||||
source $CONFIG_DIR/detector.cfg
|
||||
|
||||
# create cache dirs
|
||||
DET_DIR=$CCLONE_CACHE/detector
|
||||
DET_TAGS=$DET_DIR/tags
|
||||
DET_BRANCHES=$DET_DIR/branches
|
||||
[ -d $DET_TAGS ] || mkdir -p $DET_TAGS
|
||||
[ -d $DET_BRANCHES ] || mkdir -p $DET_BRANCHES
|
||||
}
|
||||
|
||||
|
||||
33
old/checker/detector-lib-general
Normal file
33
old/checker/detector-lib-general
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
function detectorTryInit(){
|
||||
# repo dir
|
||||
dir=$1
|
||||
history=$DET_DIR/detectorExecuted
|
||||
|
||||
if ! [ -f $history ]
|
||||
then
|
||||
echo "Initializing detector cache"
|
||||
# initialize seed
|
||||
git --git-dir $dir log --all --format="%H" > $history
|
||||
fi
|
||||
}
|
||||
|
||||
function detectorCheckCommit(){
|
||||
sha=$1
|
||||
history=$DET_DIR/detectorExecuted
|
||||
[ -f $history ] || touch $history
|
||||
|
||||
if grep -q $sha $history
|
||||
then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
function detectorSaveCommit(){
|
||||
sha=$1
|
||||
history=$DET_DIR/detectorExecuted
|
||||
echo $sha >> $history
|
||||
}
|
||||
51
old/checker/detector-lib-git
Normal file
51
old/checker/detector-lib-git
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
function detectorSum(){
|
||||
local dir=$1
|
||||
[ -f $dir/FETCH_HEAD ] || touch $dir/FETCH_HEAD
|
||||
# use md5sum - it is in busybox
|
||||
cat $dir/FETCH_HEAD | md5sum | cut -f1 -d' '
|
||||
}
|
||||
|
||||
function detectorSumPersist(){
|
||||
detectorSum $1 > $CCLONE_CACHE/detectorSum
|
||||
}
|
||||
|
||||
function detectorCheckFetchHead(){
|
||||
# check if repo fetch_head changed, if so, return 1
|
||||
local dir=$1
|
||||
|
||||
[ -f $CCLONE_CACHE/detectorSum ] || touch $CCLONE_CACHE/detectorSum
|
||||
|
||||
newSum=$(detectorSum $dir)
|
||||
oldSum=$(cat $CCLONE_CACHE/detectorSum)
|
||||
|
||||
if [ "x$oldSum" = "x$newSum" ]
|
||||
then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function gitListTags(){
|
||||
local dir=$1
|
||||
git --git-dir="$dir" tag -l | cat
|
||||
}
|
||||
|
||||
function gitListBranches(){
|
||||
local dir=$1
|
||||
git --git-dir="$dir" for-each-ref --format='%(refname:short)' refs/heads/
|
||||
}
|
||||
|
||||
|
||||
function gitPrefBranches(){
|
||||
local dir=$1
|
||||
gitListBranches $1 | grep master || true
|
||||
gitListBranches $1 | grep upstream || true
|
||||
gitListBranches $1 | sort | grep -vE 'master|upstream'
|
||||
}
|
||||
|
||||
|
||||
14
old/checker/notify-commit
Executable file
14
old/checker/notify-commit
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# notify on commit push
|
||||
#
|
||||
# Parameters (via env)
|
||||
#
|
||||
# COMMIT - hash of commit
|
||||
# COMMIT_AUTHOR - author of commit
|
||||
# COMMIT_ABBREV - abbreviated sha
|
||||
# COMMIT_LOG - short line of commit log
|
||||
# COMMIT_BRANCH - name of branch
|
||||
# PROJECT_NAME - project name specified in cloner.cfg
|
||||
echo "Commit: ($COMMIT: (AUTHOR=$COMMIT_AUTHOR; BRANCH=$COMMIT_BRANCH), Project: $PROJECT_NAME)"
|
||||
echo -e "\t$COMMIT_ABBREV: $COMMIT_LOG"
|
||||
|
||||
14
old/checker/notify-tag
Executable file
14
old/checker/notify-tag
Executable file
@@ -0,0 +1,14 @@
|
||||
#/bin/bash
|
||||
# notify on tag push (new tag or change)
|
||||
#
|
||||
# Parameters (via env)
|
||||
#
|
||||
# TAG_HASH - hash of tagged commit
|
||||
# TAG_NAME - tag label
|
||||
# TAG_AUTHOR - who authored the tag - if available
|
||||
# TAG_ABBREV - commit abbreviated hash
|
||||
# TAG_LOG - short status line of log
|
||||
# PROJECT_NAME - name of project specified in cloner.cfg
|
||||
echo "TAG: (Name=$TAG_NAME; AUTHOR=$TAG_AUTHOR; SHA: $TAG_HASH), PROJECT: $PROJECT_NAME"
|
||||
echo -e "\t$TAG_ABBREV: $TAG_LOG"
|
||||
|
||||
176
old/checker/run-checker
Executable file
176
old/checker/run-checker
Executable file
@@ -0,0 +1,176 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# source libs
|
||||
mydir=$(dirname $(realpath $0))
|
||||
source $mydir/cloner-lib-general
|
||||
source $mydir/cloner-lib-auth
|
||||
source $mydir/cloner-lib-cfg
|
||||
source $mydir/detector-lib-cfg
|
||||
|
||||
|
||||
# interval - in minutes
|
||||
interval=${cloner_interval:-0}
|
||||
stampfile=$CCLONE_CACHE/last-check-time
|
||||
|
||||
# does it exist - if not, sync
|
||||
[ -d $CCLONE_CACHE ] || mkdir $CCLONE_CACHE
|
||||
[ -f $stampfile ] || echo 0 > $stampfile
|
||||
|
||||
|
||||
now=$(date +"%s")
|
||||
last=$(cat $stampfile)
|
||||
diff=$(($now - $last))
|
||||
mindiff=$(($interval * 60))
|
||||
unset now last
|
||||
|
||||
if [ $diff -lt $mindiff ]
|
||||
then
|
||||
echo "Limit not reached - not syncing now"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# check and clone repo
|
||||
submodules=${cloner_submodules:-0}
|
||||
depth=${cloner_submodule_depth:-}
|
||||
|
||||
export HOME=$CCLONE_CACHE
|
||||
|
||||
prepareGitAuth $CONFIG_DIR
|
||||
|
||||
# without submodule support
|
||||
if [ ! "x$submodules" = "x1" ]
|
||||
then
|
||||
mirror-main-repo $repo
|
||||
else
|
||||
mirror-recursive $repo $depth
|
||||
fi
|
||||
|
||||
date +"%s" > $stampfile
|
||||
|
||||
# if detector is not enabled, quit quietly
|
||||
if ! detectorRunCapable
|
||||
then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
source $mydir/detector-lib-git
|
||||
source $mydir/detector-lib-general
|
||||
|
||||
detectorLoadConfig
|
||||
|
||||
repodir=$(gen-mirror-path $repo)
|
||||
|
||||
if detectorCheckFetchHead $repodir
|
||||
then
|
||||
# nothing changed, just die
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# try to init cache
|
||||
detectorTryInit $repodir
|
||||
|
||||
# first, solve commits
|
||||
# branches that were deleted or merged
|
||||
find $DET_BRANCHES -type f | sort | while read branchpath
|
||||
do
|
||||
branch=$(basename $branchpath)
|
||||
if ! gitListBranches $repodir | grep -q "^$branch$"
|
||||
then
|
||||
echo "Unexistent branch <$branch>!!"
|
||||
# rm it, should be merget etc...
|
||||
rm $DET_BRANCHES/$branch
|
||||
fi
|
||||
done
|
||||
|
||||
# new branches or new commits in curent branches
|
||||
# firstly list master branch, to make first commits in it
|
||||
gitPrefBranches $repodir | while read branch
|
||||
do
|
||||
[ -f $DET_BRANCHES/$branch ] || touch $DET_BRANCHES/$branch
|
||||
oldsha=$(cat $DET_BRANCHES/$branch)
|
||||
newsha=$(git --git-dir $repodir show-ref --heads $branch | cut -d' ' -f1)
|
||||
[ -z "$oldsha" ] || oldsha=$oldsha..
|
||||
# walk through every commit in branch (since last change)
|
||||
for commitId in $(git --no-pager --git-dir $repodir log --reverse --format="%H" $oldsha$branch)
|
||||
do
|
||||
if detectorCheckCommit $commitId
|
||||
then
|
||||
# commit was not processed - start
|
||||
# COMMIT = $commitId
|
||||
# COMMIT_AUTHOR = $author
|
||||
author=$(git --git-dir $repodir log $commitId -1 --format="%an <%ae>")
|
||||
# COMMIT_ABBREV
|
||||
abbr=$(git --git-dir $repodir log $commitId -1 --format="%h")
|
||||
# COMMIT_LOG
|
||||
log=$(git --git-dir $repodir log $commitId -1 --format="%s")
|
||||
# BRANCH = $branch
|
||||
# PORJECT_NAME = $cloner_project_name
|
||||
|
||||
set +e
|
||||
COMMIT="$commitId" \
|
||||
COMMIT_AUTHOR="$author" \
|
||||
COMMIT_BRANCH="$branch" \
|
||||
COMMIT_ABBREV="$abbr" \
|
||||
COMMIT_LOG="$log" \
|
||||
PROJECT_NAME="$cloner_project_name" \
|
||||
notify-commit
|
||||
rc=$?
|
||||
[ $rc -eq 0 ] || echo "Notify $branch/$commitId: return code = $rc"
|
||||
set -e
|
||||
detectorSaveCommit $commitId
|
||||
fi
|
||||
|
||||
done
|
||||
echo $newsha > $DET_BRANCHES/$branch
|
||||
done
|
||||
|
||||
|
||||
# solve tags - remove nonexistent refs
|
||||
find $DET_TAGS -type f | sort | while read tagname
|
||||
do
|
||||
tag=$(basename $tagname)
|
||||
if ! git --git-dir="$repodir" rev-parse "tags/$tag" > /dev/null 2>&1
|
||||
then
|
||||
echo "Removing tag: $tag (was [$(cat $tagname)])"
|
||||
rm $tagname
|
||||
fi
|
||||
done
|
||||
|
||||
# tags that changed or were pushed as new
|
||||
gitListTags $repodir | while read tagname
|
||||
do
|
||||
[ -f $DET_TAGS/$tagname ] || touch $DET_TAGS/$tagname
|
||||
oldsha=$(cat $DET_TAGS/$tagname)
|
||||
newsha=$(git --git-dir $repodir show-ref --tags $tagname | cut -d' ' -f1)
|
||||
if ! [ "x$oldsha" = "x$newsha" ]
|
||||
then
|
||||
# TAG_HASH = $newsha
|
||||
# TAG_NAME = $tagname
|
||||
# TAG_AUTHOR
|
||||
author=$(git --git-dir $repodir log $newsha -1 --pretty=format:"%an <%ae>")
|
||||
# TAG_ABBREV
|
||||
abbr=$(git --git-dir $repodir log $newsha -1 --format="%h")
|
||||
# TAG_LOG
|
||||
log=$(git --git-dir $repodir log $newsha -1 --format="%s")
|
||||
# PROJECT_NAME = $cloner_project_name
|
||||
|
||||
# call the notify script
|
||||
set +e
|
||||
TAG_HASH="$newsha" \
|
||||
TAG_NAME="$tagname" \
|
||||
TAG_AUTHOR="$author" \
|
||||
TAG_ABBREV="$abbr" \
|
||||
TAG_LOG="$log" \
|
||||
PROJECT_NAME="$cloner_project_name" notify-tag
|
||||
rc=$?
|
||||
[ $rc -eq 0 ] || echo "Notify $tagname: return code = $rc"
|
||||
set -e
|
||||
fi
|
||||
echo $newsha > $DET_TAGS/$tagname
|
||||
done
|
||||
|
||||
# save hash to keep things clear
|
||||
detectorSumPersist $repodir
|
||||
|
||||
Reference in New Issue
Block a user