From 69a50e1e79ecc9e5f1f122cd1f051c814f7c9cec Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Thu, 25 Feb 2021 17:57:49 +0100 Subject: [PATCH] Add a postinstall script for the linux packages, permit the use of -p instead of -printresult for the ybcon arguments, and change the installation directory to /opt/bin. --- CMakeLists.txt | 5 +++- TestYbcon => scripts/TestYbcon | 0 scripts/postinst.sh | 3 ++ scripts/ybcon.sh | 54 ++++++++++++++++++++++++++++++++++ src/main.cpp | 2 +- 5 files changed, 62 insertions(+), 2 deletions(-) rename TestYbcon => scripts/TestYbcon (100%) create mode 100644 scripts/postinst.sh create mode 100755 scripts/ybcon.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index d86e6eb..28842c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,9 +40,12 @@ add_executable(ybcon src/main.cpp resources/Yerbacon.rc src/parser/MainParse.cpp # lpkg = linux package, wpkg = windows package if (UNIX AND NOT MINGW) + set(CPACK_PACKAGING_INSTALL_PREFIX "/opt") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}_lpkg") set(CPACK_SYSTEM_NAME "Linux-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") set(CPACK_TOPLEVEL_TAG "Linux-${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}") + set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/scripts/postinst.sh") + set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) set(CPACK_RPM_PACKAGE_AUTOREQ YES) set(CPACK_RPM_PACKAGE_LICENSE "MPL-2.0") @@ -51,7 +54,7 @@ if (UNIX AND NOT MINGW) if (NOT DEFINED CPACK_GENERATOR) set(CPACK_GENERATOR TGZ;STGZ;DEB;RPM) endif() - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ybcon + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ybcon ${CMAKE_CURRENT_SOURCE_DIR}/scripts/ybcon.sh PERMISSIONS OWNER_WRITE OWNER_EXECUTE diff --git a/TestYbcon b/scripts/TestYbcon similarity index 100% rename from TestYbcon rename to scripts/TestYbcon diff --git a/scripts/postinst.sh b/scripts/postinst.sh new file mode 100644 index 0000000..310447e --- /dev/null +++ b/scripts/postinst.sh @@ -0,0 +1,3 @@ +#!/usr/bin/sh + +ln -sf /opt/bin/ybcon.sh /usr/bin/ybcon diff --git a/scripts/ybcon.sh b/scripts/ybcon.sh new file mode 100755 index 0000000..2071eb2 --- /dev/null +++ b/scripts/ybcon.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# ybcon start script + +EXENAME=ybcon + +# Default location of the executable +defaultBinLocation=/opt/bin/ybcon + +usage() { + echo "$EXENAME [-h|--help] [-p|-printresult] file" + echo " -h or --help What you're seeing right now" + echo " -p or -printresult Prints the transpilation result to stdout" +} + +args=""; +run=false; + +newArgs() { + if [ "$args" = "" ]; then + args="$args$1" + else + args="$args $1" + fi +} + +for it in "$@" +do + case "$it" in + -h | --help ) + echo "Usage:" + usage + exit 0 ;; + -p | -printresult ) + newArgs "$it" + shift ;; + *.ybcon ) + newArgs "$it" + run=true + break ;; + * ) + usage ;; + esac +done + +runIt() { eval "$1" " $args"; } + +if [ "$run" = true ]; then + if [ -f $defaultBinLocation ]; then + runIt "$defaultBinLocation" + elif [ -f ybcon ]; then + runIt "./ybcon" + fi +fi \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8badc51..27e0bb7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char* argv[]) { for (int i = 0; i < argc; i++) { currentArg = ((string) argv[i]); - if (currentArg == "-printresult") printResult = true; + if ((currentArg == "-printresult") || (currentArg == "-p")) printResult = true; else if (currentArg.starts_with("--target=")) target = '.' + currentArg.erase(0, 9); } const string parsedString = parseString(make_unique(getFileContent(fileName)));