From 4d3bf414733663b9726ebb25eb2d6ead9f302139 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sun, 31 Jul 2022 15:52:29 -0500 Subject: [PATCH 01/10] gitignore vscode files --- gitea/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitea/.gitignore b/gitea/.gitignore index 8113eca..de6a3b3 100644 --- a/gitea/.gitignore +++ b/gitea/.gitignore @@ -1,4 +1,4 @@ - +**/.vscode .vscode/* !.vscode/settings.json !.vscode/tasks.json From 327abea47ec657455064246adac1ee8c1ca01cb0 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sun, 31 Jul 2022 19:41:33 -0500 Subject: [PATCH 02/10] Add vscode dotfiles --- .gitignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index fa0ae04..92be537 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,16 @@ .vstags *.tdy *.bak +**/.vscode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix \ No newline at end of file From 7781fedfd0c1d3e12fbd2ce45bb0e9c5b2a827c7 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sun, 31 Jul 2022 19:42:07 -0500 Subject: [PATCH 03/10] Added status check to condition where update not needed. Added SSH health check. Improve logic flow of update and notification --- gitea/update-gitea.pl | 149 +++++++++++++++++++++++++++++------------- 1 file changed, 105 insertions(+), 44 deletions(-) diff --git a/gitea/update-gitea.pl b/gitea/update-gitea.pl index c125963..ec013a3 100755 --- a/gitea/update-gitea.pl +++ b/gitea/update-gitea.pl @@ -28,6 +28,8 @@ use MIME::Lite; use utf8; use open ':std', ':encoding(UTF-8)'; use Encode qw(encode encode_utf8 ); +# use Net::SSH qw(sshopen2); +use Capture::Tiny qw(capture); my ( $verbose, $info ); @@ -38,28 +40,36 @@ GetOptions( ########################################## ### The user must set these variables ### -my $email = 'gitea-update@tlcnet.info'; -my $filetype = '-linux-amd64'; +my $email = 'gitea-update@tlcnet.info'; +my $filetype = '-linux-amd64'; +my $download_dir = '/home/gitea/bin/'; ########################################## +my $update_needed = 0; + +################################### +# Get version currently installed # +################################### # https://api.github.com/repos/go-gitea/gitea/releases/latest # This URL will only have one version listed my $gitea_bin_dir = '/usr/local/bin/'; my $gitea_bin = $gitea_bin_dir . '/gitea'; my $gitea_current_version_string = `$gitea_bin --version`; my $alphanum_ver = 0; - chomp $gitea_current_version_string; unless ( defined $gitea_current_version_string ) { my $status = "❌ [DIE]: Unable to get the version of the gitea binary on the system: $!"; notification('failed ❌', $status); die RED "$status", RESET; } - my %binary_file = get_current_binary($gitea_current_version_string); my $gitea_current_version = $binary_file{'version'}; + +###################################### +# Check upstream version and get tag # +###################################### my $baseURL = q{https://github.com/go-gitea/gitea/}; -my $latestURL = q{https://api.github.com/repos/go-gitea/gitea/releases/latest}; +my $latestURL = q{https://api.github.com/repos/go-gitea/gitea/releases/latest}; # https://hubpages.com/technology/Use-Perl-to-access-REST-API # Spin up the browser object @@ -72,23 +82,31 @@ my $latest_release_hash = decode_json( $resp->content ) or die "[DIE]: Unable to parse the version data! Output is:\n $resp"; my $orig_tag = $latest_release_hash->{tag_name}; -# print "[TLC DEBUG]: ORIG TAG is $orig_tag\n"; +print "[TLC DEBUG]: ORIG TAG is $orig_tag\n" if defined $verbose; my $tag = $orig_tag; substr( $tag, 0, 1, '' ); my $release_id = $latest_release_hash->{id}; # Works -printf( YELLOW -"[INFO] Latest upstream version: $tag\n Release ID $release_id\n", RESET); + +################ +# Set filename # +################ my $unz_filename = 'gitea-' . $tag . $filetype; #ex: gitea-1.7.6-linux-amd64 -my $download_dir = '/home/gitea/bin/'; my $download_filename = $unz_filename . '.xz'; if ( defined $verbose ) { - printf( YELLOW - "[INFO]\nRelease id: $release_id\nUncompressed filename: $unz_filename\nDownload file target: $download_filename\n" - ); + printf( YELLOW + "[INFO] Latest upstream version: $tag\n Release ID $release_id\n", RESET); + printf( YELLOW + "[INFO]\nRelease id: $release_id\nUncompressed filename: $unz_filename\nDownload file target: $download_filename\n", RESET + ); } + +############################################# +# Check if upstream is newer than installed # +############################################# if ( versioncmp( $gitea_current_version, $tag ) == -1 ) { + $update_needed = 1; printf( "[INFO] Version tag is greater than the system version, proceeding with update\n" ); @@ -105,42 +123,58 @@ if ( versioncmp( $gitea_current_version, $tag ) == -1 ) { } install_bin($download_filename); } -else { - my $status = '✅ Version tag upstream matches the system version, no update needed'; - print "[TLC DEBUG] TAG is $tag\n"; - print( YELLOW "[INFO] $status\n", RESET ); - notification('not needed ✅', $status, $gitea_current_version, $tag); - exit 1; -} -my $gitea_status = check_gitea_status(); -if ( $gitea_status =~ /active/ ) { - print( GREEN "[INFO] Gitea service is active\n", RESET ); -} -unless ( $gitea_status =~ /active/ ) { - my $status = '❌ [DIE] Status of gitea service is no good!'; - print( RED "[INFO] $status\n", RESET ); - notification('failed ❌', $status, $gitea_current_version, $tag); - die $status; -} +################################## +# Get service status and version # +################################## +my ($gitea_status, $gitea_proc_status, $gitea_ssh_status) = check_gitea_status(); $gitea_current_version_string = `$gitea_bin --version`; chomp $gitea_current_version_string; %binary_file = get_current_binary($gitea_current_version_string); $gitea_current_version = $binary_file{'version'}; -if ( versioncmp( $gitea_current_version, $tag ) == -1 ) { - my $status = RED "Upstream version tag is STILL greater than the current system version, something went wrong\n", RESET; - notification('failed ❌', $status, $gitea_current_version, $tag); - printf( $status ); +if ( $gitea_status ) { + print( GREEN "[INFO] ✅ Gitea service is active\n", RESET ); } else { - my $status = '✅ [INFO] Gitea successfuly update. Installed version is current and service is running'; - print( GREEN "[INFO] $status\n", RESET ); - say "Removing the downloaded xz file and uncompressed file"; - system("rm -vf " . $download_dir . $unz_filename); - system("rm -vf " . $download_dir . $download_filename); - notification('succeeded ✅', $status, $gitea_current_version, $tag); - # Intentionally *not* removing the 'gitea' binary in case something goes wrong running the current binary. + print( RED "[ERROR] ❌ Gitea service is NOT active\nProcess: $gitea_proc_status\nSSH: $gitea_ssh_status\n", RESET ); +} + +######################## +# Notify appropriately # +######################## +if ( !$update_needed && $gitea_status ) { + my $status = '✅ Version tag upstream matches the system version, no update needed. Service is running.'; + print( YELLOW "[INFO] $status\nInstalled version: $gitea_current_version\nUpstream version: $tag\n", RESET ); + notification('not needed ✅', $status, $gitea_current_version, $tag); + exit 1; +} +elsif ( $update_needed && versioncmp( $gitea_current_version, $tag ) == -1 ) { + my $status = '❌ Upstream version tag is STILL greater than the current system version after attempting to update, something went wrong'; + notification('failed ❌', $status, $gitea_current_version, $tag); + print( RED $status, RESET ); +} +elsif ( $update_needed && $gitea_status ) { + my $status = '✅ [INFO] Gitea successfuly updated. Installed version is current and service is running'; + print( GREEN "[INFO] $status\n", RESET ); + say "Removing the downloaded xz file and uncompressed file"; + system("rm -vf " . $download_dir . $unz_filename); + system("rm -vf " . $download_dir . $download_filename); + notification('succeeded ✅', $status, $gitea_current_version, $tag); + # Intentionally *not* removing the 'gitea' binary in case something goes wrong running the current binary. +} +elsif ( !$gitea_status ) { + my $status = q{❌ [DIE] The gitea service is no good!

