Update logging, path, docker scripts

This commit is contained in:
Andrejus
2020-07-12 14:11:50 +01:00
parent 1418a61962
commit f9cb667046
8 changed files with 55 additions and 39 deletions

2
.gitignore vendored
View File

@@ -1,7 +1,7 @@
# install # install
tmp tmp
*.deb *.deb
*.log logs/*
**/plugged **/plugged
**/autoload **/autoload

View File

@@ -14,14 +14,14 @@ RUN echo "$USER ALL=(ALL) NOPASSWD: ALL" \
# Filesystem steps # Filesystem steps
ENV WORKSPACE="/home/$USER/workspace" ENV WORKSPACE="/home/$USER/workspace"
ENV LOG_TARGET="STDOUT"
ADD --chown=test-user . "$WORKSPACE/dotfiles" ADD --chown=test-user . "$WORKSPACE/dotfiles"
WORKDIR "$WORKSPACE/dotfiles" WORKDIR "$WORKSPACE/dotfiles"
# Install steps # Install steps
USER test-user USER test-user
ENV FAST_MODE="true"
ARG TARGET="all" ARG TARGET="all"
RUN make TARGET=$TARGET RUN make install TARGET=$TARGET
# Test entrypoint # Test entrypoint
ENTRYPOINT [ "make", "--directory", "tests", "TARGET=$TARGET" ] ENTRYPOINT [ "make", "--directory", "tests", "TARGET=$TARGET" ]

View File

@@ -3,6 +3,7 @@
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
.PHONY: clean install .PHONY: clean install
# Install dotfiles to home folder
all: all:
./bootstrap.pl ./bootstrap.pl
@@ -11,7 +12,7 @@ install:
./install.pl ./install.pl
clean: clean:
rm ./.install.*.log rm -rf logs
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Docker commands # Docker commands

View File

@@ -7,16 +7,17 @@ use Cwd;
use Stow; use Stow;
# Stow files
my $dir = getcwd; my $dir = getcwd;
my $target = $ENV{'HOME'};
print "Stowing $dir/files to $target\n";
my %stow_options = ( dir => $dir, my %stow_options = ( dir => $dir,
target => $ENV{'HOME'}); target => $target);
my $stow = new Stow(%stow_options); my $stow = new Stow(%stow_options);
my @pkgs = ('files'); my @pkgs = ('files');
$stow->plan_stow(@pkgs); $stow->plan_stow(@pkgs);
# my %conflicts = $stow->get_conflicts();
$stow->process_tasks(); $stow->process_tasks();
print "done\n"; print "done\n";

View File

@@ -1,3 +1,5 @@
echo "Loading bash profile"
# Load .profile, containing login, non-bash related initializations. # Load .profile, containing login, non-bash related initializations.
source "$HOME/.profile" source "$HOME/.profile"

View File

@@ -27,28 +27,22 @@ if [ -z "$PROFILE_LOCK" ]; then
# pyenv # pyenv
export PYENV_ROOT="$HOME/.pyenv" export PYENV_ROOT="$HOME/.pyenv"
if [ -d "$PYENV_ROOT" ]; then
export PATH="$PYENV_ROOT/bin:$PATH" export PATH="$PYENV_ROOT/bin:$PATH"
export PATH="$PYENV_ROOT/shims:$PATH" export PATH="$PYENV_ROOT/shims:$PATH"
if [ -d "$PYENV_ROOT" ]; then
[ -x "$(command -v pyenv)" ] && eval "$(pyenv init -)" [ -x "$(command -v pyenv)" ] && eval "$(pyenv init -)"
fi fi
# poetry # poetry
export POETRY_ROOT="$HOME/.poetry" export POETRY_ROOT="$HOME/.poetry"
if [ -d "$POETRY_ROOT" ]; then
export PATH="$POETRY_ROOT/bin:$PATH" export PATH="$POETRY_ROOT/bin:$PATH"
fi
# nvm # nvm
export NVM_DIR="$XDG_CONFIG_HOME/nvm" export NVM_DIR="$XDG_CONFIG_HOME/nvm"
if [ -d "$NVM_DIR" ]; then
export PATH="$NVM_DIR/bin:$PATH" export PATH="$NVM_DIR/bin:$PATH"
fi
# yarn # yarn
export YARN_DIR="$HOME/.yarn" export YARN_DIR="$HOME/.yarn"
if [ -d "$YARN_DIR" ]; then
export PATH="$YARN_DIR/bin:$PATH" export PATH="$YARN_DIR/bin:$PATH"
fi
fi fi

