Skip to content

Commit 11b4c6b

Browse files
author
marcofilho
committed
base: add actual sha256sum checking.
Compare SHA-256 hash sum for each downloaded archive file against previously known SHA-256 values to ensure files are what they are supposed to be. This impacts how new modules are introduced, as they are required to define the expected SHA-256 along with the installation procedure, preferably on the adequade *_versions.sh files.
1 parent 06f9e67 commit 11b4c6b

File tree

8 files changed

+85
-37
lines changed

8 files changed

+85
-37
lines changed

base/install-functions.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ download_from_github() {
1515
github_org=$1
1616
module_name=$2
1717
commit=$3
18+
sha=$4
1819

19-
lnls-get-n-unpack -l https://github.com/$github_org/$module_name/archive/$commit.tar.gz
20+
lnls-get-n-unpack -l https://github.com/$github_org/$module_name/archive/$commit.tar.gz $sha
2021

2122
# GitHub tarballs for tags starting with 'v' don't include that 'v'
2223
commit=${commit#v}
@@ -66,7 +67,8 @@ install_from_github() {
6667
dependency_name=$3
6768
tag=$4
6869
release_content="$5"
70+
sha=$6
6971

70-
download_from_github $github_org $module_name $tag
72+
download_from_github $github_org $module_name $tag $sha
7173
install_module $flag_ioc $module_name $dependency_name "$release_content"
7274
}

base/install_area_detector.sh

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

105105
cd ..
106106

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

@@ -113,4 +113,5 @@ EPICS_BASE
113113
ASYN
114114
AREA_DETECTOR
115115
ADCORE
116-
"
116+
" \
117+
$NDSSCPIMEGA_SHA256

base/install_cagateway.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ set -ex
77

88
install_from_github epics-modules pcas PCAS $PCAS_VERSION "
99
EPICS_BASE
10-
"
10+
" \
11+
$PCAS_SHA256
1112

1213
install_from_github epics-extensions ca-gateway CA_GATEWAY $CA_GATEWAY_VERSION "
1314
EPICS_BASE
1415
PCAS
1516
CAPUTLOG
16-
"
17+
" \
18+
$CA_GATEWAY_SHA256

base/install_epics.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -ex
55
. $EPICS_IN_DOCKER/install-functions.sh
66
. $EPICS_IN_DOCKER/epics_versions.sh
77

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

1111
patch -d ${EPICS_BASE_PATH} -Np1 < $EPICS_IN_DOCKER/epics-base-static-linking.patch

base/install_modules.sh

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ set -ex
77

88
install_from_github epics-base pvxs PVXS $PVXS_VERSION "
99
EPICS_BASE
10-
"
10+
" \
11+
$PVXS_SHA256
1112

12-
download_from_github epics-base p4p $P4P_VERSION
13+
download_from_github epics-base p4p $P4P_VERSION $P4P_SHA256
1314
echo PYTHON=python3 >> p4p/configure/CONFIG_SITE
1415
install_module p4p P4P "
1516
EPICS_BASE
@@ -19,44 +20,52 @@ echo 'python3*/linux*/' > p4p/.lnls-keep-paths
1920

2021
install_from_github epics-modules sequencer SNCSEQ $SEQUENCER_VERSION "
2122
EPICS_BASE
22-
"
23+
" \
24+
$SEQUENCER_SHA256
2325

2426
install_from_github epics-modules calc CALC $CALC_VERSION "
2527
EPICS_BASE
26-
"
28+
" \
29+
$CALC_SHA256
2730

2831
# Build asyn without seq since it's only needed for testIPServer
2932
install_from_github epics-modules asyn ASYN $ASYN_VERSION "
3033
EPICS_BASE
3134
CALC
32-
"
35+
" \
36+
$ASYN_SHA256
3337

3438
install_from_github epics-modules modbus MODBUS $MODBUS_VERSION "
3539
EPICS_BASE
3640
ASYN
37-
"
41+
" \
42+
$MODBUS_SHA256
3843

3944
install_from_github paulscherrerinstitute StreamDevice STREAM $STREAMDEVICE_VERSION "
4045
EPICS_BASE
4146
ASYN
4247
CALC
43-
"
48+
" \
49+
$STREAMDEVICE_SHA256
4450

4551
install_from_github epics-modules busy BUSY $BUSY_VERSION "
4652
EPICS_BASE
4753
ASYN
48-
"
54+
" \
55+
$BUSY_SHA256
4956

5057
install_from_github epics-modules autosave AUTOSAVE $AUTOSAVE_VERSION "
5158
EPICS_BASE
52-
"
59+
" \
60+
$AUTOSAVE_SHA256
5361

5462
install_from_github epics-modules sscan SSCAN $SSCAN_VERSION "
5563
EPICS_BASE
5664
SNCSEQ
57-
"
65+
" \
66+
$SSCAN_SHA256
5867

59-
download_from_github ChannelFinder recsync $RECCASTER_VERSION
68+
download_from_github ChannelFinder recsync $RECCASTER_VERSION $RECCASTER_SHA256
6069
mv recsync recsync-root
6170
mv recsync-root/client recsync
6271
rm -r recsync-root
@@ -66,35 +75,39 @@ EPICS_BASE
6675

6776
install_from_github epics-modules ipac IPAC $IPAC_VERSION "
6877
EPICS_BASE
69-
"
78+
" \
79+
$IPAC_SHA256
7080

71-
download_from_github epics-modules caPutLog $CAPUTLOG_VERSION
81+
download_from_github epics-modules caPutLog $CAPUTLOG_VERSION $CAPUTLOG_SHA256
7282
patch -d caPutLog -Np1 < $EPICS_IN_DOCKER/caputlog-waveform-fix.patch
7383
install_module caPutLog CAPUTLOG "
7484
EPICS_BASE
7585
"
7686

7787
install_from_github brunoseivam retools RETOOLS $RETOOLS_VERSION "
7888
EPICS_BASE
79-
"
89+
" \
90+
$RETOOLS_SHA256
8091

8192
install_from_github -i epics-modules ether_ip ETHER_IP $ETHER_IP_VERSION "
8293
EPICS_BASE
83-
"
94+
" \
95+
$ETHER_IP_SHA256
8496

8597
install_from_github epics-modules iocStats DEVIOCSTATS $IOCSTATS_VERSION "
8698
EPICS_BASE
87-
"
99+
" \
100+
$IOCSTATS_SHA256
88101

89-
download_from_github slac-epics-modules ipmiComm $IPMICOMM_VERSION
102+
download_from_github slac-epics-modules ipmiComm $IPMICOMM_VERSION $IPMICOMM_SHA256
90103
patch -d ipmiComm -Np1 < $EPICS_IN_DOCKER/backport-ipmicomm.patch
91104
patch -d ipmiComm -Np1 < $EPICS_IN_DOCKER/ipmicomm.patch
92105
JOBS=1 install_module ipmiComm IPMICOMM "
93106
EPICS_BASE
94107
ASYN
95108
"
96109

97-
download_from_github mdavidsaver pyDevSup $PYDEVSUP_VERSION
110+
download_from_github mdavidsaver pyDevSup $PYDEVSUP_VERSION $PYDEVSUP_SHA256
98111
echo PYTHON=python3 >> pyDevSup/configure/CONFIG_SITE
99112
install_module pyDevSup PYDEVSUP "
100113
EPICS_BASE
@@ -103,7 +116,8 @@ echo 'python3*/linux*/' > pyDevSup/.lnls-keep-paths
103116

104117
mkdir snmp
105118
cd snmp
106-
lnls-get-n-unpack -l https://groups.nscl.msu.edu/controls/files/epics-snmp-$SNMP_VERSION.zip
119+
lnls-get-n-unpack -l https://groups.nscl.msu.edu/controls/files/epics-snmp-$SNMP_VERSION.zip \
120+
$SNMP_SHA256
107121
cd ..
108122
install_module -i snmp SNMP "
109123
EPICS_BASE
@@ -112,7 +126,8 @@ EPICS_BASE
112126
install_from_github epics-modules scaler SCALER $SCALER_VERSION "
113127
EPICS_BASE
114128
ASYN
115-
"
129+
" \
130+
$SCALER_SHA256
116131

117132
install_from_github -i epics-modules mca MCA $MCA_VERSION "
118133
EPICS_BASE
@@ -124,9 +139,10 @@ SNCSEQ
124139
AUTOSAVE
125140
ASYN
126141
MCA
127-
"
142+
" \
143+
$MCA_SHA256
128144

129-
download_from_github ISISComputingGroup EPICS-lakeshore $LAKESHORE_VERSION
145+
download_from_github ISISComputingGroup EPICS-lakeshore $LAKESHORE_VERSION $LAKESHORE_SHA256
130146
mv EPICS-lakeshore/lakeshore336 .
131147
rm -r EPICS-lakeshore
132148
install_module lakeshore336 LAKESHORE "
@@ -138,4 +154,5 @@ EPICS_BASE
138154
ASYN
139155
CALC
140156
STREAM
141-
"
157+
" \
158+
$LAKESHORE340_SHA256

base/install_motor.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ SNCSEQ
5555

5656
cd $EPICS_MODULES_PATH
5757

58-
download_from_github dls-controls pmac $PMAC_VERSION
58+
download_from_github dls-controls pmac $PMAC_VERSION $PMAC_SHA256
5959

6060
rm pmac/configure/RELEASE.local.linux-x86_64
6161
rm pmac/configure/RELEASE.linux-x86_64.Common
@@ -80,7 +80,7 @@ MOTOR
8080
BUSY
8181
"
8282

83-
download_from_github cnpem motorParker $PARKER_VERSION
83+
download_from_github cnpem motorParker $PARKER_VERSION $PARKER_SHA256
8484
install_module motorParker MOTOR_PARKER "
8585
EPICS_BASE
8686
ASYN

base/install_opcua.sh

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

99
opcua_release_url=https://github.com/epics-modules/opcua/releases/download/v${OPCUA_VERSION}
1010
opcua_release_file=BDIST_opcua-${OPCUA_VERSION}_Base-${EPICS_BASE_VERSION}_debian${DEBIAN_VERSION%.*}.tar.gz
11-
lnls-get-n-unpack -l $opcua_release_url/$opcua_release_file
11+
lnls-get-n-unpack -l $opcua_release_url/$opcua_release_file $OPCUA_SHA256
1212
rm HOW_TO.md
1313

1414
mv opcuaBinaryDist opcua-module

base/lnls-get-n-unpack.sh

Lines changed: 30 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>...]\n"
9+
echo -e "Usage: lnls-get-n-unpack <extraction_mode> <URL1> <SHA256SUM1> [<URL2> <SHA256SUM2> ...]\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
parse_arguments() {
@@ -21,6 +23,7 @@ parse_arguments() {
2123
help
2224
fi
2325

26+
# Check extraction mode
2427
case "$1" in
2528
-r) dest=/ ;;
2629
-l) dest=. ;;
@@ -29,26 +32,49 @@ parse_arguments() {
2932
;;
3033
esac
3134

35+
# Check if we have odd number of arguments (extraction_mode + N*url + N*sha256sum)
36+
if [ $(( $# % 2 )) -ne 1 ]; then
37+
>&2 echo "ERROR: Even number of arguments detected. Something is wrong."
38+
help 1
39+
fi
40+
3241
echo "$dest ${@:2}" # Throw extraction mode argument away
3342
}
3443

44+
shacheck() {
45+
downloaded_file=$1
46+
sha=$2
47+
url=$3
48+
49+
if ! echo $sha $downloaded_file | sha256sum -c; then
50+
echo "ERROR: SHA $sha for URL $url does not match."
51+
exit 1
52+
fi
53+
}
54+
3555
download () {
3656
dest=$1
3757
shift
3858

39-
for url; do
59+
while [[ $# -gt 1 ]]; do
60+
url=$1
61+
sha=$2
4062
download_dir=$(mktemp -d)
4163
echo Downloading "$url"...
4264
wget -P $download_dir "$url" &> /tmp/wget.log || (cat /tmp/wget.log && false)
43-
4465
filename=$(basename $download_dir/*)
66+
67+
shacheck $download_dir/$filename $sha $url
68+
4569
if [[ ${filename,,} == *".zip" ]]; then
4670
unzip -qo $download_dir/$filename -d $dest
4771
else
4872
tar --no-same-owner -xf $download_dir/$filename -C $dest
4973
fi
5074

5175
rm -rf $download_dir /tmp/wget.log
76+
77+
shift 2
5278
done
5379
}
5480

0 commit comments

Comments
 (0)