Skip to content

Commit

Permalink
[Feature]: Add shell script for installation and workflows for testing (
Browse files Browse the repository at this point in the history
  • Loading branch information
shinymack authored Feb 24, 2025
1 parent 9dcb6f4 commit f062ff2
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 7 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/test-install-script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Test Install Script

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true

on:
push:
branches:
- main
- test-install-script
paths:
- '.github/workflows/test-install-script.yml'
- 'install.sh'
pull_request:
branches:
- main
paths:
- '.github/workflows/test-install-script.yml'
- 'install.sh'

jobs:
linux:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, ubuntu-22.04, archlinux]
include:
- os: ubuntu-latest
image: ubuntu:latest
- os: ubuntu-22.04
image: ubuntu:22.04
- os: archlinux
image: archlinux:latest

name: ${{ matrix.os }}
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Make install.sh Executable
run: chmod +x install.sh

- name: Run Installation Script
run: ./install.sh


wsl:
name: WSL
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up WSL2
uses: vedantmgoyal9/setup-wsl2@main

- name: Install dos2unix and Convert Line Endings
run: |
wsl sudo apt update -y
wsl sudo apt install dos2unix -y
wsl dos2unix "/mnt/d/a/Pixels_Seminar/Pixels_Seminar/install.sh" # Convert line endings
- name: Make Executable and Run Script
run: |
wsl chmod +x "/mnt/d/a/Pixels_Seminar/Pixels_Seminar/install.sh"
wsl bash "/mnt/d/a/Pixels_Seminar/Pixels_Seminar/install.sh" # Run the script
macos:
name: MacOS Latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Make install.sh Executable
run: chmod +x install.sh

- name: Run Installation Script
run: ./install.sh
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,58 @@ This repository includes basics to :

## Installation Instructions

OpenCV library and other dependency needs to be installed on your system, so follow these steps of installation:
OpenCV library and other dependencies need to be installed on your system. Follow one of the methods below:

* Clone SRA-VJTI's Pixel Repository on your system
### **Method 1: If `git` is Installed**
#### **Step 1: Clone the Repository**
If `git` is installed, clone the repository:
```sh
git clone https://github.com/SRA-VJTI/Pixels_Seminar.git
```

* Change terminal directory inside the cloned repository
```
Navigate to the repository:
```sh
cd Pixels_Seminar
```
* Run the installation script

#### **Step 2: Install Dependencies**
##### **Option 1: Using `make` (if installed)**
Check if `make` is installed by running:
```sh
make --version
```
If `make` is installed, you will see output similar to:
```sh
GNU Make 4.3
Built for x86_64-pc-linux-gnu
```
Then, install dependencies with:
```sh
make install
```

Installation is done successfully.
##### **Option 2: Using the Installation Script (if `make` is missing)**
If `make` is not installed or you see an error like:
```sh
command not found: make
```
Run the installation script:
```sh
chmod +x install.sh
./install.sh
```
This will install the required dependencies, including `make`.

---

### **Method 2: If `git` is Not Installed**
Manually download and run the installation script:
```sh
wget https://raw.githubusercontent.com/SRA-VJTI/Pixels_Seminar/main/install.sh -O install.sh
chmod +x install.sh
./install.sh
```
This will install `git`, clone the repository, and install necessary dependencies automatically.

Installation is successfully completed.


112 changes: 112 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
set -e

# Function to check if a command exists
command_exists() {
command -v "$1" &>/dev/null
}

# Detect OS
OS=""
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if grep -qE "debian|ubuntu" /etc/os-release; then
OS="debian"
elif grep -q "arch" /etc/os-release; then
OS="arch"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
elif grep -q "WSL" /proc/version &>/dev/null; then
OS="wsl"
fi

# Ensure sudo is installed (for CI or minimal environments)
if ! command_exists sudo; then
echo "sudo is not installed. Installing sudo..."
case "$OS" in
"debian" | "wsl")
su -c "apt update && apt install sudo -y"
;;
"arch")
su -c "pacman -Sy --noconfirm sudo"
;;
*)
echo "Unsupported OS for automatic sudo installation. Please install manually."
exit 1
;;
esac
fi

# Ensure Git is installed
if ! command_exists git; then
echo "Git is not installed. Installing Git..."
case "$OS" in
"debian" | "wsl")
sudo apt update && sudo apt install -y git
;;
"arch")
sudo pacman -Sy --noconfirm git
;;
"macos")
brew install git
;;
*)
echo "Unsupported OS. Please install Git manually."
exit 1
;;
esac
fi

if [ ! -d "Pixels_Seminar" ]; then
echo "Cloning the repository..."
git clone https://github.com/SRA-VJTI/Pixels_Seminar.git
fi

cd Pixels_Seminar

# Check if OpenCV is installed
if pkg-config --exists opencv4 sdl2; then
echo "OpenCV is already installed."
exit 0
else
echo "OpenCV not found. Installing dependencies..."
fi

# Install dependencies based on OS
case "$OS" in
"debian" | "wsl")
echo "🔹 Detected Debian/Ubuntu or WSL"

# Install sudo if not available (for containers)
if ! command_exists sudo; then
su -c "apt update && apt install sudo -y"
fi

export DEBIAN_FRONTEND=noninteractive
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime
apt-get install -y tzdata
dpkg-reconfigure --frontend noninteractive tzdata

# Install pkg-config and OpenCV dependencies
sudo apt update -y
sudo apt install -y pkg-config build-essential make g++ git libopencv-dev libsdl2-2.0-0 libsdl2-image-dev libsdl2-dev
;;
"arch")
echo "🔹 Detected Arch Linux"
sudo pacman -Sy --noconfirm base-devel opencv hdf5 glew vtk fmt sdl2 pkg-config
;;
"macos")
echo "🔹 Detected macOS"
if ! command_exists brew; then
echo "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install git cmake opencv sdl2
;;
*)
echo "Unsupported OS"
exit 1
;;
esac

echo "Installation complete!"

0 comments on commit f062ff2

Please sign in to comment.