-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapptainer_binman.sh
45 lines (35 loc) · 1.06 KB
/
apptainer_binman.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# apptainer_binman.sh
# B.Pietras Nov '24.
# creates bashscripts to replicate binaries inside an apptainer image
# Needs 'template.txt' in pwd
if [[ ! -f ./template.txt ]]; then
echo "template.txt not found! Exiting."
exit 1
fi
# Load the below before running script:
module load apps/apptainer/1.3.0
bins=$(mktemp)
template=$(mktemp)
tempo=$(mktemp)
cat template.txt >$template
trap 'rm -rf "$bins" "$template" "$tempo"; exit' ERR EXIT
read -p "Enter /path/to/name.sif: " sif
read -p "Enter exectable path inside sif: " binpath
echo
apptainer exec $sif ls -1 $binpath >$bins
readarray -t bin_array <$bins
# This "THE_SIF" needs to be set in the module file
sif_caps=$(echo $sif | rev | cut -d '/' -f1 | rev | cut -d '.' -f1 | tr '[:lower:]' '[:upper:]')
sif_caps="${sif_caps}_SIF"
if [ ! -d ./bins ]; then
mkdir -p ./bins
fi
for bin in "${bin_array[@]}"; do
# echo $bin
cat $template | sed -e "s|THE_SIF|${sif_caps}|g" -e "s|binpath|${binpath}\/${bin}|g" >$tempo
cat $tempo >bins/"$bin"
echo 'bins/'$bin' created'
done
chmod +x bins/*
echo -e '\nDone!'