diff --git a/.gitignore b/.gitignore index 452a78b..bab403c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # install tmp -.dotlock *.deb +*.log # pytest **/__pycache__ diff --git a/Makefile b/Makefile index 322adc1..96d484b 100644 --- a/Makefile +++ b/Makefile @@ -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 # ---------------------------------------------------------------------------- # diff --git a/bootstrap.pl b/bootstrap.pl new file mode 100755 index 0000000..649887f --- /dev/null +++ b/bootstrap.pl @@ -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; + diff --git a/bash/.bash_profile b/files/bash/.bash_profile similarity index 100% rename from bash/.bash_profile rename to files/bash/.bash_profile diff --git a/bash/.bashrc b/files/bash/.bashrc similarity index 100% rename from bash/.bashrc rename to files/bash/.bashrc diff --git a/bash/.profile b/files/bash/.profile similarity index 100% rename from bash/.profile rename to files/bash/.profile diff --git a/fish/config.fish b/files/fish/config.fish similarity index 100% rename from fish/config.fish rename to files/fish/config.fish diff --git a/fish/fishfile b/files/fish/fishfile similarity index 100% rename from fish/fishfile rename to files/fish/fishfile diff --git a/fish/functions/nvm.fish b/files/fish/functions/nvm.fish similarity index 100% rename from fish/functions/nvm.fish rename to files/fish/functions/nvm.fish diff --git a/fish/functions/update.fish b/files/fish/functions/update.fish similarity index 100% rename from fish/functions/update.fish rename to files/fish/functions/update.fish diff --git a/git/.gitconfig b/files/git/.gitconfig similarity index 100% rename from git/.gitconfig rename to files/git/.gitconfig diff --git a/git/.gitignore_global b/files/git/.gitignore_global similarity index 100% rename from git/.gitignore_global rename to files/git/.gitignore_global diff --git a/ssh/config b/files/ssh/config similarity index 100% rename from ssh/config rename to files/ssh/config diff --git a/vim/init.vim b/files/vim/init.vim similarity index 100% rename from vim/init.vim rename to files/vim/init.vim diff --git a/vim/plugins.vim b/files/vim/plugins.vim similarity index 100% rename from vim/plugins.vim rename to files/vim/plugins.vim diff --git a/install.pl b/install.pl index b453640..1e2e5c0 100755 --- a/install.pl +++ b/install.pl @@ -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) { diff --git a/install/33-aws.sh b/install/33-aws.sh index 98675f8..b12087e 100755 --- a/install/33-aws.sh +++ b/install/33-aws.sh @@ -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 diff --git a/setup.pl b/setup.pl index 0a42a30..833810c 100755 --- a/setup.pl +++ b/setup.pl @@ -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');