diff --git a/.config/clonedev/config.yml b/.config/clonedev/config.yml new file mode 100755 index 00000000..7d781ca0 --- /dev/null +++ b/.config/clonedev/config.yml @@ -0,0 +1,60 @@ +base_dir: "${XDG_DOCUMENTS_DIR}/dev" + +actions: + gitea_owned_repos: + api_url: "https://git.snaile.de/api/v1" + targets: + - "orgs/snailed" + - "users/luca" + endpoint: "repos" + token_cmd: "secret-tool lookup gitea api_token" + # read:organization + # read:repository + # read:user + extra_headers: + - "Authorization: token ${TOKEN}" + json_filter: ".[].ssh_url" + github_starred_repos: + api_url: "https://api.github.com" + targets: "users/ssnailed" + endpoint: "starred" + json_filter: ".[].ssh_url" + +clone_flags: "--recursive -j8" + +subdirectories: + desktop: + - "luca/bootstrapper" + - "luca/dmenu-custom" + - "luca/dwm-custom" + - "luca/dwmblocks-custom" + - "luca/st-custom" + - "luca/tokyonight-icons" + - "luca/tokyonight-theme" + server: + - "snailed/ansible-example" + - "snailed/ansible-homelab" + - "snailed/dotfiles-server" + - "snailed/qbittorrent-natpmp" + - "snailed/server-resources" + - "snailed/void-packages-custom" + - "snailed/xbps-builder" + - "spantaleev/matrix-docker-ansible-deploy" + - "void-linux/void-packages" + nvim: + - "snailed/taolf" + misc: + - "snailed/tidal-scraper" + - "b3nj5m1n/xdg-ninja" + - "jnweiger/led-name-badge-ls32" + +block_unsorted: false + +block_repos: + - "luca/dotfiles" + - "luca/pinentry-dmenu-custom" + - "snailed/matrix-inventory" + +extra_repos: + - "https://github.com/void-linux/void-packages" + - "https://github.com/spantaleev/matrix-docker-ansible-deploy" diff --git a/.config/clonedev/hooks/install/matrix-docker-ansible-deploy b/.config/clonedev/hooks/install/matrix-docker-ansible-deploy new file mode 100755 index 00000000..a39de552 --- /dev/null +++ b/.config/clonedev/hooks/install/matrix-docker-ansible-deploy @@ -0,0 +1,2 @@ +#!/bin/sh +submodule add -f -- https://git.snaile.de/snailed/matrix-inventory inventory diff --git a/.config/clonedev/hooks/update/matrix-docker-ansible-deploy b/.config/clonedev/hooks/update/matrix-docker-ansible-deploy new file mode 100755 index 00000000..ad40dfcb --- /dev/null +++ b/.config/clonedev/hooks/update/matrix-docker-ansible-deploy @@ -0,0 +1,2 @@ +#!/bin/sh +just roles diff --git a/.local/bin/clonedev.pl b/.local/bin/clonedev.pl new file mode 100755 index 00000000..8af4e4ce --- /dev/null +++ b/.local/bin/clonedev.pl @@ -0,0 +1,140 @@ +#!/bin/perl +use strict; +use warnings; +use feature ("signatures"); +use YAML(); +use JSON(); +use WWW::Curl::Easy; +use WWW::Curl::Multi; +use Data::Dump(); +use File::Path(); + +use constant USERAGENT => + "User-Agent: MarxBot/4.2.0 (A script reading some information about repos)"; + +my %requests; +my %responses; +my %callbacks; +my $last_handle = 0; +my $active_requests = 0; + +sub new_curl( $url, $handle, @headers ) { + my $curl = WWW::Curl::Easy->new; + $curl->setopt( CURLOPT_URL, $url ); + $curl->pushopt( CURLOPT_HTTPHEADER, [USERAGENT] ); + for my $header (@headers) { + $curl->pushopt( CURLOPT_HTTPHEADER, [$header] ); + } + $curl->setopt( CURLOPT_PRIVATE, $handle ); + $curl->setopt( CURLOPT_WRITEDATA, \$responses{$handle} ); + $requests{$handle} = $curl; +} + +sub new_callback( $callback, $handle ) { + $callbacks{$handle} = $callback; +} + +sub exec_multicurl() { + my $curlm = WWW::Curl::Multi->new; + for my $handle ( keys %requests ) { + $curlm->add_handle( $requests{$handle} ); + $active_requests++; + } + while ($active_requests) { + my $active_transfers = $curlm->perform; + if ( $active_transfers != $active_requests ) { + while ( my ( $handle, $return_value ) = $curlm->info_read ) { + if ($handle) { + $active_requests--; + $callbacks{$handle}->(); + delete $requests{$handle}; + } + } + } + } +} + +sub json_decode($handle) { + my @tmp = split( '\[\{"', $responses{$handle} ); + my $json_string = '[{"' . $tmp[1]; + return decode_json($json_string); +} + +sub git_clone($url) { + print("git clone --recursive -j8 $url"); + + # TODO: +} + +sub json_extract_values( $handle, $key ) { + my @ret; + my $i = 0; + my @tmp = JSON::decode_json ( $responses{$handle} ); + while ( my $value = $tmp[0][ ++$i ]{$key} ) { + push( @ret, $value ); + } + return @ret; +} + +sub get_target_dir() { + +} + +sub handle_repo($url) { + # TODO: Handle blocking + # TODO: Handle cloning + # TODO: Handle pulling + # TODO: Trigger hooks on clone/pull + # TODO: Handle automatic directory placement +} + +sub get_conf() { + my $configdir; + if ( $ENV{XDG_CONFIG_HOME} ) { + $configdir = "$ENV{XDG_CONFIG_HOME}/clonedev"; + } + else { + $configdir = "$ENV{HOME}/.config/clonedev"; + } + open(my $cfg, '<', $configdir . "/config.yml"); + my ($hashref, $arrayref, $string) = YAML::Load(do { local $/; <$cfg> }); + close($cfg); + return %$hashref; +} + +# ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ +# ░ ░░░░ ░░░ ░░░ ░░ ░░░ ░ +# ▒ ▒▒ ▒▒ ▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒ ▒ +# ▓ ▓▓ ▓▓▓▓ ▓▓▓▓▓ ▓▓▓▓▓ ▓ ▓ ▓ +# █ █ █ ██ █████ █████ ██ █ +# █ ████ ██ ████ ██ ██ ███ █ +# ████████████████████████████████████████ + +my %conf = get_conf(); + + + +# my $gitea_repos = ++$last_handle; +# new_curl( "https://git.snaile.de/api/v1/orgs/snailed/repos", +# $gitea_repos, +# "Authorization: token 0991e5a3028713e369b7758489c774a3108070b7" ); +# new_callback( +# sub () { +# my @urls = json_extract_values( $gitea_repos, "ssh_url" ); +# foreach my $url (@urls) { +# print($url . "\n"); +# } +# }, +# $gitea_repos +# ); +# +# my $github_octocat = ++$last_handle; +# new_curl( "https://api.github.com/octocat", $last_handle ); +# new_callback( +# sub () { +# print( $responses{$github_octocat} ); +# }, +# $github_octocat +# ); + +# exec_multicurl(); diff --git a/.local/bin/clonedev b/.local/bin/clonedev.sh similarity index 96% rename from .local/bin/clonedev rename to .local/bin/clonedev.sh index 141dde13..96cb0a3e 100755 --- a/.local/bin/clonedev +++ b/.local/bin/clonedev.sh @@ -62,7 +62,16 @@ scroll() { tput sgr0 } -pull() { +# pull() { +# +# } +# +# clone() { +# +# } + +# FIX: pulling isn't functional yet +ensure() { repo=$1 dir=$(get_path "$repo") || { warn "$repo blocked ✗" @@ -150,9 +159,9 @@ mkdir -p "$BASE" && cd "$BASE" || { for target in $TARGETS; do for repo in $(list "$API_URL/$target/$ENDPOINT" | sed 's|.git$||' | xargs); do - pull "$repo" + ensure "$repo" done done for repo in $(echo "$EXTRA_REPOS" | xargs); do - pull "$repo" + ensure "$repo" done