#!/bin/bash [ -f Makefile ] && mv Makefile Makefile.bak CHR_UPGRADE='^' CHR_UNINSTALL='/' cat << EOF > Makefile # Autogenerated at $(date +'%d.%m.%Y %H:%M') using ${BASH_SOURCE[0]} .DEFAULT_GOAL := help #=============================================== # Scripts listed in ./install #=============================================== EOF for file in ./install/*; do name=${file##*/} name=${name%.sh} desc=$(grep -m 1 -oP "(?<=^##makedesc:\s).*$" ${file}) [ -z "$desc" ] && desc='' echo -e "##${name}: ${desc}\n${name}:\n\t@${file}\n" >> Makefile done; cat << EOF >> Makefile #=============================================== # Scripts listed in ./packs #=============================================== EOF for file in ./packs/*; do cat "$file" >> Makefile echo >> Makefile done; 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='' echo -e "# ${desc}\n${CHR_UPGRADE}${name}:\n\t@${file}\n" >> Makefile 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='' echo -e "# ${desc}\n${CHR_UNINSTALL}${name}:\n\t@${file}\n" >> Makefile 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" @echo "\nYou can combine GOALs, here are some examples:" @echo "\tmake ${CHR_UNINSTALL}docker docker" @echo "\tmake php ${CHR_UNINSTALL}docker ${CHR_UPGRADE}omz" @echo "\nAvailable GOALs:" @sed -n 's/^##//p' $< | column -ts ':' | sed -e "s/^/\t/" +%: @make $* ^%: @./upgrade/$* @%: @./uninstall/$* EOF echo "New ./Makefile has been generated!" echo "Old one has been saved as ./Makefile.bak" echo "Now run 'make' to get help"