Skip to content

Commit 7e8b171

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 2360cbd commit 7e8b171

File tree

8 files changed

+67
-38
lines changed

8 files changed

+67
-38
lines changed

base/install-functions.sh

Lines changed: 5 additions & 3 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}
@@ -65,8 +66,9 @@ install_from_github() {
6566
module_name=$2
6667
dependency_name=$3
6768
tag=$4
68-
release_content="$5"
69+
sha=$5
70+
release_content="$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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ 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

111-
install_from_github cnpem NDSSCPimega NDSSCPIMEGA $NDSSCPIMEGA_VERSION "
111+
install_from_github cnpem NDSSCPimega NDSSCPIMEGA $NDSSCPIMEGA_VERSION $NDSSCPIMEGA_SHA256 "
112112
EPICS_BASE
113113
ASYN
114114
AREA_DETECTOR

base/install_cagateway.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ set -ex
55
. $EPICS_IN_DOCKER/install-functions.sh
66
. $EPICS_IN_DOCKER/cagateway_versions.sh
77

8-
install_from_github epics-modules pcas PCAS $PCAS_VERSION "
8+
install_from_github epics-modules pcas PCAS $PCAS_VERSION $PCAS_SHA256 "
99
EPICS_BASE
1010
"
1111

12-
install_from_github epics-extensions ca-gateway CA_GATEWAY $CA_GATEWAY_VERSION "
12+
install_from_github epics-extensions ca-gateway CA_GATEWAY $CA_GATEWAY_VERSION $CA_GATEWAY_SHA256 "
1313
EPICS_BASE
1414
PCAS
1515
CAPUTLOG

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: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,96 +5,96 @@ set -ex
55
. $EPICS_IN_DOCKER/install-functions.sh
66
. $EPICS_IN_DOCKER/modules_versions.sh
77

8-
install_from_github epics-base pvxs PVXS $PVXS_VERSION "
8+
install_from_github epics-base pvxs PVXS $PVXS_VERSION $PVXS_SHA256 "
99
EPICS_BASE
1010
"
1111

12-
download_from_github epics-base p4p $P4P_VERSION
12+
download_from_github epics-base p4p $P4P_VERSION $P4P_SHA256
1313
echo PYTHON=python3 >> p4p/configure/CONFIG_SITE
1414
install_module p4p P4P "
1515
EPICS_BASE
1616
PVXS
1717
"
1818
echo 'python3*/linux*/' > p4p/.lnls-keep-paths
1919

20-
install_from_github epics-modules sequencer SNCSEQ $SEQUENCER_VERSION "
20+
install_from_github epics-modules sequencer SNCSEQ $SEQUENCER_VERSION $SEQUENCER_SHA256 "
2121
EPICS_BASE
2222
"
2323

24-
install_from_github epics-modules calc CALC $CALC_VERSION "
24+
install_from_github epics-modules calc CALC $CALC_VERSION $CALC_SHA256 "
2525
EPICS_BASE
2626
"
2727

2828
# Build asyn without seq since it's only needed for testIPServer
29-
install_from_github epics-modules asyn ASYN $ASYN_VERSION "
29+
install_from_github epics-modules asyn ASYN $ASYN_VERSION $ASYN_SHA256 "
3030
EPICS_BASE
3131
CALC
3232
"
3333

34-
install_from_github epics-modules modbus MODBUS $MODBUS_VERSION "
34+
install_from_github epics-modules modbus MODBUS $MODBUS_VERSION $MODBUS_SHA256 "
3535
EPICS_BASE
3636
ASYN
3737
"
3838

39-
install_from_github paulscherrerinstitute StreamDevice STREAM $STREAMDEVICE_VERSION "
39+
install_from_github paulscherrerinstitute StreamDevice STREAM $STREAMDEVICE_VERSION $STREAMDEVICE_SHA256 "
4040
EPICS_BASE
4141
ASYN
4242
CALC
4343
"
4444

45-
install_from_github epics-modules busy BUSY $BUSY_VERSION "
45+
install_from_github epics-modules busy BUSY $BUSY_VERSION $BUSY_SHA256 "
4646
EPICS_BASE
4747
ASYN
4848
"
4949

50-
install_from_github epics-modules autosave AUTOSAVE $AUTOSAVE_VERSION "
50+
install_from_github epics-modules autosave AUTOSAVE $AUTOSAVE_VERSION $AUTOSAVE_SHA256 "
5151
EPICS_BASE
5252
"
5353

54-
install_from_github epics-modules sscan SSCAN $SSCAN_VERSION "
54+
install_from_github epics-modules sscan SSCAN $SSCAN_VERSION $SSCAN_SHA256 "
5555
EPICS_BASE
5656
SNCSEQ
5757
"
5858

59-
download_from_github ChannelFinder recsync $RECCASTER_VERSION
59+
download_from_github ChannelFinder recsync $RECCASTER_VERSION $RECCASTER_SHA256
6060
mv recsync recsync-root
6161
mv recsync-root/client recsync
6262
rm -r recsync-root
6363
install_module recsync RECCASTER "
6464
EPICS_BASE
6565
"
6666

67-
install_from_github epics-modules ipac IPAC $IPAC_VERSION "
67+
install_from_github epics-modules ipac IPAC $IPAC_VERSION $IPAC_SHA256 "
6868
EPICS_BASE
6969
"
7070

71-
download_from_github epics-modules caPutLog $CAPUTLOG_VERSION
71+
download_from_github epics-modules caPutLog $CAPUTLOG_VERSION $CAPUTLOG_SHA256
7272
patch -d caPutLog -Np1 < $EPICS_IN_DOCKER/caputlog-waveform-fix.patch
7373
install_module caPutLog CAPUTLOG "
7474
EPICS_BASE
7575
"
7676

77-
install_from_github brunoseivam retools RETOOLS $RETOOLS_VERSION "
77+
install_from_github brunoseivam retools RETOOLS $RETOOLS_VERSION $RETOOLS_SHA256 "
7878
EPICS_BASE
7979
"
8080

81-
install_from_github -i epics-modules ether_ip ETHER_IP $ETHER_IP_VERSION "
81+
install_from_github -i epics-modules ether_ip ETHER_IP $ETHER_IP_VERSION $ETHER_IP_SHA256 "
8282
EPICS_BASE
8383
"
8484

85-
install_from_github epics-modules iocStats DEVIOCSTATS $IOCSTATS_VERSION "
85+
install_from_github epics-modules iocStats DEVIOCSTATS $IOCSTATS_VERSION $IOCSTATS_SHA256 "
8686
EPICS_BASE
8787
"
8888

89-
download_from_github slac-epics-modules ipmiComm $IPMICOMM_VERSION
89+
download_from_github slac-epics-modules ipmiComm $IPMICOMM_VERSION $IPMICOMM_SHA256
9090
patch -d ipmiComm -Np1 < $EPICS_IN_DOCKER/backport-ipmicomm.patch
9191
patch -d ipmiComm -Np1 < $EPICS_IN_DOCKER/ipmicomm.patch
9292
JOBS=1 install_module ipmiComm IPMICOMM "
9393
EPICS_BASE
9494
ASYN
9595
"
9696

97-
download_from_github mdavidsaver pyDevSup $PYDEVSUP_VERSION
97+
download_from_github mdavidsaver pyDevSup $PYDEVSUP_VERSION $PYDEVSUP_SHA256
9898
echo PYTHON=python3 >> pyDevSup/configure/CONFIG_SITE
9999
install_module pyDevSup PYDEVSUP "
100100
EPICS_BASE
@@ -103,18 +103,19 @@ echo 'python3*/linux*/' > pyDevSup/.lnls-keep-paths
103103

104104
mkdir snmp
105105
cd snmp
106-
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
107108
cd ..
108109
install_module -i snmp SNMP "
109110
EPICS_BASE
110111
"
111112

112-
install_from_github epics-modules scaler SCALER $SCALER_VERSION "
113+
install_from_github epics-modules scaler SCALER $SCALER_VERSION $SCALER_SHA256 "
113114
EPICS_BASE
114115
ASYN
115116
"
116117

117-
install_from_github -i epics-modules mca MCA $MCA_VERSION "
118+
install_from_github -i epics-modules mca MCA $MCA_VERSION $MCA_SHA256 "
118119
EPICS_BASE
119120
CALC
120121
SSCAN
@@ -126,14 +127,14 @@ ASYN
126127
MCA
127128
"
128129

129-
download_from_github ISISComputingGroup EPICS-lakeshore $LAKESHORE_VERSION
130+
download_from_github ISISComputingGroup EPICS-lakeshore $LAKESHORE_VERSION $LAKESHORE_SHA256
130131
mv EPICS-lakeshore/lakeshore336 .
131132
rm -r EPICS-lakeshore
132133
install_module lakeshore336 LAKESHORE "
133134
EPICS_BASE
134135
"
135136

136-
install_from_github DiamondLightSource lakeshore340 LAKESHORE340 $LAKESHORE340_VERSION "
137+
install_from_github DiamondLightSource lakeshore340 LAKESHORE340 $LAKESHORE340_VERSION $LAKESHORE340_SHA256 "
137138
EPICS_BASE
138139
ASYN
139140
CALC

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,20 +6,23 @@ 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() {
1921
if [ "$#" -eq 0 ]; then
2022
help
2123
fi
2224

25+
# Check extraction mode
2326
case "$1" in
2427
-r) dest=/ ;;
2528
-l) dest=. ;;
@@ -29,28 +32,51 @@ 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
# Throw extraction mode argument away
3342
shift
3443
echo "$dest $@"
3544
}
3645

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

41-
for url; do
61+
while [ $# -gt 1 ]; do
62+
url=$1
63+
sha=$2
4264
download_dir=$(mktemp -d)
4365
echo Downloading "$url"...
4466
wget -P $download_dir "$url" &> /tmp/wget.log || (cat /tmp/wget.log && false)
45-
4667
filename=$(basename $download_dir/*)
68+
69+
shacheck $download_dir/$filename $sha $url
70+
4771
if [[ ${filename,,} == *".zip" ]]; then
4872
unzip -qo $download_dir/$filename -d $dest
4973
else
5074
tar --no-same-owner -xf $download_dir/$filename -C $dest
5175
fi
5276

5377
rm -rf $download_dir /tmp/wget.log
78+
79+
shift 2
5480
done
5581
}
5682

0 commit comments

Comments
 (0)