forked from EESSI/software-layer-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_scripts.sh
More file actions
executable file
·185 lines (158 loc) · 5.52 KB
/
install_scripts.sh
File metadata and controls
executable file
·185 lines (158 loc) · 5.52 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
#
# Script to install scripts from the software-layer repo into the EESSI software stack
display_help() {
echo "usage: $0 [OPTIONS]"
echo " -p | --prefix - prefix to copy the scripts to"
echo " -h | --help - display this usage information"
}
file_changed_in_pr() {
local full_path="$1"
# Make sure file exists
[[ -f "$full_path" ]] || return 1
# Check if the file is in a Git repo (it should be)
local repo_root
repo_root=$(git -C "$(dirname "$full_path")" rev-parse --show-toplevel 2>/dev/null)
if [[ -z "$repo_root" ]]; then
return 2 # Not in a git repository
fi
# Compute relative path to the repo root
local rel_path
rel_path=$(realpath --relative-to="$repo_root" "$full_path")
# Check if the file changed in the PR diff file that we have
(
cd "$repo_root" || return 2
# $PR_DIFF should be set by the calling script
if [[ ! -z ${PR_DIFF} ]] && [[ -f "$PR_DIFF" ]]; then
grep -q "b/$rel_path" "$PR_DIFF" # Add b/ to match diff patterns
else
return 3
fi
) && return 0 || return 1
}
compare_and_copy() {
if [ "$#" -ne 2 ]; then
echo "Usage of function: compare_and_copy <source_file> <destination_file>"
return 1
fi
source_file="$1"
destination_file="$2"
if [ ! -f "$destination_file" ] || ! diff -q "$source_file" "$destination_file" ; then
echo "Files $source_file and $destination_file differ, checking if we should copy or not"
# We only copy if the file is part of the PR
if file_changed_in_pr "$source_file"; then
echo "File has changed in the PR"
cp "$source_file" "$destination_file"
echo "File $source_file copied to $destination_file"
else
case $? in
1) echo "❌ File has NOT changed in PR" ;;
2) echo "🚫 Not in Git repository" ;;
3) echo "🚫 No PR diff file found" ;;
*) echo "⚠️ Unknown error" ;;
esac
fi
else
echo "Files $1 and $2 are identical. No copy needed."
fi
}
copy_files_by_list() {
# Compares and copies listed files from a source to a target directory
if [ ! "$#" -ge 3 ]; then
echo "Usage of function: copy_files_by_list <source_dir> <destination_dir> <file_list>"
echo "Here, file_list is an (expanded) bash array"
echo "Example:"
echo "my_files=(file1 file2)"
echo 'copy_files_by_list /my/source /my/target "${my_files[@]}"'
return 1
fi
source_dir="$1"
target_dir="$2"
# Need to shift all arguments to the left twice. Then, rebuild the array with the rest of the arguments
shift
shift
file_list=("$@")
# Create target dir
mkdir -p ${target_dir}
# Copy from source to target
echo "Copying files: ${file_list[@]}"
echo "From directory: ${source_dir}"
echo "To directory: ${target_dir}"
for file in ${file_list[@]}; do
compare_and_copy ${source_dir}/${file} ${target_dir}/${file}
done
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
-p|--prefix)
INSTALL_PREFIX="$2"
shift 2
;;
-h|--help)
display_help # Call your function
# no shifting needed here, we're done.
exit 0
;;
-*|--*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
POSITIONAL_ARGS+=("$1") # save positional arg
shift
;;
esac
done
set -- "${POSITIONAL_ARGS[@]}"
TOPDIR=$(dirname $(realpath $0))
# Copy for init directory
init_files=(
bash eessi_archdetect.sh eessi_defaults eessi_environment_variables eessi_software_subdir_for_host.py
minimal_eessi_env README.md test.py lmod_eessi_archdetect_wrapper.sh lmod_eessi_archdetect_wrapper_accel.sh
)
copy_files_by_list ${TOPDIR}/init ${INSTALL_PREFIX}/init "${init_files[@]}"
# Copy for the init/arch_specs directory
arch_specs_files=(
eessi_arch_arm.spec eessi_arch_ppc.spec eessi_arch_riscv.spec eessi_arch_x86.spec
)
copy_files_by_list ${TOPDIR}/init/arch_specs ${INSTALL_PREFIX}/init/arch_specs "${arch_specs_files[@]}"
# Copy for init/Magic_castle directory
mc_files=(
bash eessi_python3
)
copy_files_by_list ${TOPDIR}/init/Magic_Castle ${INSTALL_PREFIX}/init/Magic_Castle "${mc_files[@]}"
# Copy for init/modules/EESSI directory
mc_files=(
2023.06.lua
)
copy_files_by_list ${TOPDIR}/init/modules/EESSI ${INSTALL_PREFIX}/init/modules/EESSI "${mc_files[@]}"
# Copy for init/lmod directory
init_script_files=(
bash zsh ksh fish csh
)
copy_files_by_list ${TOPDIR}/init/lmod ${INSTALL_PREFIX}/init/lmod "${init_script_files[@]}"
# Copy for the scripts directory
script_files=(
utils.sh
)
copy_files_by_list ${TOPDIR}/scripts ${INSTALL_PREFIX}/scripts "${script_files[@]}"
# Copy files for the scripts/gpu_support/nvidia directory
nvidia_files=(
install_cuda_and_libraries.sh
install_cuda_host_injections.sh
link_nvidia_host_libraries.sh
)
copy_files_by_list ${TOPDIR}/scripts/gpu_support/nvidia ${INSTALL_PREFIX}/scripts/gpu_support/nvidia "${nvidia_files[@]}"
# Easystacks to be used to install software in host injections
host_injections_easystacks=(
eessi-2023.06-eb-4.9.4-2023a-CUDA-host-injections.yml
eessi-2023.06-eb-4.9.4-2023b-CUDA-host-injections.yml
)
copy_files_by_list ${TOPDIR}/scripts/gpu_support/nvidia/easystacks \
${INSTALL_PREFIX}/scripts/gpu_support/nvidia/easystacks "${host_injections_easystacks[@]}"
# Copy over EasyBuild hooks file used for installations
hook_files=(
eb_hooks.py
)
copy_files_by_list ${TOPDIR} ${INSTALL_PREFIX}/init/easybuild "${hook_files[@]}"