Skip to content

Instantly share code, notes, and snippets.

@jesusbagpuss
jesusbagpuss / z_apache_log_username.pl
Created February 27, 2024 15:18
EPrints: Add user to Apache request object so it gets logged in Apache access logfile (as %u).
# ADD THIS FILE TO e.g. [EPRINT_ROOT]/archives/[ARCHIVE_ID]/cfg/cfg.d/
#
# Add username to Apache Request object so it gets added to Apache access.log file
# NB This will not cause the username to be logged in the EPrints access dataset.
use EPrints::Const;
$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {
my( %args ) = @_;
my( $r, $repo ) = @args{qw( request repository )};
@jesusbagpuss
jesusbagpuss / JLRS_remap_eprint_divisions
Created June 29, 2023 11:11
EPrints - update division field values
#!/usr/bin/perl -w
##########################################################################
#
# Save this into [EPRINTS_ROOT]/bin/local/JLRS_remap_eprint_divisions
# ...or adjust the 'use lib' line below in relation to where you've saved it.
#
##########################################################################
use FindBin;
@jesusbagpuss
jesusbagpuss / jlrs_plugin_test
Created June 15, 2023 12:14
Test an EPrints Plugin
#!/usr/bin/perl -w
# Save this file in an EPrints installation - at [EPRINTS_ROOT]/bin/local/jlrs_plugin_test
#
# Run it with the following params:
# - archiveid
# - pluginid (e.g. Stats::Handler)
# - (optional) method_to_call
#
@jesusbagpuss
jesusbagpuss / z_rewrite_url_map.pl
Created February 15, 2023 15:34
Add to EPRINTS_ROOT/archives/ARCHIVE_ID/cfg/cfg.d/
# Map specific URLs to be permanently redirected
use EPrints::Const; # for trigger return values
# define specific URLs that have been moved.
# If all the new URLs are to the same base URL, you could have e.g 1234 => 5678 in the
# hash, and prepend a static 'https://new.repo.com/' in the 'Location' line below
$c->{z_url_rewrite_map} = {
'1234' => 'https://abc.de/1/',
@jesusbagpuss
jesusbagpuss / fix_language
Created January 17, 2023 09:20
Check all EPrints, and all documents, and set language
#!/usr/bin/perl -w
### the 'use lib' line assumes the scipt is saved into [EPRINTS_ROOT]/bin/local/
### If the script is saved in another location, please update that line accordingly.
use FindBin;
use lib "$FindBin::Bin/../../perl_lib";
use EPrints;
use strict;
@jesusbagpuss
jesusbagpuss / test_eprint_debug
Created December 15, 2022 10:40
Debug / analysis of getting data from an EPrint DataObj
#!/usr/bin/perl -w
# Save this into ~/bin/local/
# or alter line 7 below! ;)
use FindBin;
use lib "$FindBin::Bin/../../perl_lib";
use EPrints;
use Data::Dumper;
@jesusbagpuss
jesusbagpuss / z_creation_date.pl
Created December 1, 2022 09:04
EPrints field to get creation date
# Return this datestamp from the first history item of this record - the creation date.
#
# requires https://bazaar.eprints.org/452/1/plugins/EPrints/MetaField/Virtualwithvalue.pm
# (and some phrases)
$c->add_dataset_field( "eprint",
{
name => 'creation_date',
type => 'virtualwithvalue',
virtual => 1,
@jesusbagpuss
jesusbagpuss / perl-modules-github-actions-ubuntu-runner.md
Last active August 20, 2022 17:44 — forked from JJ/perl-modules-github-actions-ubuntu-runner.md
List of Perl modules installed in the Github action runner 'ubuntu-latest' (2022-08-20)

Here's the list of modules installed in the Ubuntu-latest runner for Github actions. They've been obtained using a script that list all modules installed: perl -MFile::Find=find -MFile::Spec::Functions -Tlw -e 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'

There were three directories in `@INC' that didn't exist:

  • /usr/local/lib/x86_64-linux-gnu/perl/5.30.0
  • /usr/local/share/perl/5.30.0
  • /usr/local/lib/site_perl

/usr/lib/x86_64-linux-gnu/perl5/5.30/ directory

@jesusbagpuss
jesusbagpuss / delete_user
Created March 24, 2022 16:49
Script to delete EPrint users
#!/usr/bin/perl -w
# NB This file is designed to be saved as [EPRINTS_ROOT]/bin/local/delete_user
# If you want to save it elsewhere, the 'FindBin' on line 52 may need altering.
=pod
=head1 NAME
B<delete_user> - Removes an EPrints user account
@jesusbagpuss
jesusbagpuss / z_url_rewrite_redir.pl
Last active March 14, 2022 15:33
EPrints redirect specific URLs
use EPrints::Const;
my %rewrite_map = (
123 => 'https://other.site/321',
456 => 'https://else.where/stuff-999',
);
$c->add_trigger( EP_TRIGGER_URL_REWRITE, sub {
my( %o ) = @_;