everest-build-tools/tools/project-init/everest-project-init

139 lines
3.4 KiB
Plaintext
Raw Permalink Normal View History

2023-11-07 12:52:49 -05:00
#!/bin/sh
# everest-project-init - initialize a project
#
# Copyright (C) 2023 Everest Linux
#
# everest-project-init is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# everest-project-init is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with everest-project-init. If not, see <https://www.gnu.org/licenses/>.
red="\033[1;31m"
green="\033[1;32m"
yellow="\033[1;33m"
blue="\033[1;34m"
reset="\033[m"
check="\xE2\x9C\x93"
#
# PARAMETERS:
# "usage: ${0} [-h] [-v] [-i] [-l] DIR LANG \n"
# ^ ^______________^ ^ ^
# 0 1 2 3
#
usage () {
printf "${0} - Initialize a project\n"
printf "usage: ${0} [-h] [-v] [-i] [-l] DIR LANG\n"
printf "\n"
printf "${0} {-h --help} Show this message\n"
printf "${0} {-v --version} Show the current version\n"
printf "${0} {-i --init} Initialize in DIR with template LANG\n"
printf "${0} {-l --list} List all supported language templates\n"
printf "\n"
printf "Ensure DIR is a complete directory path.\n"
printf "\n"
printf "everest-project-init is free software.\n"
printf "See the GNU GPL version 3 for details.\n"
}
usage_small() {
printf "usage: ${0} [-h] [-v] [-i] [-l] DIR LANG\n"
}
mkprojectdir() {
printf "${blue}[i]${reset} Creating project directory...\n"
2023-11-07 13:15:59 -05:00
mkdir -v ./${2}
2023-11-07 12:52:49 -05:00
printf "${green}[${check}]${reset} Directory created.\n"
}
mkskel() {
printf "${blue}[i]${reset} Creating project directory skeleton...\n"
case ${3} in
"C")
2023-11-07 13:15:59 -05:00
mkdir -v ${2}/{src,include}
2023-11-07 12:52:49 -05:00
;;
"Bash")
2023-11-07 13:15:59 -05:00
mkdir -v ${2}/{src,install,man}
mkdir -v ${2}/src/{bin,etc,man}
2023-11-07 12:52:49 -05:00
esac
printf "${green}[${check}]${reset} Project directory skeleton created.\n"
}
dload_license() {
LICENSE_URL="https://gnu.org/licenses/gpl-3.0.txt"
printf "${blue}[i]${reset} Using license 'GPL 3' for this project.\n"
printf "${blue}[i]${reset} Downloading license for project...\n"
curl ${LICENSE_URL} -o ${2}/LICENSE
printf "${green}[${check}]${reset} License downloaded.\n"
}
mkheader() {
printf "${blue}[i]${reset} Generating file header...\n"
ROOT_URL="https://git.everestlinux.org/EverestLinux/project-init-file-headers/raw/branch/main"
cd ${2}
2023-11-07 12:52:49 -05:00
case ${3} in
"C")
2023-11-08 09:55:21 -05:00
curl ${ROOT_URL}/template.c -o ${2}/src
2023-11-07 12:52:49 -05:00
if [ "$?" != 0 ]; then
printf "${red}[x]${reset} Curl exited with non-zero status.\n"
exit 1
fi
;;
"Bash")
2023-11-08 09:55:21 -05:00
curl ${ROOT_URL}/template.sh -o ${2}/src
2023-11-07 12:52:49 -05:00
if [ "$?" != 0 ]; then
printf "${red}[x]${reset} Curl exited with non-zero status.\n"
exit 1
fi
;;
esac
printf "${blue}[i]${reset} File header generated successfully.\n"
}
2023-11-07 12:52:49 -05:00
case $1 in
-h|--help)
usage "$@"
exit 0
;;
-v|--version)
printf "everest-project-init v0.1rc\n"
exit 0
;;
-i|--init)
mkprojectdir "$@"
mkskel "$@"
dload_license "$@"
mkheader "$@"
printf "${green}[${check}]${reset} Project generated successfully.\n"
exit 0
;;
-l|--list)
printf "Available templates:\n"
printf "C\n"
printf "Bash/POSIX sh\n"
2023-11-07 13:15:59 -05:00
exit 0
2023-11-07 12:52:49 -05:00
;;
-*|--*)
usage_small "$@"
exit 1
;;
*)
usage_small "$@"
exit 1
;;
esac
usage_small "$@"
exit 1