forked from EESSI/software-layer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_scripts.sh
executable file
·81 lines (67 loc) · 2.32 KB
/
install_scripts.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
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
#!/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"
}
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
cp "$source_file" "$destination_file"
echo "File $1 copied to $2"
else
echo "Files $1 and $2 are identical. No copy needed."
fi
}
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))
# Subdirs for generic scripts
SCRIPTS_DIR_SOURCE=${TOPDIR}/scripts # Source dir
SCRIPTS_DIR_TARGET=${INSTALL_PREFIX}/scripts # Target dir
# Create target dir
mkdir -p ${SCRIPTS_DIR_TARGET}
# Copy scripts into this prefix
echo "copying scripts from ${SCRIPTS_DIR_SOURCE} to ${SCRIPTS_DIR_TARGET}"
for file in utils.sh; do
compare_and_copy ${SCRIPTS_DIR_SOURCE}/${file} ${SCRIPTS_DIR_TARGET}/${file}
done
# Subdirs for GPU support
NVIDIA_GPU_SUPPORT_DIR_SOURCE=${SCRIPTS_DIR_SOURCE}/gpu_support/nvidia # Source dir
NVIDIA_GPU_SUPPORT_DIR_TARGET=${SCRIPTS_DIR_TARGET}/gpu_support/nvidia # Target dir
# Create target dir
mkdir -p ${NVIDIA_GPU_SUPPORT_DIR_TARGET}
# Copy files from this directory into the prefix
# To be on the safe side, we dont do recursive copies, but we are explicitely copying each individual file we want to add
echo "copying scripts from ${NVIDIA_GPU_SUPPORT_DIR_SOURCE} to ${NVIDIA_GPU_SUPPORT_DIR_TARGET}"
for file in install_cuda_host_injections.sh link_nvidia_host_libraries.sh; do
compare_and_copy ${NVIDIA_GPU_SUPPORT_DIR_SOURCE}/${file} ${NVIDIA_GPU_SUPPORT_DIR_TARGET}/${file}
done