summaryrefslogtreecommitdiff
path: root/archive
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-04-22 13:12:18 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-04-22 13:12:18 -0700
commitcb92043b165afb121225802cb997c460ef133861 (patch)
tree8da909a820255378d4fa3db25f9bdc4c816a718d /archive
parentd53056bd328179f57dbddd4e7a34f2ef824c09c2 (diff)
downloaddotfiles-cb92043b165afb121225802cb997c460ef133861.tar.gz
switch back Rexfile -> insinuate-dotfiles for the time being
Diffstat (limited to 'archive')
-rw-r--r--archive/Rexfile132
-rw-r--r--archive/perl5/Local/Rex/Util.pm22
2 files changed, 154 insertions, 0 deletions
diff --git a/archive/Rexfile b/archive/Rexfile
new file mode 100644
index 00000000..00bebe09
--- /dev/null
+++ b/archive/Rexfile
@@ -0,0 +1,132 @@
+# -*- 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 <http://www.gnu.org/licenses/>.
+
+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.sh";
+};
+
+1;
diff --git a/archive/perl5/Local/Rex/Util.pm b/archive/perl5/Local/Rex/Util.pm
new file mode 100644
index 00000000..0aa966f8
--- /dev/null
+++ b/archive/perl5/Local/Rex/Util.pm
@@ -0,0 +1,22 @@
+package Local::Rex::Util;
+
+use 5.028;
+use strict;
+use warnings;
+use parent 'Exporter';
+
+use Rex -feature => ['1.4'];
+
+our @EXPORT = qw( as as_me );
+
+sub as ($&) {
+ can_run "sudo" or die "wanted to execute as $_[0] but no sudo on PATH!";
+ sudo { user => $_[0], command => $_[1]};
+}
+
+sub as_me (&) {
+ my $me = get("me") || "spwhitton";
+ as($me, \&{$_[0]});
+}
+
+1;