forked from dfirdeferred/Trimarcisia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trimarcisia.sh
87 lines (69 loc) · 2.69 KB
/
Trimarcisia.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
##################################################################
# Trimarcisia.sh v1.0.0 #
# #
# Written by Darryl G. Baker #
##################################################################
# Print ASCII Art
echo " _____ _ _ "
echo "|___ / | | | | ___ _ __ ___ ___ _ __ ___ ___ _ __ "
echo " |_ \ | |_| |/ _ \| '__/ __|/ _ \ '_ \` _ \ / _ \ '_ \ "
echo " ___) | | _ | (_) | | \__ \ __/ | | | | | __/ | | |"
echo "|____/ |_| |_|\___/|_| |___/\___|_| |_| |_|\___|_| |_|"
# List of repositories
REPOS=$(curl -s https://api.github.com/users/Trimarc/repos | jq -r '.[].name')
# Check if curl and unzip are installed, if not, install them
if ! command -v curl &> /dev/null; then
echo "curl not found. Installing..."
sudo apt-get install curl -y
fi
if ! command -v unzip &> /dev/null; then
echo "unzip not found. Installing..."
sudo apt-get install unzip -y
fi
# Function to download and unzip the repository
download_repo() {
repo_name=$1
# Check if the directory exists
if [ ! -d "$repo_name" ]; then
echo "Downloading $repo_name..."
# Get repository information
repo=$(curl -s "$api/$repo_name")
current_branch=$(echo "$repo" | jq -r '.default_branch')
# Construct the zip file URL
zip_url=$(echo "$repo" | jq -r '.archive_url' | sed "s/{archive_format}{\/ref}/zipball\/$current_branch/")
# Download and unzip the repository
curl -L -o "$repo_name.zip" "$zip_url"
echo "Unzipping $repo_name..."
unzip "$repo_name.zip" -d "$repo_name"
# Clean up the zip file
rm "$repo_name.zip"
# Open the folder
xdg-open "$repo_name" >/dev/null 2>&1 &
else
echo "$repo_name already downloaded."
# Open the folder if it exists
xdg-open "$repo_name" >/dev/null 2>&1 &
fi
}
# Display list of repositories
echo "Please select a repository to download/open:"
echo "0. Download all repositories"
for i in "${!REPOS[@]}"; do
echo "$((i+1)). ${REPOS[$i]}"
done
# Read user input
read -rp "Enter the number of the repository you want to download/open: " selection
# Validate user input
if [[ "$selection" -eq 0 ]]; then
for repo_name in "${REPOS[@]}"; do
download_repo "$repo_name"
done
echo "All repositories have been downloaded."
elif [[ "$selection" -ge 1 && "$selection" -le ${#REPOS[@]} ]]; then
repo_name="${REPOS[$((selection-1))]}"
download_repo "$repo_name"
else
echo "Invalid selection. Exiting."
exit 1
fi