|
1 | 1 | #!/bin/bash
|
| 2 | +# |
| 3 | +# SPDX-FileCopyrightText: 2024-2025 Amilcar do Carmo Lucas <[email protected]> |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 | + |
| 7 | +echo "This script is only meant for ArduPilot methodic configurator developers." |
| 8 | +read -p "Do you want to develop ArduPilot methodic Configurator software on your PC? (y/N) " response |
| 9 | + |
| 10 | +# Convert response to lowercase |
| 11 | +response=${response,,} |
| 12 | + |
| 13 | +if [[ ! $response =~ ^y(es)?$ ]]; then |
| 14 | + echo "Setup canceled, install the software using 'pip install ardupilot_methodic_configurator' instead." |
| 15 | + exit 0 |
| 16 | +fi |
2 | 17 |
|
3 | 18 | # Store the original directory
|
4 | 19 | ORIGINAL_DIR=$(pwd)
|
5 | 20 |
|
6 | 21 | # Change to the directory where the script resides
|
7 | 22 | cd "$(dirname "$0")" || exit
|
8 | 23 |
|
| 24 | +InstallDependencies() { |
| 25 | + echo "Updating package lists..." |
| 26 | + if command -v apt-get &> /dev/null; then |
| 27 | + sudo apt-get update |
| 28 | + # Install Python3 PIL.ImageTk for GUI support |
| 29 | + echo "Installing Python3 PIL.ImageTk..." |
| 30 | + sudo apt-get install -y python3-pil.imagetk |
| 31 | + else |
| 32 | + echo "apt-get not found. Skipping system package updates." |
| 33 | + fi |
| 34 | + |
| 35 | + # Uninstall serial and pyserial to avoid conflicts |
| 36 | + echo "Uninstalling serial and pyserial..." |
| 37 | + sudo python3 -m pip uninstall -y serial pyserial |
| 38 | + |
| 39 | + # Install the project dependencies |
| 40 | + echo "Installing project dependencies..." |
| 41 | + python3 -m pip install -e .[dev] |
| 42 | +} |
| 43 | + |
| 44 | +CreateDesktopEntry() { |
| 45 | + # Get the directory of the script |
| 46 | + prog_dir=$(realpath "$(dirname "$0")")/ardupilot_methodic_configurator |
| 47 | + |
| 48 | + # Check if the system is Debian-based |
| 49 | + if [ -f /etc/debian_version ] || [ -f /etc/os-release ] && grep -q 'ID_LIKE=.*debian.*' /etc/os-release; then |
| 50 | + echo "Creating ardupilot_methodic_configurator.desktop for Debian-based systems..." |
| 51 | + # Define the desktop entry content |
| 52 | + desktop_entry="[Desktop Entry]\nName=ArduPilot Methodic Configurator\nComment=A clear ArduPilot configuration sequence\nExec=bash -c 'cd $prog_dir && python3 -m ardupilot_methodic_configurator'\nIcon=$prog_dir/ArduPilot_icon.png\nTerminal=true\nType=Application\nCategories=Development;\nKeywords=ardupilot;arducopter;drone;copter;scm" |
| 53 | + # Create the .desktop file in the appropriate directory |
| 54 | + echo -e "$desktop_entry" > "/home/$USER/.local/share/applications/ardupilot_methodic_configurator.desktop" |
| 55 | + echo "ardupilot_methodic_configurator.desktop created successfully." |
| 56 | + |
| 57 | + # Check if the ~/Desktop directory exists |
| 58 | + if [ -d "$HOME/Desktop" ]; then |
| 59 | + # Copy the .desktop file to the ~/Desktop directory |
| 60 | + cp "/home/$USER/.local/share/applications/ardupilot_methodic_configurator.desktop" "$HOME/Desktop/" |
| 61 | + # Mark it as trusted |
| 62 | + chmod 755 "$HOME/Desktop/ardupilot_methodic_configurator.desktop" |
| 63 | + echo "ardupilot_methodic_configurator.desktop copied to ~/Desktop." |
| 64 | + else |
| 65 | + echo "$HOME/Desktop directory does not exist. Skipping copy to Desktop." |
| 66 | + fi |
| 67 | + |
| 68 | + update-desktop-database ~/.local/share/applications/ |
| 69 | + else |
| 70 | + echo "This system is not Debian-based. Skipping .desktop file creation." |
| 71 | + fi |
| 72 | +} |
| 73 | + |
9 | 74 | ConfigureGit() {
|
10 | 75 | echo "Configuring Git settings..."
|
11 | 76 | git config --local commit.gpgsign false
|
@@ -37,18 +102,6 @@ ConfigureGit() {
|
37 | 102 | echo Git configuration applied successfully.
|
38 | 103 | }
|
39 | 104 |
|
40 |
| -ConfigurePreCommit() { |
41 |
| - echo Setting pre-commit... |
42 |
| - echo "Checking for pip..." |
43 |
| - if ! command -v pip &> /dev/null; then |
44 |
| - echo "pip is not installed. Please install pip before running this script." |
45 |
| - exit 1 |
46 |
| - fi |
47 |
| - pip install 'pre-commit==4.1.0' |
48 |
| - pre-commit install |
49 |
| - echo Pre-commit done. |
50 |
| -} |
51 |
| - |
52 | 105 | ConfigureVSCode() {
|
53 | 106 | # Check for VSCode installation
|
54 | 107 | echo "Checking for VSCode..."
|
@@ -90,9 +143,14 @@ ConfigureVSCode() {
|
90 | 143 | }
|
91 | 144 |
|
92 | 145 | # Call configuration functions
|
| 146 | +InstallDependencies |
| 147 | +CreateDesktopEntry |
93 | 148 | ConfigureGit
|
94 | 149 | ConfigureVSCode
|
95 |
| -ConfigurePreCommit |
| 150 | + |
| 151 | +activate-global-python-argcomplete |
| 152 | + |
| 153 | +pre-commit install |
96 | 154 |
|
97 | 155 | # Run pre-commit
|
98 | 156 | echo "running pre-commit checks on all Files"
|
|
0 commit comments