From b102089d80980fecb5ca9c10a79f32ed895726a6 Mon Sep 17 00:00:00 2001 From: Netkas Date: Fri, 6 Oct 2023 05:18:24 -0400 Subject: [PATCH] Additional improvements to the debian build + a setup command built into ncc --- Makefile | 4 +- src/debian/control | 2 +- src/debian/postinst | 33 ++++++++- src/debian/postrm | 21 ++++++ src/ncc/CLI/Commands/SetupCommand.php | 96 +++++++++++++++++++++++++++ src/ncc/CLI/Main.php | 4 ++ 6 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 src/debian/postrm create mode 100644 src/ncc/CLI/Commands/SetupCommand.php diff --git a/Makefile b/Makefile index 72c23e3..4ff1e92 100644 --- a/Makefile +++ b/Makefile @@ -90,8 +90,6 @@ debian_prepare: autoload mkdir -p $(DEBIAN_BUILD_PATH)/DEBIAN mkdir -p $(DEBIAN_BUILD_PATH)/usr/share/ncc cp -rf $(SRC_PATH)/ncc/* $(DEBIAN_BUILD_PATH)/usr/share/ncc - cp -rf $(INSTALLER_SRC_PATH)/ncc.sh $(DEBIAN_BUILD_PATH)/usr/share/ncc/ncc.sh - chmod +x $(DEBIAN_BUILD_PATH)/usr/share/ncc/ncc.sh cp -rf $(CONFIG_PATH)/ncc.yaml $(DEBIAN_BUILD_PATH)/usr/share/ncc/default_config.yaml cp -rf $(CONFIG_PATH)/ncc.yaml $(DEBIAN_BUILD_PATH)/usr/share/ncc/CLI/template_config.yaml cp -rf $(CONFIG_PATH)/default_repositories.json $(DEBIAN_BUILD_PATH)/usr/share/ncc/default_repositories.json @@ -106,6 +104,8 @@ debian_prepare: autoload cp -rf $(DEBIAN_SRC_PATH)/control $(DEBIAN_BUILD_PATH)/DEBIAN/control cp -rf $(DEBIAN_SRC_PATH)/postinst $(DEBIAN_BUILD_PATH)/DEBIAN/postinst chmod +x $(DEBIAN_BUILD_PATH)/DEBIAN/postinst + cp -rf $(DEBIAN_SRC_PATH)/postrm $(DEBIAN_BUILD_PATH)/DEBIAN/postrm + chmod +x $(DEBIAN_BUILD_PATH)/DEBIAN/postrm cp -rf $(DEBIAN_SRC_PATH)/copyright $(DEBIAN_BUILD_PATH)/DEBIAN/copyright diff --git a/src/debian/control b/src/debian/control index 6d14a50..00e19bd 100644 --- a/src/debian/control +++ b/src/debian/control @@ -11,7 +11,7 @@ Vcs-Git: https://git.n64.cc/nosial/ncc.git Vcs-Browser: https://git.n64.cc/nosial/ncc Name: Nosial Code Compiler Architecture: all -Depends: php (>= 8.0), php-mbstring, php-common, php-ctype, php-curl, zlib1g, php-zip +Depends: shared-mime-info, php (>= 8.0), php-mbstring, php-common, php-ctype, php-curl, zlib1g, php-zip Description: Nosial Code Compiler is a multi-purpose compiler, package manager, and toolkit written in PHP. NCC (Nosial Code Compiler) is a versatile tool designed for various tasks related to PHP development. It allows you to compile PHP code, manage packages, and perform various tasks in a PHP-centric environment. diff --git a/src/debian/postinst b/src/debian/postinst index a355669..6a6cb50 100644 --- a/src/debian/postinst +++ b/src/debian/postinst @@ -1,2 +1,33 @@ #!/bin/bash -update-mime-database /usr/share/mime \ No newline at end of file +set -e + +# Update MIME database +if ! update-mime-database /usr/share/mime; then + echo "Error: Failed to update MIME database" + exit 1 +fi + +# Ensure PHP is installed +PHP_BIN=$(command -v php) +if [ -z "$PHP_BIN" ]; then + echo "Error: PHP binary not found" + exit 1 +fi + +# Create symlink for ncc-cli +ENTRY_POINT="/usr/bin/ncc" +if ! cat < "$ENTRY_POINT" +#!/bin/bash +$PHP_BIN /usr/share/ncc/ncc --ncc-cli "\$@" +EOF +then + echo "Error: Failed to create entry point script at $ENTRY_POINT" + exit 1 +fi +chmod +x "$ENTRY_POINT" + +# Initialize ncc +if ! ncc setup --default-repositories=/usr/share/ncc/default_repositories.json; then + echo "Error: Failed to setup ncc" + exit 1 +fi \ No newline at end of file diff --git a/src/debian/postrm b/src/debian/postrm new file mode 100644 index 0000000..68270bb --- /dev/null +++ b/src/debian/postrm @@ -0,0 +1,21 @@ +#!/bin/bash + +set -e + +case "$1" in + remove|purge) + # Remove the entry point script + ENTRY_POINT="/usr/bin/ncc" + + if [ -f "$ENTRY_POINT" ]; then + rm -f "$ENTRY_POINT" + echo "Removed $ENTRY_POINT" + else + echo "$ENTRY_POINT not found. Skipping removal." + fi + ;; + *) +esac + +# End of the script +exit 0 diff --git a/src/ncc/CLI/Commands/SetupCommand.php b/src/ncc/CLI/Commands/SetupCommand.php new file mode 100644 index 0000000..834f843 --- /dev/null +++ b/src/ncc/CLI/Commands/SetupCommand.php @@ -0,0 +1,96 @@ +getMessage()), $e); + return 1; + } + } + + try + { + Functions::initializeFiles($default_repositories); + } + catch(Exception $e) + { + Console::outException(sprintf('Failed to initialize the files: %s', $e->getMessage()), $e); + return 1; + } + + return 0; + } + + + /** + * Displays the help menu for the setup command + * + * @return int + */ + private static function help(): int + { + $options = [ + new CliHelpSection(['help'], 'Displays this help menu about the command'), + new CliHelpSection(['--default-repositories=path'], 'Optional. The path to the default repositories file. If not specified, no default repositories will be loaded') + ]; + + $options_padding = Functions::detectParametersPadding($options) + 4; + + Console::out('Usage: ncc setup [options]'); + Console::out('Options:' . PHP_EOL); + foreach($options as $option) + { + Console::out(' ' . $option->toString($options_padding)); + } + + return 0; + } + } \ No newline at end of file diff --git a/src/ncc/CLI/Main.php b/src/ncc/CLI/Main.php index 0c08337..7db755e 100644 --- a/src/ncc/CLI/Main.php +++ b/src/ncc/CLI/Main.php @@ -29,6 +29,7 @@ use ncc\CLI\Commands\BuildCommand; use ncc\CLI\Commands\ExecCommand; use ncc\CLI\Commands\PackageInspectorCommand; + use ncc\CLI\Commands\SetupCommand; use ncc\CLI\Management\ConfigMenu; use ncc\CLI\Management\CredentialMenu; use ncc\CLI\Management\PackageManagerMenu; @@ -148,6 +149,9 @@ Console::out('Unknown command ' . strtolower(self::$args['ncc-cli'])); break; + case 'setup': + return SetupCommand::start(self::$args); + case 'project': return ProjectMenu::start(self::$args);