shell/gen-makefile

96 lines
2.6 KiB
Plaintext
Raw Normal View History

2022-09-30 07:48:27 +00:00
#!/bin/bash
2022-12-11 06:48:52 +00:00
[ -f Makefile ] && mv Makefile Makefile.bak
2022-09-30 07:48:27 +00:00
CHR_UPGRADE='^'
CHR_UNINSTALL='/'
2022-12-11 06:48:52 +00:00
cat << EOF > Makefile
2022-09-30 07:48:27 +00:00
# Autogenerated at $(date +'%d.%m.%Y %H:%M') using ${BASH_SOURCE[0]}
.DEFAULT_GOAL := help
#===============================================
2022-12-11 06:48:52 +00:00
# Scripts listed in ./install
2022-09-30 07:48:27 +00:00
#===============================================
EOF
2022-12-11 06:48:52 +00:00
for file in ./install/*; do
name=${file##*/}
name=${name%.sh}
desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file})
[ -z "$desc" ] && desc='<no description>'
echo -e "##${name}: ${desc}\n${name}:\n\t@${file}\n" >> Makefile
2022-09-30 07:48:27 +00:00
done;
cat << EOF >> Makefile
2022-12-11 06:48:52 +00:00
2022-09-30 07:48:27 +00:00
#===============================================
2022-12-11 06:48:52 +00:00
# Scripts listed in ./packs
2022-09-30 07:48:27 +00:00
#===============================================
EOF
2022-12-11 06:48:52 +00:00
for file in ./packs/*; do
cat "$file" >> Makefile
echo >> Makefile
2022-09-30 07:48:27 +00:00
done;
2022-12-11 06:48:52 +00:00
2022-09-30 07:48:27 +00:00
cat << EOF >> Makefile
#===============================================
# Scripts listed in ./upgrade
#===============================================
EOF
for file in ./upgrade/*; do
name=${file##*/}
name=${name%.sh}
desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file})
[ -z "$desc" ] && desc='<no description>'
2023-04-12 11:05:12 +00:00
echo -e "##${CHR_UPGRADE}${name}: ${desc}\n${CHR_UPGRADE}${name}:\n\t@${file}\n" >> Makefile
2022-09-30 07:48:27 +00:00
done;
cat << EOF >> Makefile
#===============================================
# Scripts listed in ./uninstall
#===============================================
EOF
for file in ./uninstall/*; do
name=${file##*/}
name=${name%.sh}
desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file})
[ -z "$desc" ] && desc='<no description>'
2023-04-12 11:05:12 +00:00
echo -e "##${CHR_UNINSTALL}${name}: ${desc}\n${CHR_UNINSTALL}${name}:\n\t@${file}\n" >> Makefile
2022-09-30 07:48:27 +00:00
done;
cat << EOF >> Makefile
#===============================================
# Service goals
#===============================================
self:
@./gen-makefile
help: Makefile
@echo "Ubuntu software installator"
@echo
@echo "Usage:"
@echo "\tmake help\t - show this help"
@echo "\tmake self\t - regenerate Makefile (alias of ./gen-makefile)"
@echo "\tmake GOAL\t - install software"
@echo "\tmake ${CHR_UPGRADE}GOAL\t - upgrade software"
@echo "\tmake ${CHR_UNINSTALL}GOAL\t - uninstall software"
2022-09-30 07:48:27 +00:00
@echo "\nYou can combine GOALs, here are some examples:"
@echo "\tmake ${CHR_UNINSTALL}docker docker"
@echo "\tmake php ${CHR_UNINSTALL}docker ${CHR_UPGRADE}omz"
2022-09-30 07:48:27 +00:00
@echo "\nAvailable GOALs:"
@sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/"
+%:
2023-04-12 09:03:00 +00:00
@make $*
2022-09-30 07:48:27 +00:00
EOF
echo "New ./Makefile has been generated!"
echo "Old one has been saved as ./Makefile.bak"
echo "Now run 'make' to get help"