Skip to content

Commit c513928

Browse files
author
marcofilho
committed
base: add actual sha256sum checking.
lnls-get-n-unpack now uses all variables defined in .env file as arguments: - shacheck function checks the hashes. - Download function now iterates through pairs of arguments to get url and hash for each module. - Help function describes this usage and can now exit with error code as argument. install_epics, install_opcua, install_area_detector, install_modules and install_motor: - pass variables defined in .env as arguments to lnls-get-n-unpack and install_from_github. install_functions: - Add sha as argument to install_from_github and download_from_github. install_from_github passes sha as argument to download_from_github.
1 parent 65767ca commit c513928

File tree

7 files changed

+84
-31
lines changed

7 files changed

+84
-31
lines changed

base/install-functions.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ download_from_github() {
1010
github_org=$1
1111
module_name=$2
1212
commit=$3
13+
sha=$4
1314

14-
lnls-get-n-unpack -l https://github.com/$github_org/$module_name/archive/$commit.tar.gz
15+
lnls-get-n-unpack -l https://github.com/$github_org/$module_name/archive/$commit.tar.gz $sha
1516

1617
mv $module_name-$commit $module_name
1718
}
@@ -59,7 +60,8 @@ install_from_github() {
5960
dependency_name=$3
6061
tag=$4
6162
release_content="$5"
63+
sha=$6
6264

63-
download_from_github $github_org $module_name $tag
65+
download_from_github $github_org $module_name $tag $sha
6466
install_module $flag_ioc $module_name $dependency_name "$release_content"
6567
}

base/install_area_detector.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ make clean
103103

104104
cd ..
105105

106-
download_from_github cnpem ssc-pimega $LIBSSCPIMEGA_VERSION
106+
download_from_github cnpem ssc-pimega $LIBSSCPIMEGA_VERSION $LIBSSCPIMEGA_SHA256
107107
make -C ssc-pimega/c install
108108
rm -rf ssc-pimega
109109

@@ -112,4 +112,5 @@ EPICS_BASE
112112
ASYN
113113
AREA_DETECTOR
114114
ADCORE
115-
"
115+
" \
116+
$NDSSCPIMEGA_SHA256

base/install_epics.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -ex
44

55
. /opt/epics/install-functions.sh
66

7-
lnls-get-n-unpack -l https://epics-controls.org/download/base/base-${EPICS_BASE_VERSION}.tar.gz
7+
lnls-get-n-unpack -l https://epics-controls.org/download/base/base-${EPICS_BASE_VERSION}.tar.gz $EPICS_BASE_SHA256
88
mv base-${EPICS_BASE_VERSION} ${EPICS_BASE_PATH}
99

1010
patch -d ${EPICS_BASE_PATH} -Np1 < backport-epics-base-musl.patch

base/install_modules.sh

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,91 +6,105 @@ set -ex
66

77
install_from_github mdavidsaver pvxs PVXS $PVXS_VERSION "
88
EPICS_BASE
9-
"
9+
" \
10+
$PVXS_SHA256
1011

1112
install_from_github epics-modules sequencer SNCSEQ $SEQUENCER_VERSION "
1213
EPICS_BASE
13-
"
14+
" \
15+
$SEQUENCER_SHA256
1416

1517
install_from_github epics-modules calc CALC $CALC_VERSION "
1618
EPICS_BASE
17-
"
19+
" \
20+
$CALC_SHA256
1821

1922
# Build asyn without seq since it's only needed for testIPServer
2023
install_from_github epics-modules asyn ASYN $ASYN_VERSION "
2124
EPICS_BASE
2225
CALC
23-
"
26+
" \
27+
$ASYN_SHA256
2428

2529
install_from_github epics-modules modbus MODBUS $MODBUS_VERSION "
2630
EPICS_BASE
2731
ASYN
28-
"
32+
" \
33+
$MODBUS_SHA256
2934

3035
install_from_github paulscherrerinstitute StreamDevice STREAM $STREAMDEVICE_VERSION "
3136
EPICS_BASE
3237
ASYN
3338
CALC
34-
"
39+
" \
40+
$STREAMDEVICE_SHA256
3541

