File size: 1,263 Bytes
571f20f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash


set -e  # Exit immediately if a command exits with a non-zero status.

# Directory containing the script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Subdirectory to update
SUBDIR="install_module"

# Full path to the subdirectory
SUBDIR_PATH="$SCRIPT_DIR/$SUBDIR"

# GitHub repository URL
REPO_URL="https://github.com/seapoe1809/Health_server"

# Update the install_module subdirectory
if [ -d "$SUBDIR_PATH/.git" ]; then
    echo "Updating existing $SUBDIR directory..."
    cd "$SUBDIR_PATH"
    git fetch origin
    
    # Check if 'main' branch exists
    if git ls-remote --exit-code --heads origin main >/dev/null 2>&1; then
        BRANCH="main"
    elif git ls-remote --exit-code --heads origin master >/dev/null 2>&1; then
        BRANCH="master"
    else
        echo "Error: Neither 'main' nor 'master' branch found in the remote repository."
        exit 1
    fi
    
    echo "Using branch: $BRANCH"
    git checkout $BRANCH
    git reset --hard origin/$BRANCH
else
    echo "Cloning $SUBDIR directory..."
    git clone "$REPO_URL" "$SUBDIR_PATH"
    cd "$SUBDIR_PATH"
    
    # Check which branch was cloned
    BRANCH=$(git rev-parse --abbrev-ref HEAD)
    echo "Cloned branch: $BRANCH"
fi

echo "Update complete."