rade install

The install function is an essential feature for a package manager. During installation, rade retrieves information about dependencies, capacity, language used, etc. Let's see what rade does when you enter rade install hello_knife.

Checking if the package exists

It checks if the package to be installed exists (in this case, checking if hello_knife exists). It checks all directories in the packagelist, and if a directory named hello_knife exists, it continues with the installation. If it doesn't exist, it outputs a message saying "No such package exists".

If it exists

If it exists, rade reads the following files in the package directory: dependencies file, language file, repository file, capacity file, and version file.

Then, rade reads the repository URL in the repository file and clones that repository.

If cloning is successful

When rade successfully clones, it searches for a directory named .comrade in that repository. If a .comrade directory exists, rade reads a file called exec_name inside the .comrade directory. This file contains the name of the executable file after compiling the repository. After reading this file, rade executes install.sh in that repository. If .comrade doesn't exist, rade assumes the executable file name is the repository name and executes install.sh. install.sh is a shell script that describes how to compile the repository and is essential for rade's program installation.

Compiling the program

rade executes install.sh for compilation. If install.sh terminates abnormally, rade stops execution and outputs an error message. There's one package where you can experience this abnormal termination. It's the build_error package. If you try to install the build_error package, it intentionally causes a compilation error, stops the build, and even stops rade. Feel free to try installing it if you're interested. (There's a rumor that something interesting happens if you fix it...) Back to the main topic.

When the build completes successfully, rade searches for the executable file. If the executable file exists, rade moves the program to ~/.comrade/bin/, writes logs, and successfully completes the installation. If the program doesn't exist, rade throws an error and terminates abnormally. (The process when the program doesn't exist is handled by .expect()) When the installation is complete, rade deletes the build directory and prepares for the next installation.

Here's the rade log when installing the hello_knife package:

❯ rade install hello_knife
>>> removing build directory... # Remove the build directory if it exists
>>> Clone package... # Since a package named hello_knife was found, read the repository file and clone it
install package: hello_knife
executable file name: hello # Since the .comrade directory existed, read and output exec_name in that directory
capacity: bytes # Read and output the capacity file. (Note: hello_knife's capacity file is empty, so it only displays bytes)
language: C # hello_knife is written in C language, so it displays C
versions: v1.0 # Output hello_knife's version
dependencies: None # hello_knife has no dependencies, so it displays None
repository: https://github.com/knife-package-manager/hello_knife # hello_knife's repository URL

install hello_knife?
[y/n] y
>>> Start Installation
>>> run install.sh (build start) # Execute install.sh and start the build
>>> build end # install.sh terminated normally
>>> moving file... # Move the executable file to ~/.comrade/bin/ to make it executable
>>> remove build directory... # Delete the build directory
>>> Fill in the log... # Write the installed items to the log
/home/inado/.comrade/log/install/hello_knife
All done! # Installation completed normally, notifying that everything is done
Installation is complete
For more information on hello_knife, please see https://github.com/knife-package-manager/hello_knife.

This concludes this chapter. Next is the explanation of the list function.