3642
install_from_github epics-modules busy BUSY $BUSY_VERSION "
3743
EPICS_BASE
3844
ASYN
39-
"
45+
" \
46+
$BUSY_SHA256
4047

4148
install_from_github epics-modules autosave AUTOSAVE $AUTOSAVE_VERSION "
4249
EPICS_BASE
43-
"
50+
" \
51+
$AUTOSAVE_SHA256
4452

4553
install_from_github epics-modules sscan SSCAN $SSCAN_VERSION "
4654
EPICS_BASE
4755
SNCSEQ
48-
"
56+
" \
57+
$SSCAN_SHA256
4958

50-
download_from_github ChannelFinder recsync $RECCASTER_VERSION
59+
download_from_github ChannelFinder recsync $RECCASTER_VERSION $RECCASTER_SHA256
5160
install_module recsync/client RECCASTER "
5261
EPICS_BASE
5362
"
5463

5564
install_from_github epics-modules ipac IPAC $IPAC_VERSION "
5665
EPICS_BASE
57-
"
66+
" \
67+
$IPAC_SHA256
5868

59-
download_from_github epics-modules caPutLog $CAPUTLOG_VERSION
69+
download_from_github epics-modules caPutLog $CAPUTLOG_VERSION $CAPUTLOG_SHA256
6070
patch -d caPutLog -Np1 < caputlog-waveform-fix.patch
6171
install_module caPutLog CAPUTLOG "
6272
EPICS_BASE
6373
"
6474

6575
install_from_github brunoseivam retools RETOOLS $RETOOLS_VERSION "
6676
EPICS_BASE
67-
"
77+
" \
78+
$RETOOLS_SHA256
6879

6980
install_from_github -i epics-modules ether_ip ETHER_IP $ETHER_IP_VERSION "
7081
EPICS_BASE
71-
"
82+
" \
83+
$ETHER_IP_SHA256
7284

7385
install_from_github epics-modules iocStats DEVIOCSTATS $IOCSTATS_VERSION "
7486
EPICS_BASE
75-
"
87+
" \
88+
$IOCSTATS_SHA256
7689

77-
download_from_github slac-epics-modules ipmiComm $IPMICOMM_VERSION
90+
download_from_github slac-epics-modules ipmiComm $IPMICOMM_VERSION $IPMICOMM_SHA256
7891
patch -d ipmiComm -Np1 < backport-ipmicomm.patch
7992
patch -d ipmiComm -Np1 < ipmicomm.patch
8093
JOBS=1 install_module ipmiComm IPMICOMM "
8194
EPICS_BASE
8295
ASYN
8396
"
8497

85-
download_from_github mdavidsaver pyDevSup $PYDEVSUP_VERSION
98+
download_from_github mdavidsaver pyDevSup $PYDEVSUP_VERSION $PYDEVSUP_SHA256
8699
echo PYTHON=python3 >> pyDevSup/configure/CONFIG_SITE
87100
install_module pyDevSup PYDEVSUP "
88101
EPICS_BASE
89102
"
90103

91104
mkdir snmp
92105
cd snmp
93-
lnls-get-n-unpack -l https://groups.nscl.msu.edu/controls/files/epics-snmp-$SNMP_VERSION.zip
106+
lnls-get-n-unpack -l https://groups.nscl.msu.edu/controls/files/epics-snmp-$SNMP_VERSION.zip \
107+
$SNMP_SHA256
94108
cd ..
95109
install_module -i snmp SNMP "
96110
EPICS_BASE
@@ -99,7 +113,8 @@ EPICS_BASE
99113
install_from_github epics-modules scaler SCALER $SCALER_VERSION "
100114
EPICS_BASE
101115
ASYN
102-
"
116+
" \
117+
$SCALER_SHA256
103118

104119
install_from_github -i epics-modules mca MCA $MCA_VERSION "
105120
EPICS_BASE
@@ -111,4 +126,5 @@ SNCSEQ
111126
AUTOSAVE
112127
ASYN
113128
MCA
114-
"
129+
" \
130+
$MCA_SHA256

base/install_motor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ SNCSEQ
5454

5555
cd $EPICS_MODULES_PATH
5656

