File: github-clone.sh

package info (click to toggle)
openvas-scanner 23.35.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,416 kB
  • sloc: ansic: 41,615; xml: 6,251; pascal: 3,723; yacc: 1,250; sh: 1,068; makefile: 333; sql: 273; javascript: 12
file content (38 lines) | stat: -rwxr-xr-x 959 bytes parent folder | download
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
#!/bin/bash

if [ -z "$1" ]; then
    echo "Error: Repository name is not provided."
    exit 1
fi

IFS='/' read -r owner repo <<< "$1"

parent_dir="/workspaces"
if [ ! -d "$parent_dir" ]; then
    echo "Parent directory '$parent_dir' does not exist. Creating it."
    mkdir -p "$parent_dir"
fi

owner_dir="$parent_dir/$owner"
if [ ! -d "$owner_dir" ]; then
    echo "Owner directory '$owner_dir' does not exist. Creating it."
    mkdir -p "$owner_dir"
fi

target_dir="/workspaces/$1"

if [ -d "$target_dir" ]; then
    echo "Error: Target directory '$target_dir' already exists."
    exit 1
fi

if ls $HOME/.ssh/id_* &>/dev/null; then
    if git clone git@github.com:$1.git "$target_dir"; then
        echo "Cloning with SSH URL successful."
    else
        echo "Warning: Cloning with SSH URL failed. Falling back to HTTPS URL."
        git clone https://github.com/$1.git "$target_dir"
    fi
else
    git clone https://github.com/$1.git "$target_dir"
fi