This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathclone.sh
164 lines (142 loc) · 4.31 KB
/
clone.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
set -e
cd /home/sketu/rising
log_file="cloned_repositories.txt"
> "$log_file"
function repo_exists {
local repo_url=$1
git ls-remote --exit-code "$repo_url" &> /dev/null
return $?
}
function get_remote_url {
local remote_name=$1
local repo=$2
case $remote_name in
github)
echo "https://github.com/$repo.git"
;;
gitlab)
echo "https://gitlab.com/$repo.git"
;;
gitea)
echo "https://gitea.com/$repo.git"
;;
bitbucket)
echo "https://bitbucket.org/$repo.git"
;;
codeberg)
echo "https://codeberg.org/$repo.git"
;;
git.mainlining)
echo "https://git.mainlining.org/$repo.git"
;;
repo.radio)
echo "https://repo.radio/$repo.git"
;;
*)
echo "https://github.com/$repo.git"
;;
esac
}
function find_repo_with_fallback {
local repo_name=$1
local username=$2
local remote_name=$3
local orgs=("RisingOSS-devices" "LineageOS")
if [[ -n "$username" ]]; then
repo_url=$(get_remote_url "$remote_name" "$username/$repo_name")
if repo_exists "$repo_url"; then
echo "$repo_url"
return
fi
fi
for org in "${orgs[@]}"; do
local repo_url=$(get_remote_url "$remote_name" "$org/$repo_name")
if repo_exists "$repo_url"; then
echo "$repo_url"
return
fi
done
echo ""
}
function clone_repository {
local repo_url=$1
local dest_dir=$2
if [[ -d "$dest_dir" ]]; then
rm -rf "$dest_dir"
fi
git clone "$repo_url" --depth=1 --recursive "$dest_dir"
if [[ $? -ne 0 ]]; then
echo "Error: Failed to clone the repository $repo_url."
return 1
fi
echo "$dest_dir" >> "$log_file"
return 0
}
function check_vendorsetup {
local dest_dir=$1
if [[ -f "$dest_dir/vendorsetup.sh" ]]; then
echo "Error: vendorsetup.sh found in $dest_dir. Please remove it and add to rising.dependencies."
return 1
fi
return 0
}
function process_dependencies {
local dest_dir=$1
local dependencies_file
if [[ -f "$dest_dir/rising.dependencies" ]]; then
dependencies_file="$dest_dir/rising.dependencies"
elif [[ -f "$dest_dir/lineage.dependencies" ]]; then
dependencies_file="$dest_dir/lineage.dependencies"
else
return 0
fi
echo "Found dependencies file: $dependencies_file"
jq -c '.[]' "$dependencies_file" | while read -r dependency; do
local dependency_repository=$(echo "$dependency" | jq -r '.repository')
local dependency_branch=$(echo "$dependency" | jq -r '.branch // "fifteen"')
local dependency_target_path=$(echo "$dependency" | jq -r '.target_path')
local remote_name=$(echo "$dependency" | jq -r '.remote // "github"')
local username=""
if [[ "$dependency_repository" == *"/"* ]]; then
username=$(echo "$dependency_repository" | cut -d'/' -f1)
dependency_repository=$(echo "$dependency_repository" | cut -d'/' -f2-)
fi
local dependency_url=$(find_repo_with_fallback "$dependency_repository" "$username" "$remote_name")
if [[ -z "$dependency_url" ]]; then
echo "Warning: Failed to find Repository $dependency_repository. Continuing with next dependency."
continue
fi
if ! clone_and_check_dependencies "$dependency_url" "$dependency_target_path"; then
echo "Warning: Failed to clone dependency $dependency_url. Continuing with next dependency."
fi
done
}
function clone_and_check_dependencies {
local repo_url=$1
local dest_dir=$2
if ! clone_repository "$repo_url" "$dest_dir"; then
return 1
fi
if ! check_vendorsetup "$dest_dir"; then
return 1
fi
process_dependencies "$dest_dir"
}
function main {
local primary_repo_url="https://github.com/RisingOSS-devices/android_device_${BRAND}_${CODENAME}.git"
local fallback_repo_url="https://github.com/LineageOS/android_device_${BRAND}_${CODENAME}.git"
if repo_exists "$primary_repo_url"; then
clone_and_check_dependencies "$primary_repo_url" "device/$BRAND/$CODENAME"
else
echo "Warning: Repository not found in RisingOSS-devices ($primary_repo_url). Cloning from LineageOS."
if repo_exists "$fallback_repo_url"; then
clone_and_check_dependencies "$fallback_repo_url" "device/$BRAND/$CODENAME"
else
echo "Error: Repository doesn't exist in RisingOSS-devices or LineageOS."
exit 1
fi
fi
echo "Device dependencies cloned successfully. Starting Build"
}
main