57-
download_from_github dls-controls pmac $PMAC_VERSION
57+
download_from_github dls-controls pmac $PMAC_VERSION $PMAC_SHA256
5858

5959
rm pmac/configure/RELEASE.local.linux-x86_64
6060
rm pmac/configure/RELEASE.linux-x86_64.Common

base/install_opcua.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -ex
66

77
opcua_release_url=https://github.com/epics-modules/opcua/releases/download/v${OPCUA_VERSION}
88
opcua_release_file=IOC_opcua-${OPCUA_VERSION}_Base-${EPICS_BASE_VERSION}_debian${DEBIAN_VERSION%.*}.tar.gz
9-
lnls-get-n-unpack -l $opcua_release_url/$opcua_release_file
9+
lnls-get-n-unpack -l $opcua_release_url/$opcua_release_file $OPCUA_SHA256
1010

1111
mv binaryOpcuaIoc opcua
1212
install_module -i opcua OPCUA "

base/lnls-get-n-unpack.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ set -eu
66

77
help () {
88
echo "lnls-get-n-unpack: download and extract archive from the network"
9-
echo -e "Usage: lnls-get-n-unpack <extraction_mode> <URL1> [URL2] [...] [URLN]\n"
9+
echo -e "Usage: lnls-get-n-unpack <extraction_mode> <URL1> <1SHA256SUM> [URL2] [2SHA256SUM] [...] [URLN] [NSHA256SUM]\n"
1010
echo "Extraction mode:"
1111
echo " -l extracts to local directory (./)"
1212
echo " -r extracts to root directory (/)"
1313
echo "URL:"
1414
echo " url to download source from."
15-
exit 0
15+
echo "SHA256SUM:"
16+
echo " Reference sha256 hash to compare url download with."
17+
exit $1
1618
}
1719

1820
check_arguments() {
@@ -25,10 +27,11 @@ check_arguments() {
2527
# if -h is anywhere arguments list, call help and exit.
2628
for arg in "$@"; do
2729
if [ "$arg" == "-h" ] || [ "$arg" == "--help" ]; then
28-
help
30+
help 0
2931
fi
3032
done
3133

34+
# Check extraction mode
3235
case "$1" in
3336
-r) dest=/ ;;
3437
-l) dest=. ;;
@@ -37,19 +40,48 @@ check_arguments() {
3740
;;
3841
esac
3942

43+
# Check if we have odd number of arguments (extraction_mode + N*url + N*sha256sum)
44+
if [ $(( $# % 2 )) -ne 1 ]; then
45+
>&2 echo "ERROR: Even number of arguments detected. Something is wrong."
46+
help 1
47+
fi
48+
49+
}
50+
51+
shacheck() {
52+
53+
download_dir=$1
54+
sha=$2
55+
url=$3
56+
57+
downloaded_file=$(find $download_dir -type f)
58+
if [[ $(echo $downloaded_file | wc -w) -ne 1 ]]; then
59+
echo "ERROR: Download of $url is yielding something different than one single file."
60+
echo "Don't know how to proceed. Exiting..."
61+
exit 1
62+
fi
63+
64+
if ! echo $sha $downloaded_file | sha256sum -c; then
65+
echo "ERROR: SHA $sha for URL $url does not match."
66+
exit 1
67+
fi
68+
4069
}
4170

4271
download () {
4372

4473
shift # Throw extraction mode argument away
4574

46-
for url; do
75+
while [[ $# -gt 1 ]]; do
76+
url=$1
77+
sha=$2
4778
download_dir=$(mktemp -d)
4879

4980
echo Downloading "$url"...
5081
wget -P $download_dir "$url" &> /tmp/wget.log || (cat /tmp/wget.log && false)
5182

5283
filename=$(basename $download_dir/*)
84+
shacheck $download_dir $sha $url
5385

5486
if [[ ${filename,,} == *".zip" ]]; then
5587
unzip -qo $download_dir/$filename -d $dest
@@ -58,6 +90,8 @@ download () {
5890
fi
5991

6092
rm -rf $download_dir /tmp/wget.log
93+
94+
shift 2
6195
done
6296

6397
}

0 commit comments

Comments
 (0)