python_skeleton/deploy_new_python_project.sh

144 lines
4.4 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."
2022-06-14 08:42:54 +02:00
echo " --license-url License URL to fetch in plain text and save in your project folder."
echo " --description Description."
if [ -e "$(dirname "${0}")/defaults" ]
then
echo "Defaults:"
cat "$(dirname "${0}")/defaults"
fi
2022-06-14 08:42:54 +02:00
echo ""
}
2024-01-29 17:46:33 +01:00
AUTHOR_EMAIL="${USER}@$(hostname -f)"
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
2022-06-14 08:52:01 +02:00
source "$(dirname "${0}")/defaults"
2021-01-13 16:10:29 +01:00
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-20 17:53:02 +01:00
shift
2021-01-13 09:46:46 +01:00
;;
"--project-codename"|"-p")
2021-01-13 09:46:46 +01:00
shift
2024-01-19 14:12:08 +01:00
PROJECT_CODENAME="${1//-/_}"
2024-01-19 14:35:01 +01:00
PROJECT_CODENAME_CAMEL=$(echo "${PROJECT_CODENAME}" | sed -E 's/_([a-z])/\U\1/g' | sed -E 's/^([a-z])/\U\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
;;
2022-06-14 08:42:54 +02:00
"--license-url"|"-U")
shift
2022-06-14 08:52:01 +02:00
LICENSE_URL="${1}"
2022-06-14 08:42:54 +02:00
shift
;;
"--description")
shift
DESCRIPTION="${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
2022-08-08 20:55:47 +02:00
if [ -z "${DESCRIPTION}" ]; then
2022-06-14 08:42:54 +02:00
DESCRIPTION=${PROJECT_NAME}
fi
2021-01-13 16:10:29 +01:00
2021-01-13 16:17:31 +01:00
destination_path="${DEPLOYMENT_PATH}/${PROJECT_CODENAME}"
2021-01-20 17:53:02 +01:00
mkdir -p "${DEPLOYMENT_PATH}"
2021-01-13 16:10:29 +01:00
script_path=$(dirname "${0}")
cp "${script_path}/skeleton" "${destination_path}" -rfp
2022-06-14 08:52:01 +02:00
if [ -z "${LICENSE_URL}" ]; then
2022-06-14 08:42:54 +02:00
case "${license}" in
"GPLv3")
2022-06-14 08:52:01 +02:00
LICENSE_URL="https://www.gnu.org/licenses/gpl-3.0.txt"
2022-06-14 08:42:54 +02:00
;;
"GPLv2")
2022-06-14 08:52:01 +02:00
LICENSE_URL="https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt"
2022-06-14 08:42:54 +02:00
;;
"GPLv1"|"GPL")
licence_url="https://www.gnu.org/licenses/old-licenses/gpl-1.0.txt"
;;
*)
echo "Warning! Put the license text in the file ${destination_path}/LICENSE or pass the URL with the --license-url option"
;;
esac
fi
if [ -n "${licence_url}" ]; then
2022-06-14 08:52:01 +02:00
curl -s "${LICENSE_URL}" > "${destination_path}/LICENSE"
2022-06-14 08:42:54 +02:00
fi
mv "${destination_path}/project_codename" "${destination_path}/${PROJECT_CODENAME}"
mv "${destination_path}/${PROJECT_CODENAME}/project_codename.py" "${destination_path}/${PROJECT_CODENAME}/${PROJECT_CODENAME}.py"
2024-10-03 12:24:24 +02:00
mv "${destination_path}/${PROJECT_CODENAME}/project_codename.sh" "${destination_path}/${PROJECT_CODENAME}/${PROJECT_CODENAME}.sh"
2021-01-13 16:10:29 +01:00
while read -r file
do
2021-01-20 17:53:02 +01:00
sed -i "s/__project_codename__/${PROJECT_CODENAME}/g" "${file}"
2024-01-19 14:17:10 +01:00
sed -i "s/__project_codename_camel__/${PROJECT_CODENAME_CAMEL}/g" "${file}"
2021-01-20 17:53:02 +01:00
sed -i "s/__author__/${AUTHOR}/g" "${file}"
sed -i "s/__author_email__/${AUTHOR_EMAIL}/g" "${file}"
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}"
2024-10-10 10:30:21 +02:00
# shellcheck disable=SC2001
2024-09-25 12:48:36 +02:00
escape_url=$(echo "${URL}" | sed 's_/_\\/_g')
sed -i "s/__url__/${escape_url}/g" "${file}"
2021-01-20 17:53:02 +01:00
sed -i "s/__license__/${LICENSE}/g" "${file}"
2022-06-14 08:42:54 +02:00
sed -i "s/__description__/${DESCRIPTION}/g" "${file}"
2024-01-19 14:12:08 +01:00
done <<< "$(find "${destination_path}/" -type f)"