1515# You should have received a copy of the GNU General Public License
1616# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18+ use URI;
1819use Getopt::Long;
1920use v5.10;
2021no feature " say" ;
@@ -40,6 +41,11 @@ my $dep_scan_depth = $ENV{DEPENDENCY_SCAN_DEPTH} // 2;
4041my $skip_portage_sync = $ENV {SKIP_PORTAGE_SYNC } // 0;
4142my $emerge_split_install = $ENV {EMERGE_SPLIT_INSTALL } // 0;
4243my $webrsync = $ENV {WEBRSYNC } // 0;
44+ # Define git tarball url to use instead of webrsync or emerge --sync
45+ my $portage_git_url = $ENV {PORTAGE_GIT_URL } // " " ;
46+ # Define supported tarball types: github|gitlab
47+ my $portage_git_service = $ENV {PORTAGE_GIT_SRV } // " github" ;
48+ my $portage_git_branch = $ENV {PORTAGE_GIT_BRANCH } // " master" ;
4349my $enman_repositories = $ENV {ENMAN_REPOSITORIES };
4450my $emerge_remove = $ENV {EMERGE_REMOVE };
4551my $remove_enman_repositories = $ENV {REMOVE_ENMAN_REPOSITORIES };
@@ -342,6 +348,39 @@ sub compile_packs {
342348 return $compiled ;
343349}
344350
351+ sub fetch_portage_from_git {
352+
353+ my ( $url , $srv , $branch ) = @_ ;
354+
355+ $url = substr ($url , 0, length ($url )-1) unless substr ($url , -1) cmp " /" ;
356+ my $uri = URI-> new($url );
357+ my $base = ( $uri -> path_segments )[-1];
358+
359+ say " ==== Fetching $srv Portage for branch $branch ====" ;
360+
361+ if ( $srv and $srv eq " gitlab" ) {
362+ $url .= " /-/archive/$branch /$base -$branch .tar.gz" ;
363+ } else {
364+ $url .= " /archive/$branch .tar.gz" ;
365+ }
366+
367+ _system( " wget -O /tmp/portage.tar.gz $url " );
368+ _system( " mkdir /tmp/portage ; tar xzf /tmp/portage.tar.gz -C /tmp/portage" );
369+
370+ # Avoid to remove /usr/portage for use case where I have already
371+ # files under /usr/portage/distfiles or /usr/portage/packages to use.
372+ my @excluded_dirs = (
373+ " 'distfiles'" ,
374+ " 'packages'"
375+ );
376+ my $rsync_opts = " -a --delete --delete-during --recursive -d -A -H" ;
377+ $rsync_opts .= " --exclude $_ " foreach @excluded_dirs ;
378+
379+ _system( " rsync $rsync_opts /tmp/portage/$base -$branch / /usr/portage/" );
380+
381+ _system( " rm -rf /tmp/portage " );
382+ }
383+
345384sub help {
346385 say " -> You should feed me with something" , " " , " Examples:" , " " ,
347386 " \t $0 app-text/tree" , " \t $0 plasma-meta --layman kde" , " " ,
@@ -464,7 +503,11 @@ unless ( $skip_portage_sync == 1 ) {
464503
465504 # sync portage and overlays
466505 _system(" layman -S" );
467- if ( $webrsync == 1 ) {
506+ if ( $portage_git_url ne " " and $portage_git_branch ne " " ) {
507+ fetch_portage_from_git( $portage_git_url , $portage_git_service ,
508+ $portage_git_branch );
509+ }
510+ elsif ( $webrsync == 1 ) {
468511 _system(" emerge-webrsync" );
469512 }
470513 else {
0 commit comments