# -*- mode: cperl -*- # Sean's personal Rexfile # # Copyright (C) 2020 Sean Whitton # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or (at # your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . use 5.028; use strict; use warnings; use lib "$ENV{HOME}/src/dotfiles/perl5"; use autodie; use File::chdir; use File::Temp qw(tempdir tempfile); use Local::Rex::Util; use File::Spec::Functions qw(catfile rel2abs); use Rex::Helper::Path; # use these modules without importing any names to avoid clashes with # Rex functions use File::Path (); =head1 GLOBAL CONFIG =cut use Rex -feature => ['1.4']; # never SSH passwords key_auth; # globals our $dotfiles_tar; our $dotfiles_gpg; # constants use constant { MY_GPG_KEY => 'spwhitton@spwhitton.name', }; =head1 MY HOSTS =cut task "athena", "athena.silentflame.com" => sub { set me => "spwhitton"; needs main => "dotfiles"; as_me { needs main => "dotfiles" }; }; auth for => "athena", user => "root"; =head1 TASKS FOR HOSTS, OR TO RUN LOCALLY =cut # this is a more general alternative to my 'insinuate-dotfiles' script # which should be compatible with more UNIX hosts ('insinuate-dotfiles' # relied upon some GNU tar options on the remote) task "dotfiles" => sub { file "~/dotfiles.tar", ensure => "absent"; file "~/spwhitton.gpg", ensure => "absent"; return if is_dir("~/src/dotfiles/.git"); if (LOCAL { is_dir("~/src/dotfiles/.git") }) { # we can upload a dotfiles tarball from localhost (like # 'insinuate-dotfiles' did). # # Check whether we already ran the dotfiles task during this # rex run, and reuse the tarball if so unless (defined $dotfiles_tar and -f $dotfiles_tar) { LOCAL { local $CWD = tempdir(DIR => catfile($ENV{HOME}, "tmp"), CLEANUP => 1); system qw(git clone --no-hardlinks --depth 1 -o local -b master), "file://$ENV{HOME}/src/dotfiles", "src/dotfiles"; { local $CWD = "src/dotfiles"; system qw(git remote rm local); File::Path::rmtree(".git/refs/remotes/local"); } system qw(tar cf dotfiles.tar src); $dotfiles_tar = rel2abs("dotfiles.tar"); }; } file "~/dotfiles.tar", source => $dotfiles_tar; extract "~/dotfiles.tar"; file "~/dotfiles.tar", ensure => "absent"; # copy my gpg key over there so I can use `mr up` to securely # update dotfiles if (can_run "gpg") { # check if we already ran the dotfiles task during this # rex run, and reuse the exported key if so unless (defined $dotfiles_gpg and -f $dotfiles_gpg) { LOCAL { my (undef, $filename) = tempfile( DIR => catfile($ENV{HOME}, "tmp"), UNLINK => 1 ); system "gpg", "--export-options", "export-minimal", "--output", $filename, "--export", MY_GPG_KEY; $dotfiles_gpg = $filename; }; } file "~/spwhitton.gpg", source => $dotfiles_gpg; run "gpg", ["--import", resolv_path "~/spwhitton.gpg"]; file "~/spwhitton.gpg", ensure => "absent"; } } else { # we need to git clone & verify (like propellor does) die "unimplemented"; } run "~/src/dotfiles/bin/bstraph"; }; 1;