Paste: github-sync.cgi
Author: | erg |
Mode: | shellscript |
Date: | Sun, 17 Nov 2019 00:20:16 |
Plain Text |
set -e
resolve_symlinks() {
local dir_context path
path=$(readlink -- "$1")
if [ $? -eq 0 ]; then
dir_context=$(dirname -- "$1")
resolve_symlinks "$(_prepend_path_if_relative "$dir_context" "$path")"
else
printf '%s\n' "$1"
fi
}
_prepend_path_if_relative() {
case "$2" in
/* ) printf '%s\n' "$2" ;;
* ) printf '%s\n' "$1/$2" ;;
esac
}
canonicalize_path() {
if [ -d "$1" ]; then
_canonicalize_dir_path "$1"
else
_canonicalize_file_path "$1"
fi
}
_canonicalize_dir_path() {
(cd "$1" 2>/dev/null && pwd -P)
}
_canonicalize_file_path() {
local dir file
dir=$(dirname -- "$1")
file=$(basename -- "$1")
(cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
}
realpath() {
canonicalize_path "$(resolve_symlinks "$1")"
}
DIR="$(dirname $(realpath $0))"
log="${DIR}/github-sync.log"
date=$(date)
echo -n "${date}" >> "${log}"
on_fail() {
popd
echo ' -- failed' >> "${log}"
echo 'Content-type: text/plain'
echo ''
echo 'fail'
exit 1
}
trap 'on_fail "$_"' ERR
pushd /git/factor-github.git
git --bare fetch origin '*:*'
popd
echo ' -- ok' >> "${log}"
echo 'Content-type: text/plain'
echo ''
echo 'success'
New Annotation