+ Process: } . $gitea_proc_status . q{

+ SSH Output:
} . $gitea_ssh_status . q{
}; + notification('failed ❌', $status, $gitea_current_version, $tag); + die '❌ [DIE] The gitea service is no good!'; +} +else { + my $status = '❌ [DIE] Unknown update status!'; + print( RED $status, RESET ); + notification('failed ❌', $status, $gitea_current_version, $tag); + die $status; } # ##### Subroutines ##### @@ -155,7 +189,7 @@ sub get_current_binary { my $current_version; if ( $current_version_string =~ m/ion\ (\d+\.\d+\.\d*)\s+b/ ) { $current_version = $1; - printf("Version number of the installed gitea binary: $1\n"); + printf("Version number of the installed gitea binary: $1\n") if defined $verbose; } elsif ( $current_version_string =~ m/ion\ (\d+\d+\w*)\s/ ) { $current_version = $1; @@ -305,8 +339,35 @@ sub install_bin { } sub check_gitea_status { - my $gitea_status = `systemctl is-active gitea`; - return $gitea_status; + my $gitea_status; + my $gitea_proc_status = `systemctl is-active gitea`; + sleep 1; # Otherwise the SSH regex doesnt work; + + my $command = 'ssh -i /home/tracey/.ssh/id_tlc_gitea gitea'; + # DEBUG - induce failure + # my $command = 'ssh -i /home/tracey/.ssh/blerg gitea'; + my ($out, $err, $exit) = capture { system $command }; + + # print "\n---- STDERR: --------------\n"; + # print $err; + # print "\n---- STDOUT: --------------\n"; + # print $out; + # print "\n---- EXIT CODE: -----------\n"; + # print $exit / 256; + # print "\n---------------------------\n"; + my $gitea_ssh_status = $err; + if ($gitea_ssh_status =~ /(successfully)/gm) { + print "Gitea SSH status: $1\n"; + } + + + unless ( ($gitea_proc_status =~ /active/) && ($gitea_ssh_status =~ /successfully/gm) ) { + $gitea_status = 0; + } + if ( ($gitea_proc_status =~ /active/) && ($gitea_ssh_status =~ /successfully/gm) ) { + $gitea_status = 1; + } + return $gitea_status, $gitea_proc_status, $gitea_ssh_status; } sub notification { @@ -315,7 +376,7 @@ sub notification { my $from = 'system@host.tlcnet.info'; my $ver_body; - # print "[TLC DEBUG] Body received is\n$body\n"; + print "[TLC DEBUG] Body received is\n$body\n" if defined $verbose; if ( defined $running_version ) { $ver_body = q{ From a5ab4366ae8660c388658c24d5e3d291c1e461e2 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sun, 4 Sep 2022 16:29:22 -0500 Subject: [PATCH 04/10] Remove deprecated selenium dotfiles dir --- selenium_bash/.bashrc | 120 -------------------------------------- selenium_bash/.profile | 22 ------- selenium_bash/.rootbashrc | 99 ------------------------------- 3 files changed, 241 deletions(-) delete mode 100755 selenium_bash/.bashrc delete mode 100755 selenium_bash/.profile delete mode 100755 selenium_bash/.rootbashrc diff --git a/selenium_bash/.bashrc b/selenium_bash/.bashrc deleted file mode 100755 index 77cbad4..0000000 --- a/selenium_bash/.bashrc +++ /dev/null @@ -1,120 +0,0 @@ -# ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples - -# If not running interactively, don't do anything -case $- in - *i*) ;; - *) return;; -esac - -# don't put duplicate lines or lines starting with space in the history. -# See bash(1) for more options -HISTCONTROL=ignoreboth - -# append to the history file, don't overwrite it -shopt -s histappend - -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# If set, the pattern "**" used in a pathname expansion context will -# match all files and zero or more directories and subdirectories. -#shopt -s globstar - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color|*-256color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -#force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# colored GCC warnings and errors -#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' - -# some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Add an "alert" alias for long running commands. Use like so: -# sleep 10; alert -alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. - -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi - -#List upgradeable packages -apt list --upgradeable diff --git a/selenium_bash/.profile b/selenium_bash/.profile deleted file mode 100755 index c9db459..0000000 --- a/selenium_bash/.profile +++ /dev/null @@ -1,22 +0,0 @@ -# ~/.profile: executed by the command interpreter for login shells. -# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login -# exists. -# see /usr/share/doc/bash/examples/startup-files for examples. -# the files are located in the bash-doc package. - -# the default umask is set in /etc/profile; for setting the umask -# for ssh logins, install and configure the libpam-umask package. -#umask 022 - -# if running bash -if [ -n "$BASH_VERSION" ]; then - # include .bashrc if it exists - if [ -f "$HOME/.bashrc" ]; then - . "$HOME/.bashrc" - fi -fi - -# set PATH so it includes user's private bin if it exists -if [ -d "$HOME/bin" ] ; then - PATH="$HOME/bin:$PATH" -fi diff --git a/selenium_bash/.rootbashrc b/selenium_bash/.rootbashrc deleted file mode 100755 index f6939ee..0000000 --- a/selenium_bash/.rootbashrc +++ /dev/null @@ -1,99 +0,0 @@ -# ~/.bashrc: executed by bash(1) for non-login shells. -# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) -# for examples - -# If not running interactively, don't do anything -[ -z "$PS1" ] && return - -# don't put duplicate lines in the history. See bash(1) for more options -# ... or force ignoredups and ignorespace -HISTCONTROL=ignoredups:ignorespace - -# append to the history file, don't overwrite it -shopt -s histappend - -# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) -HISTSIZE=1000 -HISTFILESIZE=2000 - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# make less more friendly for non-text input files, see lesspipe(1) -[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, unless we know we "want" color) -case "$TERM" in - xterm-color) color_prompt=yes;; -esac - -# uncomment for a colored prompt, if the terminal has the capability; turned -# off by default to not distract the user: the focus in a terminal window -# should be on the output of commands, not on the prompt -#force_color_prompt=yes - -if [ -n "$force_color_prompt" ]; then - if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then - # We have color support; assume it's compliant with Ecma-48 - # (ISO/IEC-6429). (Lack of such support is extremely rare, and such - # a case would tend to support setf rather than setaf.) - color_prompt=yes - else - color_prompt= - fi -fi - -if [ "$color_prompt" = yes ]; then - PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' -else - PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' -fi -unset color_prompt force_color_prompt - -# If this is an xterm set the title to user@host:dir -case "$TERM" in -xterm*|rxvt*) - PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" - ;; -*) - ;; -esac - -# enable color support of ls and also add handy aliases -if [ -x /usr/bin/dircolors ]; then - test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" - alias ls='ls --color=auto' - #alias dir='dir --color=auto' - #alias vdir='vdir --color=auto' - - alias grep='grep --color=auto' - alias fgrep='fgrep --color=auto' - alias egrep='egrep --color=auto' -fi - -# some more ls aliases -alias ll='ls -alF' -alias la='ls -A' -alias l='ls -CF' - -# Alias definitions. -# You may want to put all your additions into a separate file like -# ~/.bash_aliases, instead of adding them here directly. -# See /usr/share/doc/bash-doc/examples in the bash-doc package. - -if [ -f ~/.bash_aliases ]; then - . ~/.bash_aliases -fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then -# . /etc/bash_completion -#fi From f4df252683c3550d015bab73c9bf9a1b2bed8d94 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sun, 4 Sep 2022 16:32:09 -0500 Subject: [PATCH 05/10] Remove deprecated dir --- home_config/.vimrc | 9 --------- home_config/konsole_tabs_colo | 3 --- home_config/ssh_config | 19 ------------------- 3 files changed, 31 deletions(-) delete mode 100755 home_config/.vimrc delete mode 100755 home_config/konsole_tabs_colo delete mode 100755 home_config/ssh_config diff --git a/home_config/.vimrc b/home_config/.vimrc deleted file mode 100755 index fb4b67c..0000000 --- a/home_config/.vimrc +++ /dev/null @@ -1,9 +0,0 @@ - -filetype plugin indent on -" show existing tab with 4 spaces width -set tabstop=4 -" when indenting with '>', use 4 spaces width -set shiftwidth=4 -" On pressing tab, insert 4 spaces -set expandtab -set pastetoggle= #To switch between paste and nopaste modes \ No newline at end of file diff --git a/home_config/konsole_tabs_colo b/home_config/konsole_tabs_colo deleted file mode 100755 index db89b5c..0000000 --- a/home_config/konsole_tabs_colo +++ /dev/null @@ -1,3 +0,0 @@ -# Konsole tabs for colo session -title: Local;; command: /usr/bin/zsh ;; profile: Breeze -title: Colo;; command: ssh cp ;; profile: Mikado diff --git a/home_config/ssh_config b/home_config/ssh_config deleted file mode 100755 index 46f4864..0000000 --- a/home_config/ssh_config +++ /dev/null @@ -1,19 +0,0 @@ -Host cp - HostName cp.tlcnet.info - User root - Port 227 - IdentityFile ~/.ssh/tlc_server -Host pi3root - HostName pi3 - User root - IdentityFile ~/.ssh/tlc_pi3 -Host pi3 - HostName pi3 - User pi - IdentityFile ~/.ssh/tlc_pi3_pi -Host gittea - HostName gitea.tlcnet.info - RSAAuthentication yes -# User git - Port 227 - IdentityFile ~/.ssh/id_tlc_gitea From 5fe9b6b02bf42f30413321e3472e0bfa051e3e6a Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sun, 4 Sep 2022 16:49:11 -0500 Subject: [PATCH 06/10] Updated README after directory cleanup --- README.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c0def5a..5c10552 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,16 @@ -# ZSH Bash and other config files for personal use -# File processing scripts to archive financial files from previous year -## TODO -None \ No newline at end of file +# Various shell utility scripts + +## File processing +Archive financial files from previous year and set up directory structure for current year + +## gitea +Backup and update gitea on the server + +## gnome +Old customizer scripts for gnome + +## nextcloud +WIP - Install all missing needed modules for Nextcloud on a server + +## Other +Utility, scripts to set up a Solus development environment, backup and restore installed packages on Solus From c7b5feb111e8914e9c98d9f36ebb3d10160c0d87 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Sat, 22 Oct 2022 16:13:42 -0500 Subject: [PATCH 07/10] Minor wording update --- gitea/update-gitea.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitea/update-gitea.pl b/gitea/update-gitea.pl index ec013a3..d8cd101 100755 --- a/gitea/update-gitea.pl +++ b/gitea/update-gitea.pl @@ -266,7 +266,7 @@ sub get_download_url { printf( RED "[DEBUG] Array of hashes of the json response for the assets:\n" ); - printf Dumper $asset_resp_array_ref, RESET; + printf Dumper($asset_resp_array_ref), RESET; } foreach my $asset_ref ( @{$asset_resp_array_ref} ) { @@ -356,8 +356,8 @@ sub check_gitea_status { # print $exit / 256; # print "\n---------------------------\n"; my $gitea_ssh_status = $err; - if ($gitea_ssh_status =~ /(successfully)/gm) { - print "Gitea SSH status: $1\n"; + if ($gitea_ssh_status =~ /(successful)/gm) { + print "Gitea SSH connection attempt: $1\n"; } From 12dce591bbcfe3e74c824b6cf997257fe004fcc9 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Mon, 11 Sep 2023 17:21:56 -0500 Subject: [PATCH 08/10] Modularize file processing, small improvements --- file_processing/archive_statements.pl | 94 ++++++--------------------- file_processing/archive_taxes.pl | 5 +- 2 files changed, 23 insertions(+), 76 deletions(-) diff --git a/file_processing/archive_statements.pl b/file_processing/archive_statements.pl index 4368a83..29d4c07 100755 --- a/file_processing/archive_statements.pl +++ b/file_processing/archive_statements.pl @@ -1,87 +1,35 @@ #!/usr/bin/perl -use strict; -use warnings; +use Modern::Perl; +use ProcessDirectories; # Script to archive the financial data from the previous year -use Time::Piece; -use File::Basename; -use File::Find::Rule; -use File::Copy::Recursive qw(dircopy); -use File::DirCompare; use Carp qw( croak ); +# use File::Basename; +# use File::Find::Rule; +# use File::Copy::Recursive qw(dircopy); +# use File::DirCompare; +# use Getopt::Long qw(GetOptionsFromArray); +use Time::Piece qw/localtime/; -my $now = localtime; -my $year = $now->year; -print "Current year: $year\n"; - -# Get year to archive from current year +my $now = localtime; +my $year = $now->year; my $lastyear = $now->add_years(-1)->year; -print("Last year: $lastyear\n"); +print("Current year: $year Last year: $lastyear\n"); # Define and create folders -my $financial_folder = '/home/tracey/Documents/financial/current_year/'; -my $financial_archive_folder = - '/home/tracey/Documents/financial/1_financial_archives/'; -my $lastyear_folder = - $financial_archive_folder . $lastyear . 'FinancialArchives'; -my @folders = - ( $financial_folder, $financial_archive_folder, $lastyear_folder ); +my $financial_folder = '/home/tracey/Documents/financial/current_year/'; +my $financial_archive_folder = '/home/tracey/Documents/financial/1_financial_archives/'; +my $lastyear_folder = $financial_archive_folder . $lastyear . '_FinancialArchives'; -print("Copying current directories to archive folder\n"); -print("From: $financial_folder\n"); -print("To: $lastyear_folder\n"); -dircopy( $financial_folder, $lastyear_folder ) - or croak "Could not copy directories $!"; -# Make sure contents match before we do any Deleting -# croak on errors to guard against data losss -my $same_result = compare_dirs( $financial_folder, $lastyear_folder ); -croak "Error: The folders are not the same!" unless ( $same_result == 1 ); +create_archive_dirs ( $financial_folder, $lastyear_folder ); + +# Make sure contents match before we do any deleting +# croak on errors to guard against data loss +# my $same_result = compare_dirs( $financial_folder, $lastyear_folder ); +croak "Error: The source and destintion folder contents are not the same!" unless ( compare_dirs( $financial_folder, $lastyear_folder ) ); # Delete all files from current year from archive folders # Also delete files from last year in current year folder -delete_dirs( $financial_folder, $lastyear_folder, $year, $lastyear ); +clean_dirs( $financial_folder, $lastyear_folder, $year, $lastyear ); -sub compare_dirs { - my ( $dir1, $dir2 ) = @_; - my $same = 1; - print("Making sure the copy was complete and all files match\n"); - File::DirCompare->compare( - $dir1, $dir2, - sub { - my ( $a, $b ) = @_; - if ( !$b ) { - printf "Only in %s: %s\n", dirname($a), basename($a); - $same = 0; - } - elsif ( !$a ) { - printf "Only in %s: %s\n", dirname($b), basename($b); - $same = 0; - } - else { - print "Files $a and $b differ\n"; - $same = 0; - } - } - ); - print("Diff of directories done\n"); - return $same; -} - -sub delete_dirs { - my ( $new_dir, $old_dir, $curr_year, $last_year ) = @_; - print("Deleting files from current year $curr_year in archives\n"); - print("and files from last year $last_year from current folder\n"); - - my @this_year_files = - File::Find::Rule->file()->name("*$curr_year*")->in($old_dir); - my @last_year_files = - File::Find::Rule->file()->name("*$last_year*")->in($new_dir); - - unlink @this_year_files; - print("Deleted all $curr_year files from the folder for $last_year\n"); - unlink @last_year_files; - print("Deleted all $last_year files from the folder for $curr_year\n"); - - return; -} diff --git a/file_processing/archive_taxes.pl b/file_processing/archive_taxes.pl index a454926..cff31e3 100755 --- a/file_processing/archive_taxes.pl +++ b/file_processing/archive_taxes.pl @@ -1,6 +1,5 @@ #!/usr/bin/perl -use strict; -use warnings; +use Modern::Perl; use Time::Piece; use File::Find::Rule; # find all the subdirectories of a given directory @@ -21,7 +20,7 @@ print("Last year was $lastyear and tax year was $lasttaxyear\n"); # Define and create folders my ( $financial_folder, $financial_archive_folder, $lastyear_folder, $lasttaxyear_folder ); $financial_folder = '/home/tracey/Documents/financial/current_year/'; -$financial_archive_folder = '~/Documents/financial/1_financial_archives/'; +$financial_archive_folder = '/home//Documents/financial/1_financial_archives/'; $lastyear_folder = $financial_archive_folder . $lastyear . 'FinancialArchives'; $lasttaxyear_folder = $financial_archive_folder . $lasttaxyear . 'TaxArchives'; my @folders = ( $financial_folder, $financial_archive_folder, $lastyear_folder, $lasttaxyear_folder ); From 10e3e1f745535d7c087db434eea500fe6033c48b Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Mon, 11 Sep 2023 20:01:15 -0500 Subject: [PATCH 09/10] Reorganize directory --- 05_fuse | 4 - file_processing/README.md | 5 + file_processing/lib/FinancialFileArchiver.pm | 0 file_processing/lib/ProcessDirectories.pm | 125 ++++++ file_processing/t/00-load.t | 14 + file_processing/t/01-subroutines.t | 79 ++++ file_processing/t/02-archive-files.t | 19 + .../t/1_archives/2022_Archives/2002_file-1 | 7 + .../t/1_archives/2022_Archives/2002_file-2 | 5 + .../t/1_archives/2022_Archives/2002_file-3 | 9 + .../t/1_archives/2022_Archives/2003_file-1 | 7 + .../t/1_archives/2022_Archives/2003_file-2 | 8 + file_processing/t/current_year/2002_file-1 | 7 + file_processing/t/current_year/2002_file-2 | 5 + file_processing/t/current_year/2002_file-3 | 9 + file_processing/t/current_year/2003_file-1 | 7 + file_processing/t/current_year/2003_file-2 | 8 + gitea/.gitignore | 13 - gitea/backup-gitea-bin.pl | 44 -- gitea/update-gitea.pl | 416 ------------------ perl_scratch.pl | 13 + bright_up.sh => utility/bright_up.sh | 0 checkPPAs.sh => utility/checkPPAs.sh | 0 check_os.sh => utility/check_os.sh | 0 utility/reset_kde.fish | 29 ++ utility/tx_session.sh | 15 + 26 files changed, 371 insertions(+), 477 deletions(-) delete mode 100755 05_fuse create mode 100644 file_processing/README.md create mode 100644 file_processing/lib/FinancialFileArchiver.pm create mode 100644 file_processing/lib/ProcessDirectories.pm create mode 100644 file_processing/t/00-load.t create mode 100644 file_processing/t/01-subroutines.t create mode 100644 file_processing/t/02-archive-files.t create mode 100644 file_processing/t/1_archives/2022_Archives/2002_file-1 create mode 100644 file_processing/t/1_archives/2022_Archives/2002_file-2 create mode 100644 file_processing/t/1_archives/2022_Archives/2002_file-3 create mode 100644 file_processing/t/1_archives/2022_Archives/2003_file-1 create mode 100644 file_processing/t/1_archives/2022_Archives/2003_file-2 create mode 100644 file_processing/t/current_year/2002_file-1 create mode 100644 file_processing/t/current_year/2002_file-2 create mode 100644 file_processing/t/current_year/2002_file-3 create mode 100644 file_processing/t/current_year/2003_file-1 create mode 100644 file_processing/t/current_year/2003_file-2 delete mode 100644 gitea/.gitignore delete mode 100755 gitea/backup-gitea-bin.pl delete mode 100755 gitea/update-gitea.pl create mode 100755 perl_scratch.pl rename bright_up.sh => utility/bright_up.sh (100%) rename checkPPAs.sh => utility/checkPPAs.sh (100%) rename check_os.sh => utility/check_os.sh (100%) create mode 100755 utility/reset_kde.fish create mode 100755 utility/tx_session.sh diff --git a/05_fuse b/05_fuse deleted file mode 100755 index 0ea1d75..0000000 --- a/05_fuse +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -#Copy this to /etc/pm/sleep.d -#Unmount all sshfs mounts before system goes to sleep so tasks do not refuse to sleep -mount -l -t fuse.sshfs | awk -F " " '{print "fusermount -u " $3}' | bash diff --git a/file_processing/README.md b/file_processing/README.md new file mode 100644 index 0000000..6dea2cc --- /dev/null +++ b/file_processing/README.md @@ -0,0 +1,5 @@ +# archive_statements.pl and archive_taxes.pl + +## Requirements + +cpanm -S File::Find::Rule File::Copy::Recursive File::DirCompare Time::Piece Test2::V0 Test2::Plugin::NoWarnings Modern::Perl \ No newline at end of file diff --git a/file_processing/lib/FinancialFileArchiver.pm b/file_processing/lib/FinancialFileArchiver.pm new file mode 100644 index 0000000..e69de29 diff --git a/file_processing/lib/ProcessDirectories.pm b/file_processing/lib/ProcessDirectories.pm new file mode 100644 index 0000000..61c9e47 --- /dev/null +++ b/file_processing/lib/ProcessDirectories.pm @@ -0,0 +1,125 @@ +package ProcessDirectories; +use Modern::Perl; +# VERSION +# AUTHORITY +# ABSTRACT: Get current subdirectories in current year directory and copy to archive directory +use Carp qw( croak ); +use File::Basename; +use File::Find::Rule; +use File::Copy::Recursive qw(dircopy); +use File::DirCompare; +use Pod::Usage; +# use Time::Piece qw/localtime/; + +sub create_archive_dirs { + my ( $source_dir, $dest_dir ) = @_; + unless ( -d $source_dir ) { + die "Source directory '$source_dir' does not exist, please create it"; + } + + print("Copying current directories to archive folder\n"); + print("From: $source_dir\n"); + print("To: $dest_dir\n"); + dircopy( $source_dir, $dest_dir ) + or croak "Could not copy directories $!"; + + return; +} + +sub compare_dirs { + my ( $dir1, $dir2 ) = @_; + my $same = 1; + print("Making sure all directories and files match between source and destination\n"); + File::DirCompare->compare( + $dir1, $dir2, + sub { + my ( $a, $b ) = @_; + if ( !$b ) { + printf "Only in %s: %s\n", dirname($a), basename($a); + $same = 0; + } + elsif ( !$a ) { + printf "Only in %s: %s\n", dirname($b), basename($b); + $same = 0; + } + else { + print "Files $a and $b differ\n"; + $same = 0; + } + } + ); + return $same; +} + +sub clean_dirs { + my ( $new_dir, $old_dir, $curr_year, $last_year ) = @_; + + my @this_year_files = + File::Find::Rule->file()->name("*$curr_year*")->in($old_dir); + my @last_year_files = + File::Find::Rule->file()->name("*$last_year*")->in($new_dir); + + unlink @this_year_files; + print("Deleted all files for $curr_year from the folder for $last_year\n"); + unlink @last_year_files; + print("Deleted all files for $last_year from the folder for $curr_year\n"); + + return; +} + +1; + +=pod + +=head1 NAME + +ProcessDirectories + +=head1 DESCRIPTION + +Methods for copying and processing a directory of files for the past year and this year + +=head1 SYNOPSIS + + use ProcessDirectories + + create_archive_dirs ( $source_dir, $dest_dir ); + compare_dirs( $source_dir, $dest_dir ); + clean_dirs( $source_dir, $dest_dir, $year, $lastyear ); + +=head1 METHODS + +=head2 +C: Copies the directory structure and contents of a source file to the archive / destination directory. + +=head3 +Usage: + create_archive_dirs( $source_dir, $destination_dir ); + +=head2 +C: Compares the content of two specified directories. Provides feedback on the results. Returns 1 if the source and destination match, 0 otherwise. + +=head3 +Usage: + compare_dirs( $source_dir, $destination_dir ); + +=head2 +C: This method accepts the following parameters: + +=over 4 + +=item source_dir + +=item destination_dir + +=item this_year + +=item last_year + +=back + +=head3 +Usage: + clean_dirs( $source_dir, $destination_dir, 2023, 2022 ); + +=cut \ No newline at end of file diff --git a/file_processing/t/00-load.t b/file_processing/t/00-load.t new file mode 100644 index 0000000..fad0213 --- /dev/null +++ b/file_processing/t/00-load.t @@ -0,0 +1,14 @@ +use Test2::V0; +use Test2::Plugin::Times; +use Test2::Plugin::ExitSummary; +use Test2::Plugin::NoWarnings; +use FindBin qw($Bin); +use lib "$Bin/../lib"; + + +plan(1); +BEGIN { + use ProcessDirectories; + + pass('Module loads correctly.'); +} \ No newline at end of file diff --git a/file_processing/t/01-subroutines.t b/file_processing/t/01-subroutines.t new file mode 100644 index 0000000..74b657d --- /dev/null +++ b/file_processing/t/01-subroutines.t @@ -0,0 +1,79 @@ +use Test2::V0; +use Test2::Plugin::Times; +use Test2::Plugin::ExitSummary; +use Test2::Plugin::NoWarnings; +use FindBin qw($Bin); +use File::Path::Tiny; +use Time::Piece qw/localtime/; + +use lib "$Bin/../lib"; +use ProcessDirectories; + + +plan(2); + +# Preconditions +my $now = localtime; +my $year = $now->year; +my $lastyear = $now->add_years(-1)->year; +diag("Current year: $year Last year: $lastyear\n"); + +## Define and create test source folder +my $current_year_dir = 't/current_year/'; +my $archive_folder = 't/1_archives/'; +my $prev_year_dir = $archive_folder . $lastyear . '_Archives'; +diag("Source test dir $current_year_dir Dest test dir $prev_year_dir"); + +if(!File::Path::Tiny::mk($current_year_dir)) { + die "Could not create test source directory: '$current_year_dir': $!"; +} + +my @test_files = qw( 2003_file-1 2003_file-2 2002_file-1 2002_file-2 2002_file-3 ); +for my $file (@test_files) { + create_file($current_year_dir . '/' . $file); +} + +# Begin testing +ProcessDirectories::create_archive_dirs( $current_year_dir, $prev_year_dir ); +ok( ( -d $prev_year_dir ), "Previous year archive directory was created" ); + + +ok( ProcessDirectories::compare_dirs( $current_year_dir, $prev_year_dir ), "Previous year archive directory contents matches current directory contents" ); + + +# clean_dirs + +# End Testing + +# Cleanup +# if(!File::Path::Tiny::rm($current_year_dir)) { +# die "Could not remove test source directory: '$current_year_dir': $!"; +# } +# if(!File::Path::Tiny::rm($archive_folder)) { +# die "Could not remove test archive directory: '$archive_folder': $!"; +# } + +sub create_file { + my $filepath = shift; + open (my $fh, ">", $filepath) or die "Can't open file '$filepath' for writing: $!"; + + # you can control the range of characters here + my $minimum = 4; + my $range = 16; + my $num_bytes = '100'; + + for (my $bytes = 0; $bytes < $num_bytes; $bytes += 4) { + my $rand = int(rand($range ** 4)); + my $string = ''; + for (1..4) { + $string .= chr($rand % $range + $minimum); + $rand = int($rand / $range); + } + print $fh $string; + } + + close($fh) or warn "Can't close file '$filepath': $!"; + + + return; +} \ No newline at end of file diff --git a/file_processing/t/02-archive-files.t b/file_processing/t/02-archive-files.t new file mode 100644 index 0000000..a4092e6 --- /dev/null +++ b/file_processing/t/02-archive-files.t @@ -0,0 +1,19 @@ +use Modern::Perl; +use Carp qw/carp croak/; + +use Test2::V0; +use Test2::Tools::Subtest qw/subtest_streamed/; +use Test2::Plugin::ExitSummary; +# use Test2::Tools::Exception qw/dies lives/; +use Test2::Plugin::NoWarnings; +# use Cwd qw(cwd); +use File::Path qw(remove_tree make_path); +use Time::Piece qw/localtime/; + +# Order is important +use FindBin qw($Bin); +use lib "$Bin/../lib"; +use ProcessDirectories; + +use File::Temp qw/ tempfile tempdir /; + diff --git a/file_processing/t/1_archives/2022_Archives/2002_file-1 b/file_processing/t/1_archives/2022_Archives/2002_file-1 new file mode 100644 index 0000000..31f5985 --- /dev/null +++ b/file_processing/t/1_archives/2022_Archives/2002_file-1 @@ -0,0 +1,7 @@ +  +     +       + + +    +       \ No newline at end of file diff --git a/file_processing/t/1_archives/2022_Archives/2002_file-2 b/file_processing/t/1_archives/2022_Archives/2002_file-2 new file mode 100644 index 0000000..cd4e7d2 --- /dev/null +++ b/file_processing/t/1_archives/2022_Archives/2002_file-2 @@ -0,0 +1,5 @@ +    +   +     +   +   \ No newline at end of file diff --git a/file_processing/t/1_archives/2022_Archives/2002_file-3 b/file_processing/t/1_archives/2022_Archives/2002_file-3 new file mode 100644 index 0000000..77a727f --- /dev/null +++ b/file_processing/t/1_archives/2022_Archives/2002_file-3 @@ -0,0 +1,9 @@ +   +    +   +    + + +  +    +  \ No newline at end of file diff --git a/file_processing/t/1_archives/2022_Archives/2003_file-1 b/file_processing/t/1_archives/2022_Archives/2003_file-1 new file mode 100644 index 0000000..a40fba6 --- /dev/null +++ b/file_processing/t/1_archives/2022_Archives/2003_file-1 @@ -0,0 +1,7 @@ +     +  + +        + + +       \ No newline at end of file diff --git a/file_processing/t/1_archives/2022_Archives/2003_file-2 b/file_processing/t/1_archives/2022_Archives/2003_file-2 new file mode 100644 index 0000000..77d1d77 --- /dev/null +++ b/file_processing/t/1_archives/2022_Archives/2003_file-2 @@ -0,0 +1,8 @@ +     +    +   +   + +   +      + \ No newline at end of file diff --git a/file_processing/t/current_year/2002_file-1 b/file_processing/t/current_year/2002_file-1 new file mode 100644 index 0000000..31f5985 --- /dev/null +++ b/file_processing/t/current_year/2002_file-1 @@ -0,0 +1,7 @@ +  +     +       + + +    +       \ No newline at end of file diff --git a/file_processing/t/current_year/2002_file-2 b/file_processing/t/current_year/2002_file-2 new file mode 100644 index 0000000..cd4e7d2 --- /dev/null +++ b/file_processing/t/current_year/2002_file-2 @@ -0,0 +1,5 @@ +    +   +     +   +   \ No newline at end of file diff --git a/file_processing/t/current_year/2002_file-3 b/file_processing/t/current_year/2002_file-3 new file mode 100644 index 0000000..77a727f --- /dev/null +++ b/file_processing/t/current_year/2002_file-3 @@ -0,0 +1,9 @@ +   +    +   +    + + +  +    +  \ No newline at end of file diff --git a/file_processing/t/current_year/2003_file-1 b/file_processing/t/current_year/2003_file-1 new file mode 100644 index 0000000..a40fba6 --- /dev/null +++ b/file_processing/t/current_year/2003_file-1 @@ -0,0 +1,7 @@ +     +  + +        + + +       \ No newline at end of file diff --git a/file_processing/t/current_year/2003_file-2 b/file_processing/t/current_year/2003_file-2 new file mode 100644 index 0000000..77d1d77 --- /dev/null +++ b/file_processing/t/current_year/2003_file-2 @@ -0,0 +1,8 @@ +     +    +   +   + +   +      + \ No newline at end of file diff --git a/gitea/.gitignore b/gitea/.gitignore deleted file mode 100644 index de6a3b3..0000000 --- a/gitea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -**/.vscode -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -!.vscode/*.code-snippets - -# Local History for Visual Studio Code -.history/ - -# Built Visual Studio Code Extensions -*.vsix diff --git a/gitea/backup-gitea-bin.pl b/gitea/backup-gitea-bin.pl deleted file mode 100755 index eb106d6..0000000 --- a/gitea/backup-gitea-bin.pl +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/perl - -# backup_gitea_bin.pl -# Author: Tracey Clark -# Created: 2019-06-20 -# You must have a mail transport agent installed to run this script - -use strict; -use warnings; - -### TEST CODE ### -my $gitea_bin='/home/tracey/tmp/testbin'; -my $gitea_current_version='1'; -my %binary_file = ( - input => $gitea_bin, - version => $gitea_current_version, - ); - my ( %opts ) = %binary_file; - my $input = $opts{input}; - my $version = $opts{version}; - my $gitea_bin_backup = '/home/tracey/tmp/testbin.' . $gitea_current_version . '.bz2'; - -### TEST CODE ### -# my ( %opts ) = %{shift()}; -# my $input = $opts{input}; -# my $version = $opts{version}; -printf("Backing up the current binary\n"); -printf("Input in backup_bin script is $input\n and version is $version\n"); - - -# my $gitea_bin_backup = '/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2'; -printf("Gitea bin backup will be $gitea_bin_backup\n"); -# Do this with a system call to make a compressed copy of the current binary -# bzip2 -k file.txt -# my $status = system("vi", "fred.txt"); -# if (($status >>=8) != 0) { -# die "Failed to run vi"; -# } - -# HEREHERE how to specify output file?? -my $bzip_status = system("/bin/bzip2 -k $input"); -if (($bzip_status >>=8) != 0) { - die "Failed to run bzip2"; -} diff --git a/gitea/update-gitea.pl b/gitea/update-gitea.pl deleted file mode 100755 index d8cd101..0000000 --- a/gitea/update-gitea.pl +++ /dev/null @@ -1,416 +0,0 @@ -#!/usr/bin/perl - -# Update gitea based on version provided -# Author: Tracey Clark -# Created: 2019-03-04 -# You must have a mail transport agent installed to run this script - -# Note: Daily backups are also being run from cron -# /home/gitea/gitea_backup.sh - -# Re-write to use this dir according to gitea docs -# https://docs.gitea.io/en-us/install-from-binary/ -# Get binary from system rather than hard code -# Stop gitea with systemctl before file copy -# Set right mod & perms? - -use strict; -use warnings; -use LWP::UserAgent; -use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error); -use File::Basename; -use JSON; -use Sort::Versions; -use Getopt::Long qw(GetOptions); -use Term::ANSIColor qw(:constants); -use feature qw(say); -use MIME::Lite; -use utf8; -use open ':std', ':encoding(UTF-8)'; -use Encode qw(encode encode_utf8 ); -# use Net::SSH qw(sshopen2); -use Capture::Tiny qw(capture); - -my ( $verbose, $info ); - -GetOptions( - 'info!' => \$info, - 'verbose!' => \$verbose, -); - -########################################## -### The user must set these variables ### -my $email = 'gitea-update@tlcnet.info'; -my $filetype = '-linux-amd64'; -my $download_dir = '/home/gitea/bin/'; -########################################## - -my $update_needed = 0; - -################################### -# Get version currently installed # -################################### -# https://api.github.com/repos/go-gitea/gitea/releases/latest -# This URL will only have one version listed -my $gitea_bin_dir = '/usr/local/bin/'; -my $gitea_bin = $gitea_bin_dir . '/gitea'; -my $gitea_current_version_string = `$gitea_bin --version`; -my $alphanum_ver = 0; -chomp $gitea_current_version_string; -unless ( defined $gitea_current_version_string ) { - my $status = "❌ [DIE]: Unable to get the version of the gitea binary on the system: $!"; - notification('failed ❌', $status); - die RED "$status", RESET; -} -my %binary_file = get_current_binary($gitea_current_version_string); -my $gitea_current_version = $binary_file{'version'}; - -###################################### -# Check upstream version and get tag # -###################################### -my $baseURL = q{https://github.com/go-gitea/gitea/}; -my $latestURL = q{https://api.github.com/repos/go-gitea/gitea/releases/latest}; - -# https://hubpages.com/technology/Use-Perl-to-access-REST-API -# Spin up the browser object -my $ua = LWP::UserAgent->new( - cookie_jar => {}, # keep cookies in RAM but not persistent between sessions -); - -my $resp = $ua->get($latestURL); -my $latest_release_hash = decode_json( $resp->content ) - or die "[DIE]: Unable to parse the version data! Output is:\n $resp"; - -my $orig_tag = $latest_release_hash->{tag_name}; -print "[TLC DEBUG]: ORIG TAG is $orig_tag\n" if defined $verbose; -my $tag = $orig_tag; -substr( $tag, 0, 1, '' ); -my $release_id = $latest_release_hash->{id}; # Works - -################ -# Set filename # -################ -my $unz_filename = 'gitea-' . $tag . $filetype; -#ex: gitea-1.7.6-linux-amd64 -my $download_filename = $unz_filename . '.xz'; - -if ( defined $verbose ) { - printf( YELLOW - "[INFO] Latest upstream version: $tag\n Release ID $release_id\n", RESET); - printf( YELLOW - "[INFO]\nRelease id: $release_id\nUncompressed filename: $unz_filename\nDownload file target: $download_filename\n", RESET - ); -} - -############################################# -# Check if upstream is newer than installed # -############################################# -if ( versioncmp( $gitea_current_version, $tag ) == -1 ) { - $update_needed = 1; - printf( - "[INFO] Version tag is greater than the system version, proceeding with update\n" - ); - backup_bin( \%binary_file ); - - my $download_url = get_download_url( $download_filename, $release_id ); - print("Downloading the compressed binary\n"); - print("[INFO] Download URL we got from the sub is $download_url\n"); - `wget -P $download_dir $download_url`; - my $xz_file = $download_dir . $download_filename; - - if ( defined $info ) { - print YELLOW "[INFO] xz file is $xz_file\n", RESET; - } - install_bin($download_filename); -} - -################################## -# Get service status and version # -################################## -my ($gitea_status, $gitea_proc_status, $gitea_ssh_status) = check_gitea_status(); -$gitea_current_version_string = `$gitea_bin --version`; -chomp $gitea_current_version_string; -%binary_file = get_current_binary($gitea_current_version_string); -$gitea_current_version = $binary_file{'version'}; - -if ( $gitea_status ) { - print( GREEN "[INFO] ✅ Gitea service is active\n", RESET ); -} -else { - print( RED "[ERROR] ❌ Gitea service is NOT active\nProcess: $gitea_proc_status\nSSH: $gitea_ssh_status\n", RESET ); -} - -######################## -# Notify appropriately # -######################## -if ( !$update_needed && $gitea_status ) { - my $status = '✅ Version tag upstream matches the system version, no update needed. Service is running.'; - print( YELLOW "[INFO] $status\nInstalled version: $gitea_current_version\nUpstream version: $tag\n", RESET ); - notification('not needed ✅', $status, $gitea_current_version, $tag); - exit 1; -} -elsif ( $update_needed && versioncmp( $gitea_current_version, $tag ) == -1 ) { - my $status = '❌ Upstream version tag is STILL greater than the current system version after attempting to update, something went wrong'; - notification('failed ❌', $status, $gitea_current_version, $tag); - print( RED $status, RESET ); -} -elsif ( $update_needed && $gitea_status ) { - my $status = '✅ [INFO] Gitea successfuly updated. Installed version is current and service is running'; - print( GREEN "[INFO] $status\n", RESET ); - say "Removing the downloaded xz file and uncompressed file"; - system("rm -vf " . $download_dir . $unz_filename); - system("rm -vf " . $download_dir . $download_filename); - notification('succeeded ✅', $status, $gitea_current_version, $tag); - # Intentionally *not* removing the 'gitea' binary in case something goes wrong running the current binary. -} -elsif ( !$gitea_status ) { - my $status = q{❌ [DIE] The gitea service is no good!