View File

@@ -4,6 +4,7 @@ use warnings;
use autodie; use autodie;
use Cwd; use Cwd;
use File::Path qw( make_path );
# Prevent running as root # Prevent running as root
if ($< == 0) { if ($< == 0) {
@@ -13,25 +14,40 @@ if ($< == 0) {
my $dir = getcwd; my $dir = getcwd;
# Generate unique logfile my $log_target = $ENV{'LOG_TARGET'} // '';
my $uuid = `uuidgen`; my $log_path = '';
chomp $uuid; if ($log_target ne 'STDOUT') {
my $log_path = "$dir/.install.$uuid.log"; # Generate unique logfile
print "Logs: $log_path\n"; my $log_dir = "$dir/logs";
make_path $log_dir or die "Failed to create path: $log_dir";
my $uuid = `uuidgen`;
chomp $uuid;
$log_path = "$log_dir/$uuid.log";
print "Logs: $log_target\n";
}
# Execute given command and log appropriately
# @arg 0 command to run
sub execute {
my $command = $log_path ne ''
? "$_[0] &> $log_path"
: $_[0];
return system($command);
}
# Ensure dependencies installed # Ensure dependencies installed
`sudo apt-get update -y && sudo apt-get install -y liblocal-lib-perl cpanminus stow >> $log_path 2>&1`; execute("sudo apt-get update -qqy && sudo apt-get install -qqy liblocal-lib-perl cpanminus stow");
# Bootstrap files # Bootstrap files
my $exit_status = `./bootstrap.pl >> $log_path 2>&1`; execute("./bootstrap.pl");
print $exit_status;
# Read scripts to be installed # Read scripts to be installed
my $install_dir = "$dir/install"; my $install_dir = "$dir/install";
print "Installing $install_dir\n"; print "Installing $install_dir\n";
opendir(DIR, $install_dir) or die "Could not open $install_dir\n"; opendir($dir, $install_dir) or die "Could not open $install_dir\n";
my @files = readdir(DIR); my @files = readdir($dir);
closedir(DIR); closedir($dir);
@files = grep(/^\d{2}-.*\.sh$/, @files); @files = grep(/^\d{2}-.*\.sh$/, @files);
@files = sort { lc($a) cmp lc($b) } @files; @files = sort { lc($a) cmp lc($b) } @files;
@@ -42,7 +58,7 @@ if ($target ne 'all') {
} }
foreach my $file (@files) { foreach my $file (@files) {
print "Running $file...\r"; print "Running $file...\r";
my $exit_status = system("/bin/bash -l $install_dir/$file >> $log_path 2>&1"); my $exit_status = execute("/bin/bash -l $install_dir/$file");
if ($exit_status != 0) { if ($exit_status != 0) {
print "Failure in $file, see above and logs for more detail.\n"; print "Failure in $file, see above and logs for more detail.\n";
exit ($exit_status); exit ($exit_status);

View File

@@ -1,14 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# ---------------------------------------------------------------------------- #
# Helper variables #
# ---------------------------------------------------------------------------- #
install_dir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )";
dotfiles_dir="$(dirname "$install_dir")";
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
# Helper functions # Helper functions
# ---------------------------------------------------------------------------- # # ---------------------------------------------------------------------------- #
clean() { clean() {
sudo apt-get clean sudo apt-get clean
} }
@@ -29,13 +22,13 @@ upgrade() {
# @arg $1 packages to install # @arg $1 packages to install
install() { install() {
sudo apt-get install $1 sudo apt-get install -qqy $1
refresh refresh
} }
# @arg $1 package list file to install # @arg $1 package list file to install
install_file() { install_file() {
sudo apt-get install -f $(cat $1) sudo apt-get install -qqyf $(cat $1)
refresh refresh
} }
@@ -109,3 +102,12 @@ C_LCYAN='\033[1;36m'
C_LGRAY='\033[0;37m' C_LGRAY='\033[0;37m'
C_WHITE='\033[1;37m' C_WHITE='\033[1;37m'
C_NC='\033[0m' C_NC='\033[0m'
# ---------------------------------------------------------------------------- #
# Helper variables #
# ---------------------------------------------------------------------------- #
install_dir="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
dotfiles_dir="$(dirname "$install_dir")"
source "$dotfiles_dir/files/.bash_profile"
refresh