-
Notifications
You must be signed in to change notification settings - Fork 5
/
eos-github2gitlab
executable file
·113 lines (99 loc) · 3.84 KB
/
eos-github2gitlab
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
#!/bin/bash
# Convert some github URLs to corresponding gitlab mirror URLs.
DIE() {
local progname="$(basename "$0")"
echo "==> $progname: error: $1" >&2
exit 1
}
Github2Gitlab_new() {
# Get value of variable EOS_FILESERVER_SITE.
source /etc/eos-script-lib-yad.conf || DIE "init failed."
local github_url="$1" # This URL may be converted to gitlab mirror.
local keep_master=no # PKGBUILDS repofolder defaults to branch name 'master'.
# Manage the only option, --keep-master.
# Note: option should be removed, used only in eos-rankmirrors (?)
case "$1" in
--keep-master)
github_url="$2"
keep_master=yes
;;
esac
# Check parameter validity.
[ -n "$github_url" ] || DIE "no URL!"
[[ "$github_url" =~ github ]] || DIE "'$github_url' is not a github URL"
# See which conversions are needed.
case "$EOS_FILESERVER_SITE" in
github)
echo "$github_url" # If github is selected, URL is already OK.
;;
gitlab)
# Some repos still use the 'master' branch.
[[ "$github_url" =~ /endeavouros-team/PKGBUILDS/ ]] && keep_master=yes
# Start constructing needed conversions.
local convert_to_gitlab=(
sed
-e 's|/endeavouros-team/|/endeavouros-filemirror/|'
-e 's|/endeavouros-team$|/endeavouros-filemirror|'
)
if [[ "$github_url" =~ '//raw.githubusercontent.com/' ]] ; then
# a few more conversions needed
convert_to_gitlab+=(
-e 's|//raw\.githubusercontent\.com/|//gitlab.com/|'
-e 's|/main/|/raw/main/|'
-e 's|/calamares/calamares/|/raw/calamares/calamares/|' # ???
-e 's|/blob/|/raw/|' # ???
-e 's|/tree/|/blob/|' # ???
)
case "$keep_master" in
yes) convert_to_gitlab+=(-e 's|/master/|/raw/master/|') ;;
no) convert_to_gitlab+=(-e 's|/master/|/raw/main/|') ;;
esac
elif [[ "$github_url" =~ '//github.com/' ]] ; then
# not much more to convert
convert_to_gitlab+=(
-e 's|//github\.com/|//gitlab.com/|'
)
fi
# Now make the conversion.
echo "$github_url" | "${convert_to_gitlab[@]}"
;;
esac
}
Github2Gitlab() { # old implementation
local url
local keep_master=no
case "$1" in
--keep-master) url="$2" ; keep_master=yes ;;
*) url="$1" ;;
esac
source /etc/eos-script-lib-yad.conf
case "$EOS_FILESERVER_SITE" in
github)
echo "$url"
;;
gitlab | *)
local sed=(sed)
if [ -n "$(echo "$url" | grep "/raw\.githubusercontent\.com/")" ] ; then
sed+=(-e 's|/raw\.githubusercontent\.com/|/gitlab.com/|')
sed+=(-e 's|/main/|/-/raw/main/|' )
if [ "$keep_master" = "yes" ] ; then
sed+=(-e 's|/master/|/-/raw/master/|')
else
sed+=(-e 's|/master/|/-/raw/main/|')
fi
sed+=(-e 's|/endeavouros-team/calamares/|/endeavouros-team/calamares/-/raw/|' )
sed+=(-e 's|/install-scripts-next/|/install-scripts-next/-/raw/|')
else
sed+=(-e 's|/github\.com/|/gitlab.com/|')
fi
sed+=(
-e 's|/endeavouros-team/|/endeavouros-filemirror/|'
-e 's|/tree/master/|/-/blob/master/|'
-e 's|/blob/master/|/-/blob/master/|'
-e 's|/eos-bash-shared$|/eos-apps-info|' # ???
)
echo "$url" | "${sed[@]}"
;;
esac
}
Github2Gitlab "$@"