python_skeleton/deploy_new_python_project.sh

99 lines
2.8 KiB
Bash
Raw Normal View History

2021-01-13 09:46:46 +01:00
#!/bin/bash
function usage() {
echo "$(basename "${0}" .sh) [--help|-h|-?] [--author|-a 'Author name'] [--authoring-date|-d 'date of creation'] [--project-name|-n 'Name of the project'] [--project-codename|-p short_project_name] [--version|-v 'version number'] [--deployment-path|-r 'path/to/copy/skeleton'] [--author-email|-e 'email@example.org'] [--url|-u 'https://domain.com'] [--license|-l 'LICENSEv1']"
echo ""
echo " --help Show this help."
echo " --author Author name, between quotes for spaces."
echo " --authoring-date Date when the script was created."
echo " --project-name Long name of the project."
echo " --project-codename Short name without spaces for command line script."
echo " --version Initial version 0.0.1?"
echo " --deployment-path Path to deploy the skeleton."
echo " --author-email Email address of the author."
echo " --url URL of the project."
echo " --license License name."
if [ -e "$(dirname "${0}")/defaults" ]
then
echo "Defaults:"
cat "$(dirname "${0}")/defaults"
fi
}
2021-01-13 16:10:29 +01:00
# shellcheck disable=SC1090
if [ -e "$(dirname "${0}")/defaults" ]
2021-01-13 16:10:29 +01:00
then
. "$(dirname "${0}")/defaults"
fi
2021-01-13 09:46:46 +01:00
while [ $# -gt 0 ]
do
case "$1" in
"--help"|"-h"|"-?")
usage
exit 0
;;
"--author"|"-a")
2021-01-13 09:46:46 +01:00
shift
2021-01-13 16:17:31 +01:00
AUTHOR="${1}"
2021-01-13 09:46:46 +01:00
shift
;;
"--authoring-date"|"-d")
2021-01-13 09:46:46 +01:00
shift
2021-01-13 16:17:31 +01:00
AUTHORING_DATE="${1}"
2021-01-13 09:46:46 +01:00
shift
;;
"--project-name"|"-n")
2021-01-13 09:46:46 +01:00
shift
2021-01-13 16:17:31 +01:00
PROJECT_NAME="${1}"
2021-01-13 09:46:46 +01:00
;;
"--project-codename"|"-p")
2021-01-13 09:46:46 +01:00
shift
2021-01-13 16:17:31 +01:00
PROJECT_CODENAME="${1}"
2021-01-13 09:46:46 +01:00
shift
;;
"--version"|"-v")
2021-01-13 09:46:46 +01:00
shift
2021-01-13 16:17:31 +01:00
VERSION="${1}"
2021-01-13 09:46:46 +01:00
shift
;;
"--deployment-path"|"-r")
2021-01-13 09:46:46 +01:00
shift
2021-01-13 16:17:31 +01:00
DEPLOYMENT_PATH="${1}"
2021-01-13 09:46:46 +01:00
shift
;;
"--author-email"|"-e")
shift
AUTHOR_EMAIL="${1}"
shift
;;
"--url"|"-u")
shift
URL="${1}"
shift
;;
"--license"|"-l")
shift
LICENSE="${1}"
shift
;;
2021-01-13 09:46:46 +01:00
*)
echo "Ignoring unknwon parameter '${1}'"
shift
;;
esac
2021-01-13 16:10:29 +01:00
done
2021-01-13 16:17:31 +01:00
destination_path="${DEPLOYMENT_PATH}/${PROJECT_CODENAME}"
2021-01-13 16:10:29 +01:00
mkdir "${destination_path}"
script_path=$(dirname "${0}")
cp "${script_path}/skeleton" "${destination_path}" -rfp
2021-01-13 16:17:31 +01:00
mv "${destination_path}/project_codename.py" "${destination_path}/${PROJECT_CODENAME}.py"
2021-01-13 16:10:29 +01:00
while read -r file
do
2021-01-13 16:17:31 +01:00
sed -i "s/__project_codename__/${PROJECT_CODENAME}/g" "${file}"
sed -i "s/__author__/${AUTHOR}/g" "${file}"
sed -i "s/__author_email__/${AUTHOR_EMAIL}/g" "${file}"
2021-01-13 16:17:31 +01:00
sed -i "s/__authoring_date__/${AUTHORING_DATE}/g" "${file}"
sed -i "s/__project_name__/${PROJECT_NAME}/g" "${file}"
sed -i "s/__version__/${VERSION}/g" "${file}"
sed -i "s/__url__/${URL}/g" "${file}"
sed -i "s/__license__/${LICENSE}/g" "${file}"
2021-01-13 16:10:29 +01:00
done <<< "$(ls "${destination_path}/")"