Skip to content

Using `init.sh`

Running the init.sh script is a crucial step to set up your development environment. Here’s a quick guide on how to run the script and what to expect:

1. Running the init.sh Script

  • Command: To start the script, you simply need to run the following command in your terminal:
    bash init.sh
    
  • Windows Users: If you're using Windows, you'll need to use Git Bash to run the script since it's designed for a Unix-like shell environment. Git Bash provides a Bash emulation used to run the script.

2. What the Script Does

  • Tool Installation: The script will check if essential tools (like make, pip, pre-commit, cppcheck, etc.) are installed on your system. If any are missing, the script will prompt you to install them.

  • Python Configuration: The script checks for installed Python versions, ensuring you have a compatible version (3.8 or newer). If it finds a suitable version, it proceeds with additional configurations, including pip installation if necessary.

  • Customizing Your Environment: It offers options to append useful functions to your shell configuration files (like ~/.bashrc), making it easier to work with Python virtual environments in your projects.

  • Project Setup: If you wish, the script also helps in renaming your project by replacing placeholders with your desired package name, GitHub username, and repository name.

3. User Interaction

  • Prompts: Throughout the script, you’ll be prompted with questions like:
  • Whether to install missing tools.
  • Whether to append functions to your shell configuration.
  • Whether to rename your project files.

You can respond with yes/no (or y/n) to these prompts based on your needs.

4. Summary

Running the init.sh script is a straightforward way to automate the setup of your development environment. It checks for and installs necessary tools, configures your Python environment, and optionally customizes your project’s structure—all with minimal input required from you.

How the init.sh Script Works

The init.sh script is a shell script designed to set up your development environment by installing necessary tools, configuring Python, and optionally renaming your project. Here’s a breakdown of how it works:

  1. Initial Setup - Running the Script:
  2. The script is executed using the command:
    bash init.sh
    
  3. It begins by checking whether the script is being run on Windows or a Unix-like system. If you are on Windows, you may need to use Git Bash to run the script.

  4. Installing Chocolatey (Windows only):

  5. If you are on Windows and Chocolatey (a package manager) is not installed, the script prompts you to install it. If you agree, it runs a PowerShell command to install Chocolatey.

  6. Checking for make:

  7. The script checks if make is installed. If make is not found, it installs it using Chocolatey on Windows or apt-get on Debian-based systems.

  8. Checking for Python and Pip:

  9. The script checks for the presence of Python versions 3.8 through 3.12. If a suitable Python version is found, it proceeds to check if pip (Python’s package manager) is installed. If pip is not found, it downloads and installs it.

  10. Virtual Environment Activation Function:

  11. The script offers to append a function activate_venv_in_python_projects to your ~/.bashrc or ~/.bash_profile. This function automatically activates a Python virtual environment if you are in a directory named python_projects and there is a .venv directory.

  12. Installing Additional Tools:

  13. The script checks for and installs several development tools:

    • pre-commit: A framework for managing and maintaining multi-language pre-commit hooks.
    • cppcheck: A static analysis tool for C/C++ code.
    • clang-format: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
  14. Installing pyenv:

  15. If pyenv (a Python version management tool) is not installed, the script installs it. On Unix-like systems, it installs pyenv using a curl command. On Windows, it advises using the pyenv-win fork, as pyenv does not officially support Windows.

  16. Configuring pyenv in Shell:

  17. The script checks if pyenv commands are already included in your ~/.bashrc. If not, it asks whether you want to configure quicker access to pyenv by appending necessary commands to ~/.bashrc.

  18. Making Scripts Executable:

  19. The script asks if you want to make all shell scripts in the scripts directory executable by running chmod +x on them.

  20. Renaming the Project:

    • The script asks if you want to rename your project. If you choose to do so, it prompts you to enter your package name, GitHub username, and repository name. It then updates several files with this new information by replacing placeholders (simple_python_template, GIT_USERNAME, GIT_REPONAME) with the provided values.
  21. Final Outputs:

    • After all installations and configurations, the script informs you of the status of each step, whether something was successfully installed, skipped, or if an error occurred.

This script automates the setup of a development environment, ensuring all necessary tools are installed and configured, and optionally helping to customize the project’s name and structure.