mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
auto update of scripts/bootstrapit_update.sh
This commit is contained in:
parent
f36c4e3fa8
commit
cbe62c371e
1 changed files with 125 additions and 89 deletions
|
|
@ -3,15 +3,15 @@
|
|||
set -Ee -o pipefail;
|
||||
shopt -s extglob nocasematch;
|
||||
|
||||
if [[ -f ${PROJECT_DIR}/.git/config ]]; then
|
||||
OLD_PWD=${PWD}
|
||||
cd ${PROJECT_DIR};
|
||||
if [[ $( git diff -s --exit-code || echo $? ) -gt 0 ]]; then
|
||||
if [[ -f "$PROJECT_DIR/.git/config" ]]; then
|
||||
OLD_PWD="$PWD"
|
||||
cd "$PROJECT_DIR";
|
||||
if [[ $( git diff -s --exit-code || echo "$?" ) -gt 0 ]]; then
|
||||
echo "ABORTING!: Your repo has local changes which are not comitted."
|
||||
echo "To avoid overwriting these changes, please commit your changes."
|
||||
exit 1;
|
||||
fi
|
||||
cd $OLD_PWD;
|
||||
cd "$OLD_PWD";
|
||||
fi
|
||||
|
||||
BOOTSTRAPIT_GIT_URL="https://gitlab.com/mbarkhau/bootstrapit.git/"
|
||||
|
|
@ -20,26 +20,27 @@ BOOTSTRAPIT_GIT_PATH=/tmp/bootstrapit;
|
|||
|
||||
echo "Updating from $BOOTSTRAPIT_GIT_URL";
|
||||
|
||||
if [[ ! -e $BOOTSTRAPIT_GIT_PATH ]]; then
|
||||
git clone ${BOOTSTRAPIT_GIT_URL} ${BOOTSTRAPIT_GIT_PATH};
|
||||
if [[ ! -e "$BOOTSTRAPIT_GIT_PATH" ]]; then
|
||||
git clone "$BOOTSTRAPIT_GIT_URL" "$BOOTSTRAPIT_GIT_PATH";
|
||||
else
|
||||
OLD_PWD=${PWD};
|
||||
cd ${BOOTSTRAPIT_GIT_PATH};
|
||||
OLD_PWD="$PWD";
|
||||
cd "$BOOTSTRAPIT_GIT_PATH";
|
||||
git pull --quiet;
|
||||
cd $OLD_PWD;
|
||||
cd "$OLD_PWD";
|
||||
fi
|
||||
|
||||
md5sum=$(which md5sum || which md5)
|
||||
|
||||
old_md5=$( cat $PROJECT_DIR/scripts/bootstrapit_update.sh | $md5sum );
|
||||
new_md5=$( cat $BOOTSTRAPIT_GIT_PATH/scripts/bootstrapit_update.sh | $md5sum );
|
||||
old_md5=$( cat "$PROJECT_DIR/scripts/bootstrapit_update.sh" | $md5sum );
|
||||
new_md5=$( cat "$BOOTSTRAPIT_GIT_PATH/scripts/bootstrapit_update.sh" | $md5sum );
|
||||
|
||||
if [[ $old_md5 != $new_md5 ]]; then
|
||||
if [[ "$old_md5" != "$new_md5" ]]; then
|
||||
# Copy the updated file, run it and exit the current execution.
|
||||
cp "${BOOTSTRAPIT_GIT_PATH}/scripts/bootstrapit_update.sh" \
|
||||
"${PROJECT_DIR}/scripts/";
|
||||
git add "${PROJECT_DIR}/scripts/bootstrapit_update.sh";
|
||||
git commit --no-verify -m "auto update of scripts/bootstrapit_update.sh"
|
||||
# shellcheck source=scripts/bootstrapit_update.sh
|
||||
source "${PROJECT_DIR}/scripts/bootstrapit_update.sh";
|
||||
exit 0;
|
||||
fi
|
||||
|
|
@ -58,7 +59,7 @@ declare -a required_config_param_names=(
|
|||
"LICENSE_ID"
|
||||
)
|
||||
|
||||
for name in "${required_config_param_names}"; do
|
||||
for name in "${required_config_param_names[@]}"; do
|
||||
if [[ -z ${!name} ]]; then
|
||||
echo "Missing parameter $name in $1";
|
||||
exit 1;
|
||||
|
|
@ -74,7 +75,7 @@ if [[ -z $DEFAULT_PYTHON_VERSION ]]; then
|
|||
fi
|
||||
|
||||
if [[ -z $SPDX_LICENSE_ID ]]; then
|
||||
if [[ $LICENSE_ID =~ "none" ]]; then
|
||||
if [[ $LICENSE_ID =~ none ]]; then
|
||||
SPDX_LICENSE_ID="Proprietary";
|
||||
else
|
||||
SPDX_LICENSE_ID=$LICENSE_ID;
|
||||
|
|
@ -90,27 +91,27 @@ LICENSE_TXT_FILE="/tmp/bootstrapit_$LICENSE_ID.txt"
|
|||
LICENSE_XML_FILE="/tmp/bootstrapit_$LICENSE_ID.xml"
|
||||
|
||||
|
||||
if ! [[ $LICENSE_ID =~ "none" ]]; then
|
||||
if ! [[ -f $LICENSE_TXT_FILE ]]; then
|
||||
if ! [[ $LICENSE_ID =~ none ]]; then
|
||||
if ! [[ -f "$LICENSE_TXT_FILE" ]]; then
|
||||
echo "Downloading license text from $LICENSE_TXT_URL"
|
||||
curl -L --silent $LICENSE_TXT_URL > $LICENSE_TXT_FILE.tmp;
|
||||
mv $LICENSE_TXT_FILE.tmp $LICENSE_TXT_FILE;
|
||||
curl -L --silent "$LICENSE_TXT_URL" > "$LICENSE_TXT_FILE.tmp";
|
||||
mv "$LICENSE_TXT_FILE.tmp" "$LICENSE_TXT_FILE";
|
||||
fi
|
||||
if ! [[ -f $LICENSE_XML_FILE ]]; then
|
||||
if ! [[ -f "$LICENSE_XML_FILE" ]]; then
|
||||
echo "Downloading license info from $LICENSE_XML_URL"
|
||||
curl -L --silent $LICENSE_XML_URL > $LICENSE_XML_FILE.tmp;
|
||||
mv $LICENSE_XML_FILE.tmp $LICENSE_XML_FILE;
|
||||
curl -L --silent "$LICENSE_XML_URL" > "$LICENSE_XML_FILE.tmp";
|
||||
mv "$LICENSE_XML_FILE.tmp" "$LICENSE_XML_FILE";
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [[ -z $LICENSE_NAME ]]; then
|
||||
if [[ $LICENSE_ID =~ "none" ]]; then
|
||||
if [[ $LICENSE_ID =~ none ]]; then
|
||||
LICENSE_NAME="All Rights Reserved";
|
||||
else
|
||||
LICENSE_NAME=$(
|
||||
awk '{ if ($0 ~ /[^>]\s*$/ ) { printf "%s", $0 } else {printf "%s\n", $0 } }' \
|
||||
$LICENSE_XML_FILE \
|
||||
"$LICENSE_XML_FILE" \
|
||||
| grep "<license" \
|
||||
| sed -E 's/.*name="([A-Za-z0-9[:punct:][:space:]]+)".*/\1/g' \
|
||||
| sed 's/"/"/g' \
|
||||
|
|
@ -121,25 +122,25 @@ fi
|
|||
|
||||
|
||||
if [[ -z $LICENSE_CLASSIFIER ]]; then
|
||||
if [[ $LICENSE_ID = "none" ]]; then
|
||||
if [[ $LICENSE_ID =~ none ]]; then
|
||||
LICENSE_CLASSIFIER="License :: Other/Proprietary License";
|
||||
elif [[ $LICENSE_ID =~ "mit" ]]; then
|
||||
elif [[ $LICENSE_ID =~ mit ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: MIT License";
|
||||
elif [[ $LICENSE_ID =~ "bsd" ]]; then
|
||||
elif [[ $LICENSE_ID =~ bsd ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: BSD License";
|
||||
elif [[ $LICENSE_ID =~ "gpl-2.0-only" ]]; then
|
||||
elif [[ $LICENSE_ID =~ gpl-2.0-only ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: GNU General Public License v2 (GPLv2)";
|
||||
elif [[ $LICENSE_ID =~ "lgpl-2.0-only" ]]; then
|
||||
elif [[ $LICENSE_ID =~ lgpl-2.0-only ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)";
|
||||
elif [[ $LICENSE_ID =~ "gpl-3.0-only" ]]; then
|
||||
elif [[ $LICENSE_ID =~ gpl-3.0-only ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: GNU General Public License v3 (GPLv3)";
|
||||
elif [[ $LICENSE_ID =~ "agpl-3.0-only" ]]; then
|
||||
elif [[ $LICENSE_ID =~ agpl-3.0-only ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: GNU Affero General Public License v3";
|
||||
elif [[ $LICENSE_ID =~ "lgpl-3.0-only" ]]; then
|
||||
elif [[ $LICENSE_ID =~ lgpl-3.0-only ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)";
|
||||
elif [[ $LICENSE_ID =~ "mpl-2.0" ]]; then
|
||||
elif [[ $LICENSE_ID =~ mpl-2.0 ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)";
|
||||
elif [[ $LICENSE_ID =~ "apache-2.0" ]]; then
|
||||
elif [[ $LICENSE_ID =~ apache-2.0 ]]; then
|
||||
LICENSE_CLASSIFIER="License :: OSI Approved :: Apache Software License";
|
||||
else
|
||||
echo "Invalid LICENSE_ID=\"$LICENSE_ID\". Could not determine LICENSE_CLASSIFIER.";
|
||||
|
|
@ -147,68 +148,77 @@ if [[ -z $LICENSE_CLASSIFIER ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $COPYRIGHT_STRING ]]; then
|
||||
if [[ -z "$COPYRIGHT_STRING" ]]; then
|
||||
COPYRIGHT_STRING="Copyright (c) ${YEAR} ${AUTHOR_NAME} (${AUTHOR_CONTACT}) - ${LICENSE_NAME}";
|
||||
fi
|
||||
|
||||
if [[ -z $IS_PUBLIC ]]; then
|
||||
IS_PUBLIC=$( echo $GIT_REPO_DOMAIN | grep -c -E '(gitlab\.com|github\.com|bitbucket\.org)' || true );
|
||||
fi
|
||||
|
||||
if [[ -z $PAGES_DOMAIN ]]; then
|
||||
if [[ $GIT_REPO_DOMAIN == "gitlab.com" ]]; then
|
||||
PAGES_DOMAIN=gitlab.io;
|
||||
elif [[ $GIT_REPO_DOMAIN == "github.com" ]]; then
|
||||
PAGES_DOMAIN=github.io;
|
||||
elif [[ $GIT_REPO_DOMAIN == "bitbucket.org" ]]; then
|
||||
PAGES_DOMAIN=bitbucket.io;
|
||||
if [[ -z "$SETUP_PY_LICENSE" ]]; then
|
||||
if [[ $LICENSE_ID =~ none ]]; then
|
||||
SETUP_PY_LICENSE="$COPYRIGHT_STRING";
|
||||
else
|
||||
PAGES_DOMAIN=gitlab-pages.$GIT_REPO_DOMAIN;
|
||||
SETUP_PY_LICENSE=$SPDX_LICENSE_ID;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $DOCKER_REGISTRY_DOMAIN ]]; then
|
||||
if [[ $GIT_REPO_DOMAIN == "gitlab.com" ]]; then
|
||||
|
||||
if [[ -z "$IS_PUBLIC" ]]; then
|
||||
IS_PUBLIC=$( echo "$GIT_REPO_DOMAIN" | grep -c -E '(gitlab\.com|github\.com|bitbucket\.org)' || true );
|
||||
fi
|
||||
|
||||
if [[ -z "$PAGES_DOMAIN" ]]; then
|
||||
if [[ "$GIT_REPO_DOMAIN" == "gitlab.com" ]]; then
|
||||
PAGES_DOMAIN=gitlab.io;
|
||||
elif [[ "$GIT_REPO_DOMAIN" == "github.com" ]]; then
|
||||
PAGES_DOMAIN=github.io;
|
||||
elif [[ "$GIT_REPO_DOMAIN" == "bitbucket.org" ]]; then
|
||||
PAGES_DOMAIN=bitbucket.io;
|
||||
else
|
||||
PAGES_DOMAIN="gitlab-pages.$GIT_REPO_DOMAIN";
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$PAGES_URL" ]]; then
|
||||
PAGES_URL="https://${GIT_REPO_NAMESPACE}.${PAGES_DOMAIN}/${PACKAGE_NAME}/"
|
||||
fi
|
||||
|
||||
if [[ -z "$DOCKER_REGISTRY_DOMAIN" ]]; then
|
||||
if [[ "$GIT_REPO_DOMAIN" == "gitlab.com" ]]; then
|
||||
DOCKER_REGISTRY_DOMAIN=registry.gitlab.com;
|
||||
else
|
||||
DOCKER_REGISTRY_DOMAIN=hub.docker.com;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z $PAGES_URL ]]; then
|
||||
PAGES_URL="https://${GIT_REPO_NAMESPACE}.${PAGES_DOMAIN}/${PACKAGE_NAME}/"
|
||||
if [[ -z "$DOCKER_BASE_IMAGE" ]]; then
|
||||
DOCKER_BASE_IMAGE=frolvlad/alpine-glibc
|
||||
fi
|
||||
|
||||
if [[ -z $GIT_REPO_URL ]]; then
|
||||
if [[ -z "$MODULE_NAME" ]]; then
|
||||
MODULE_NAME=$( echo "${PACKAGE_NAME}" | tr '[:upper:]' '[:lower:]' | sed -E -e 's;-;_;g'; );
|
||||
fi
|
||||
|
||||
if [[ -z "$GIT_REPO_URL" ]]; then
|
||||
GIT_REPO_URL=https://${GIT_REPO_DOMAIN}/${GIT_REPO_NAMESPACE}/${PACKAGE_NAME}
|
||||
elif [[ ! ${GIT_REPO_URL} =~ ^https?://[^/]+/[^/]+/[^/]+(/|.git)?$ ]]; then
|
||||
elif [[ ! "$GIT_REPO_URL" =~ ^https?://[^/]+/[^/]+/[^/]+(/|.git)?$ ]]; then
|
||||
echo "ERROR: Invalid argument for '${GIT_REPO_URL}'";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ -z $DOCKER_BASE_IMAGE ]]; then
|
||||
DOCKER_BASE_IMAGE=frolvlad/alpine-glibc
|
||||
fi
|
||||
GIT_REPO_PATH=$( echo "$GIT_REPO_URL" | sed -E -e 's;https?://[^/]+/;;g' | sed -E 's;(/|.git)$;;g' )
|
||||
GIT_REPO_NAME=$( echo "$GIT_REPO_PATH" | sed -E -e 's;^[A-Za-z_-]+/;;g' )
|
||||
|
||||
if [[ -z ${MODULE_NAME} ]]; then
|
||||
MODULE_NAME=$( echo "${PACKAGE_NAME}" | tr '[:upper:]' '[:lower:]' | sed -E -e 's;-;_;g'; );
|
||||
fi
|
||||
|
||||
GIT_REPO_PATH=$( echo "${GIT_REPO_URL}" | sed -E -e 's;https?://[^/]+/;;g' | sed -E 's;(/|.git)$;;g' )
|
||||
GIT_REPO_NAME=$( echo "${GIT_REPO_PATH}" | sed -E -e 's;^[A-Za-z_-]+/;;g' )
|
||||
|
||||
if [[ $LICENSE_ID =~ "none" ]]; then
|
||||
echo $COPYRIGHT_STRING > $PROJECT_DIR/LICENSE;
|
||||
if [[ "$LICENSE_ID" =~ "none" ]]; then
|
||||
echo "$COPYRIGHT_STRING" > "$PROJECT_DIR/LICENSE";
|
||||
else
|
||||
cat $LICENSE_TXT_FILE \
|
||||
cat "$LICENSE_TXT_FILE" \
|
||||
| sed "s/Copyright (c) <year> <owner>[[:space:]]*/Copyright (c) $YEAR $AUTHOR_NAME ($AUTHOR_CONTACT)/g" \
|
||||
| sed "s/Copyright (c) <year> <copyright holders>[[:space:]]*/Copyright (c) $YEAR $AUTHOR_NAME ($AUTHOR_CONTACT)/g" \
|
||||
> $PROJECT_DIR/LICENSE;
|
||||
> "$PROJECT_DIR/LICENSE";
|
||||
fi
|
||||
|
||||
function format_template()
|
||||
{
|
||||
cat $1 \
|
||||
cat "$1" \
|
||||
| sed "s;\${GIT_REPO_URL};${GIT_REPO_URL};g" \
|
||||
| sed "s;\${GIT_REPO_PATH};${GIT_REPO_PATH};g" \
|
||||
| sed "s;\${GIT_REPO_NAMESPACE};${GIT_REPO_NAMESPACE};g" \
|
||||
|
|
@ -225,24 +235,50 @@ function format_template()
|
|||
| sed "s;\${DESCRIPTION};${DESCRIPTION};g" \
|
||||
| sed "s;\${KEYWORDS};${KEYWORDS};g" \
|
||||
| sed "s;\${SPDX_LICENSE_ID};${SPDX_LICENSE_ID};g" \
|
||||
| sed "s;\${SETUP_PY_LICENSE};${SETUP_PY_LICENSE};g" \
|
||||
| sed "s;\${LICENSE_CLASSIFIER};${LICENSE_CLASSIFIER};g" \
|
||||
| sed "s;\${COPYRIGHT_STRING};${COPYRIGHT_STRING};g" \
|
||||
| sed "s;\${YEAR};${YEAR};g" \
|
||||
| sed "s;\${MONTH};${MONTH};g" \
|
||||
> $1.tmp;
|
||||
mv $1.tmp $1;
|
||||
> "$1.tmp";
|
||||
mv "$1.tmp" "$1";
|
||||
}
|
||||
|
||||
if [[ -z "${IGNORE_IF_EXISTS[*]}" ]]; then
|
||||
declare -a IGNORE_IF_EXISTS=(
|
||||
"CHANGELOG.md"
|
||||
"README.md"
|
||||
"setup.py"
|
||||
"makefile.config.make"
|
||||
"requirements/pypi.txt"
|
||||
"requirements/development.txt"
|
||||
"requirements/conda.txt"
|
||||
"requirements/vendor.txt"
|
||||
"src/${MODULE_NAME}/__init__.py"
|
||||
"src/${MODULE_NAME}/__main__.py"
|
||||
)
|
||||
fi
|
||||
|
||||
function copy_template()
|
||||
{
|
||||
if [[ -z ${2} ]]; then
|
||||
dest_path=${PROJECT_DIR}/$1;
|
||||
dest_subpath=$1;
|
||||
else
|
||||
dest_path=${PROJECT_DIR}/$2;
|
||||
fi;
|
||||
cat ${BOOTSTRAPIT_GIT_PATH}/$1.template > ${dest_path};
|
||||
dest_subpath=$2;
|
||||
fi
|
||||
|
||||
format_template ${dest_path};
|
||||
dest_path=${PROJECT_DIR}/$dest_subpath;
|
||||
if [[ -f "$dest_subpath" ]]; then
|
||||
for ignore_item in "${IGNORE_IF_EXISTS[@]}"; do
|
||||
if [[ "$dest_subpath" == "$ignore_item" ]]; then
|
||||
return 0;
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
cat "${BOOTSTRAPIT_GIT_PATH}/$1.template" > "$dest_path";
|
||||
|
||||
format_template "$dest_path";
|
||||
}
|
||||
|
||||
mkdir -p "${PROJECT_DIR}/test/";
|
||||
|
|
@ -288,32 +324,32 @@ chmod +x "${PROJECT_DIR}/scripts/update_conda_env_deps.sh";
|
|||
chmod +x "${PROJECT_DIR}/scripts/setup_conda_envs.sh";
|
||||
chmod +x "${PROJECT_DIR}/scripts/pre-push-hook.sh";
|
||||
|
||||
head -n 7 ${PROJECT_DIR}/license.header \
|
||||
head -n 7 "${PROJECT_DIR}/license.header" \
|
||||
| tail -n +3 \
|
||||
| sed -re 's/(^ |^$)/#/g' \
|
||||
> .py_license.header;
|
||||
> /tmp/.py_license.header;
|
||||
|
||||
src_files=${PROJECT_DIR}/src/**/*.py
|
||||
src_files="${PROJECT_DIR}/src/*/*.py"
|
||||
|
||||
for src_file in $src_files; do
|
||||
if grep -q -E '^# SPDX-License-Identifier' $src_file; then
|
||||
if grep -q -E '^# SPDX-License-Identifier' "$src_file"; then
|
||||
continue;
|
||||
fi
|
||||
offset=0
|
||||
if grep -z -q -E '^#![/a-z ]+?python' $src_file; then
|
||||
if grep -z -q -E '^#![/a-z ]+?python' "$src_file"; then
|
||||
let offset+=1;
|
||||
fi
|
||||
if grep -q -E '^# .+?coding: [a-zA-Z0-9_\-]+' $src_file; then
|
||||
if grep -q -E '^# .+?coding: [a-zA-Z0-9_\-]+' "$src_file"; then
|
||||
let offset+=1;
|
||||
fi
|
||||
rm -f ${src_file}.with_header;
|
||||
rm -f "${src_file}.with_header";
|
||||
if [[ $offset -gt 0 ]]; then
|
||||
head -n $offset ${src_file} > ${src_file}.with_header;
|
||||
head -n $offset "${src_file}" > "${src_file}.with_header";
|
||||
fi
|
||||
let offset+=1;
|
||||
cat .py_license.header >> ${src_file}.with_header;
|
||||
tail -n +$offset ${src_file} >> ${src_file}.with_header;
|
||||
mv ${src_file}.with_header $src_file;
|
||||
cat /tmp/.py_license.header >> "${src_file}.with_header";
|
||||
tail -n +$offset "${src_file}" >> "${src_file}.with_header";
|
||||
mv "${src_file}.with_header" "$src_file";
|
||||
done
|
||||
|
||||
rm .py_license.header
|
||||
rm /tmp/.py_license.header
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue