Bootstrap using stow

This commit is contained in:
Andrejus
2020-07-12 03:07:01 +01:00
parent 21757767d2
commit b748e73e80
18 changed files with 52 additions and 25 deletions

2
.gitignore vendored
View File

@@ -1,7 +1,7 @@
# install
tmp
.dotlock
*.deb
*.log
# pytest
**/__pycache__

View File

@@ -1,12 +1,18 @@
# ---------------------------------------------------------------------------- #
# Local commands
# ---------------------------------------------------------------------------- #
.PHONY: clean
.PHONY: clean install
all:
./bootstrap.pl
# @arg $TARGET binary to install
all:
install:
./install.pl
clean:
rm ./.install.*.log
# ---------------------------------------------------------------------------- #
# Docker commands
# ---------------------------------------------------------------------------- #

19
bootstrap.pl Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use Cwd;
use Stow;
# Stow files
my $dir = getcwd;
my %stow_options = (
dir => "$dir/files",
target => "$ENV{'HOME'}"
);
my $stow = new Stow(%stow_options);
my %conflicts = $stow->get_conflicts;
$stow->process_tasks() unless %conflicts;

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use Cwd;
@@ -10,28 +11,36 @@ if ($< == 0) {
exit (1);
}
my $dir = getcwd;
# Generate unique logfile
my $uuid = `uuidgen`;
chomp $uuid;
my $log_path = "$ENV{'HOME'}/.dotfiles.$uuid.log";
my $log_path = "$dir/.install.$uuid.log";
print "Logs: $log_path\n";
# Ensure dependencies installed
`sudo apt-get update -y && sudo apt-get install -y liblocal-lib-perl cpanminus stow >> $log_path 2>&1`;
my $dir = getcwd;
my $install_dir = "$dir/install";
print "Installing $install_dir\n";
# Bootstrap files
my $exit_status = `./bootstrap.pl >> $log_path 2>&1`;
print $exit_status;
# Read scripts to be installed
my $install_dir = "$dir/install";
print "Installing $install_dir\n";
opendir(DIR, $install_dir) or die "Could not open $install_dir\n";
my @files = readdir(DIR);
closedir(DIR);
@files = grep(/^\d{2}-.*\.sh$/, @files);
@files = sort { lc($a) cmp lc($b) } @files;
foreach my $file (@files)
{
# Install all scripts by default
next if($file !~ /^\d{2}-.*\.sh$/);
# Install selected targets
my $target = $ENV{'TARGET'} // 'all';
if ($target ne 'all') {
@files = grep(/${target}/, @files);
}
foreach my $file (@files) {
print "Running $file...\r";
my $exit_status = system("/bin/bash -l $install_dir/$file >> $log_path 2>&1");
if ($exit_status != 0) {

View File

@@ -2,16 +2,15 @@
source "$(dirname $0)/utils.sh"
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip -d "$dotfiles_dir/tmp"
temp_dir=$(mktemp -d)
unzip awscliv2.zip -d "$temp_dir"
rm awscliv2.zip
if not_installed "aws"; then
echo "Installing awscli..."
sudo ./tmp/aws/install
sudo $temp_dir/aws/install
fi
echo "awscli is installed, upgrading..."
sudo ./tmp/aws/install --update
sudo $temp_dir/aws/install --update
aws --version
rm -rf ./tmp/aws

View File

@@ -18,10 +18,6 @@ my $repository = $ENV{'DOTFILES_REPOSITORY'} // 'dotfiles';
my $branch = $ENV{'DOTFILES_BRANCH'} // 'master';
print "Using repository $author/$repository at $branch\n";
# Installer filename
my $installer = $ENV{'DOTFILES_INSTALLER'} // 'install.pl';
print "Using installer $installer\n";
# Install location
my $dotfiles_dir = $ENV{'DOTFILES_DIR'} // "$ENV{'HOME'}/.dotfiles";
@@ -46,7 +42,5 @@ print "Moving $temp_dotfiles_dir to $dotfiles_dir\n";
move($temp_dotfiles_dir, $dotfiles_dir);
# Install repo
my $installer_path = "$dotfiles_dir/$installer";
print 'Running installer ' . $installer_path . "\n";
my $output = capture([0,1,2], $^X, $installer_path);
print $output;
print "Running installer\n";
my @output = capture([0,1,2], $^X, 'make install');