- Process: } . $gitea_proc_status . q{

- SSH Output:
} . $gitea_ssh_status . q{
}; - notification('failed ❌', $status, $gitea_current_version, $tag); - die '❌ [DIE] The gitea service is no good!'; -} -else { - my $status = '❌ [DIE] Unknown update status!'; - print( RED $status, RESET ); - notification('failed ❌', $status, $gitea_current_version, $tag); - die $status; -} - -# ##### Subroutines ##### - -# sub check_deps { -# # Check to make sure dependencies installed on system - unit test?? -# # bzip2 perl mods -# } - -sub get_current_binary { - my $current_version_string = shift; - my $current_version; - if ( $current_version_string =~ m/ion\ (\d+\.\d+\.\d*)\s+b/ ) { - $current_version = $1; - printf("Version number of the installed gitea binary: $1\n") if defined $verbose; - } - elsif ( $current_version_string =~ m/ion\ (\d+\d+\w*)\s/ ) { - $current_version = $1; - printf("Current version number the installed gitea binary: $1\n"); - $alphanum_ver = 1; - } - my %binary_file = ( - input => $gitea_bin, - version => $current_version, - ); - unless ( defined $current_version ) { - die RED - "[DIE]: Unable to get the current gitea version! Value is $current_version", - RESET; - } - return %binary_file; -} - -sub get_binary_file { - my $version = shift; -} - -sub backup_bin { - - # Ghetto to get it working for now - - my (%opts) = %{ shift() }; - my $input = $opts{input}; - my $version = $opts{version}; - print GREEN "Backing up the current binary\n", RESET; - if ( defined $info ) { - print YELLOW - "[INFO] Input in backup_bin sub is:\n Directory $input\n Version $version\n", - RESET; - } - my $gitea_bin_backup = - '/home/gitea/bin/gitea.' . $gitea_current_version . '.bz2'; - print GREEN "Gitea bin backup will be $gitea_bin_backup\n", RESET; - system("cp $input $input.bak"); - - # TODO - # # Do this with a system call to make a compressed copy of the current binary - # # bzip2 -k file.txt - # # my $status = system("vi", "fred.txt"); - # # if (($status >>=8) != 0) { - # # die "[DIE] Failed to run vi"; - # # } - # my $bzip_status = system("bzip2 -k", "$input"); - # if (($status >>=8) != 0) { - # die "[DIE] Failed to run bzip2"; - # } - - return; -} - -sub get_download_url { - my ( $dl_filename, $rel_id ) = @_; - my $dl_url; - - # Get the download_url from the array - my $assetsURL = - 'https://api.github.com/repos/go-gitea/gitea/releases/' - . $release_id - . '/assets'; - if ( defined $info ) { - print YELLOW "[INFO] Assets URL\n"; - print "$assetsURL\n", RESET; - } - - my $asset_resp = $ua->get($assetsURL); - my $asset_resp_array_ref = decode_json( $asset_resp->content ); - - if ( defined $verbose ) { - printf( RED - "[DEBUG] Array of hashes of the json response for the assets:\n" - ); - printf Dumper($asset_resp_array_ref), RESET; - } - - foreach my $asset_ref ( @{$asset_resp_array_ref} ) { - if ( defined $verbose ) { - print( RED - "[DEBUG] The asset ref in get_download_url is $asset_ref\n" ); - print( - "The asset ref name in get_download_url is $asset_ref->{name}\n", - RESET - ); - } - if ( $asset_ref->{name} eq $dl_filename ) { - print("Yay we have a match for our desired file :D and it is \n"); - print $asset_ref->{name} . "\n"; - $dl_url = $asset_ref->{browser_download_url}; - if ( defined $info ) { - print YELLOW - "[INFO] The download url from the response array is $dl_url\n", - RESET; - } - return $dl_url; - } - } - unless ( defined $dl_url ) { - print( RED - "ONOES we have no download URL from the github API! Trying to build one manually\n", - RESET - ); - my $dl_url = build_download_url( $orig_tag, $download_filename ); - return $dl_url; - } - return 0; -} - -sub build_download_url { - my ( $url_tag, $url_file ) = @_; - print "Building the URL based on the version\n"; - -# If getting the download URL fails through the API, use this to build it manually -# URL is in the form of -# https://github.com/go-gitea/gitea/releases/download/v1.15.2/gitea-1.15.2-linux-amd64.xz - my $built_url = - 'https://github.com/go-gitea/gitea/releases/download/' - . $url_tag . '/' - . $url_file; - if ( defined $info ) { - print YELLOW "The URL built for the download is $built_url\n", RESET; - } - return $built_url; -} - -sub install_bin { - my $filename = shift; - print("Unpacking the downloaded file \"$download_dir$filename\", setting owner and permissions\n"); - my $unpacked_filename = basename($filename, ".xz"); - print "Unpacked filename is $unpacked_filename\n"; - - # Copy the downloaded binary to gitea and chmod it 750 - # Doing this with a filthy system call because the perl library - # for xz manipulation is a memory hog and buggy besides - system("xz -d --keep $download_dir" . "/" . "$filename"); - system("systemctl stop gitea"); - system("cp $download_dir$unpacked_filename $gitea_bin"); - system("chown gitea.gitea $gitea_bin"); - system("chmod 750 $gitea_bin"); - - # Restart service - print("[INFO] Restarting the gitea service\n"); - return system("systemctl restart gitea"); -} - -sub check_gitea_status { - my $gitea_status; - my $gitea_proc_status = `systemctl is-active gitea`; - sleep 1; # Otherwise the SSH regex doesnt work; - - my $command = 'ssh -i /home/tracey/.ssh/id_tlc_gitea gitea'; - # DEBUG - induce failure - # my $command = 'ssh -i /home/tracey/.ssh/blerg gitea'; - my ($out, $err, $exit) = capture { system $command }; - - # print "\n---- STDERR: --------------\n"; - # print $err; - # print "\n---- STDOUT: --------------\n"; - # print $out; - # print "\n---- EXIT CODE: -----------\n"; - # print $exit / 256; - # print "\n---------------------------\n"; - my $gitea_ssh_status = $err; - if ($gitea_ssh_status =~ /(successful)/gm) { - print "Gitea SSH connection attempt: $1\n"; - } - - - unless ( ($gitea_proc_status =~ /active/) && ($gitea_ssh_status =~ /successfully/gm) ) { - $gitea_status = 0; - } - if ( ($gitea_proc_status =~ /active/) && ($gitea_ssh_status =~ /successfully/gm) ) { - $gitea_status = 1; - } - return $gitea_status, $gitea_proc_status, $gitea_ssh_status; -} - -sub notification { - my ($result, $body, $running_version, $upstream_version) = @_; - my $subject = "Gitea update check: update " . $result; - my $from = 'system@host.tlcnet.info'; - my $ver_body; - - print "[TLC DEBUG] Body received is\n$body\n" if defined $verbose; - - if ( defined $running_version ) { - $ver_body = q{ - - - - - - - - - - - -
Running version:} . $running_version . q{
Upstream version:} . $upstream_version . q{
} - } - - my $msg = MIME::Lite->new( - Subject => encode( 'MIME-Header', $subject ), - From => $from, - To => $email, - Type => 'text/html', - Data => encode_utf8( - ' -

Gitea update result

-

' . $body . '

' . $ver_body . - '
-

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

-

Sincerely,
Your Linode VM

- ' - ) - ); - - $msg->send(); - - return 1; -} diff --git a/perl_scratch.pl b/perl_scratch.pl new file mode 100755 index 0000000..68d4bc4 --- /dev/null +++ b/perl_scratch.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl + +use Modern::Perl; +use DateTime; + +say "Date Time formatting tests"; + +my $dt_now = DateTime->now( time_zone => 'local' ); +say "Datetime now is $dt_now"; +my $date = $dt_now->ymd(''); +# yymmdd_hhmmss +my $dt = $date . '_' . $dt_now->hms(''); +say "Datetime is $dt"; \ No newline at end of file diff --git a/bright_up.sh b/utility/bright_up.sh similarity index 100% rename from bright_up.sh rename to utility/bright_up.sh diff --git a/checkPPAs.sh b/utility/checkPPAs.sh similarity index 100% rename from checkPPAs.sh rename to utility/checkPPAs.sh diff --git a/check_os.sh b/utility/check_os.sh similarity index 100% rename from check_os.sh rename to utility/check_os.sh diff --git a/utility/reset_kde.fish b/utility/reset_kde.fish new file mode 100755 index 0000000..61323b1 --- /dev/null +++ b/utility/reset_kde.fish @@ -0,0 +1,29 @@ +#!/usr/bin/fish +# Initial folder list from https://tuxtrix.com/reset-kde5-user-config-default/ + +if string length -q $HOME + echo "Backup up $HOME/.config" + cp -a $HOME/.config $HOME/.config.bak + cd $HOME/.config + + echo "Deleting KDE config files" + set fileList Trolltech.conf akregatorrc baloofilerc bluedevilglobalrc kactivitymanagerd-statsrc + set -a fileList kactivitymanagerdrc kactivitymanagerd-pluginsrc kateschemarc kcmfonts kcminputrc kconf_updaterc kded5rc + set -a fileList kdeglobals kfontinstuirc kglobalshortcutsrc khotkeysrc kmixctrlrc kmixrc + set -a fileList kscreenlockerrc ksmserverrc ksplashrc ktimezonedrc kwinrc kwinrulesrc plasma-localerc + set -a fileList plasma-nm plasma-org.kde.plasma.desktop-appletsrc plasmarc plasmashellrc + set -a fileList powermanagementprofilesrc startupconfig startupconfigfiles startupconfigkeys + set -a fileList krunnerrc touchpadxlibinputrc systemsettingsrc kxkbrc PlasmaUserFeedback + set -a fileList kde.org/* kiorc klipperrc knfsshare kuriikwsfilterrc kwalletmanager5rc kwalletrc + set -a fileList plasma.emojierrc plasmanotifyrc PlasmaUserFeedback powerdevilrc kgammarc + set -a fileList kded_device_automounterrc device_automounter_kcmrc klaunchrc + set -a fileList trashrc kactivitymanagerd-switcher gtkrc-2.0 gtkrc baloofileinformationrc + set -a fileList plasmaparc plasmawindowed-appletsrc plasmawindowedrc + + set -a fileList breezerc + + rm $fileList +else + echo "HOME variable not defined" + exit +end diff --git a/utility/tx_session.sh b/utility/tx_session.sh new file mode 100755 index 0000000..7a558e0 --- /dev/null +++ b/utility/tx_session.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +go() { + session="$1" + sessions_dir="$HOME/tilix_profiles" + tilix_opts='' + + for session in "$sessions_dir/$session/"*; do + tilix_opts="$tilix_opts -s $session" + done + + tilix $tilix_opts +} + +go $@ \ No newline at end of file From 30a09ff809c40b61734e417f10d5af0296eb4927 Mon Sep 17 00:00:00 2001 From: Tracey Clark Date: Mon, 11 Sep 2023 20:16:52 -0500 Subject: [PATCH 10/10] Update README --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5c10552..cd43066 100755 --- a/README.md +++ b/README.md @@ -2,9 +2,6 @@ ## File processing Archive financial files from previous year and set up directory structure for current year - -## gitea -Backup and update gitea on the server ## gnome Old customizer scripts for gnome @@ -12,5 +9,10 @@ Old customizer scripts for gnome ## nextcloud WIP - Install all missing needed modules for Nextcloud on a server +## utility +Miscellaneous scripts, e.g. set screen brightness from command line (bug workaround) + ## Other -Utility, scripts to set up a Solus development environment, backup and restore installed packages on Solus +* Backup and restore scripts for packages installed on Solus OS +* Set up a Solus OS development environment (update needed) +* Backup and restore scripts for Linux systems