Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shellcheck and shfmt on bash scripts #204

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ repos:
rev: 5.11.5
hooks:
- id: isort
- repo: https://github.com/pecigonzalo/pre-commit-shfmt
rev: v2.2.0
hooks:
- id: shell-fmt-go
args: [-l, -w, -s, -fn, -sr, -ci, -i=4, -d]
3 changes: 2 additions & 1 deletion .shellcheckrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
disable=SC1091 # allow sourcing files that can't immediately be found (pcds_conda)
disable=SC1091
# allow sourcing files that can't immediately be found (pcds_conda and variable-dependent paths)
62 changes: 31 additions & 31 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
Copyright (c) 2018, The Board of Trustees of the Leland Stanford Junior
University, through SLAC National Accelerator Laboratory (subject to receipt
of any required approvals from the U.S. Dept. of Energy). All rights reserved.
Redistribution and use in source and binary forms, with or without
Copyright (c) 2018, The Board of Trustees of the Leland Stanford Junior
University, through SLAC National Accelerator Laboratory (subject to receipt
of any required approvals from the U.S. Dept. of Energy). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

(1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

(2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
(1) Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

(3) Neither the name of the Leland Stanford Junior University, SLAC National
Accelerator Laboratory, U.S. Dept. of Energy nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
(2) Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, THE UNITED STATES GOVERNMENT,
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
(3) Neither the name of the Leland Stanford Junior University, SLAC National
Accelerator Laboratory, U.S. Dept. of Energy nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, THE UNITED STATES GOVERNMENT,
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.

You are under no obligation whatsoever to provide any bug fixes, patches, or
upgrades to the features, functionality or performance of the source code
("Enhancements") to anyone; however, if you choose to make your Enhancements
available either publicly, or directly to SLAC National Accelerator Laboratory,
without imposing a separate written license agreement for such Enhancements,
then you hereby grant the following license: a non-exclusive, royalty-free
You are under no obligation whatsoever to provide any bug fixes, patches, or
upgrades to the features, functionality or performance of the source code
("Enhancements") to anyone; however, if you choose to make your Enhancements
available either publicly, or directly to SLAC National Accelerator Laboratory,
without imposing a separate written license agreement for such Enhancements,
then you hereby grant the following license: a non-exclusive, royalty-free
perpetual license to install, use, modify, prepare derivative works, incorporate
into other computer software, distribute, and sublicense such Enhancements or
into other computer software, distribute, and sublicense such Enhancements or
derivative works thereof, in binary and source code form.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ usage: archive-status [-h] PV <br/>
<tr>
<td>camViewer</td>
<td>
usage: /reg/g/pcds/engineering_tools/latest/scripts/camViewer options<br/>
usage: /cds/group/pcds/engineering_tools/latest/scripts/camViewer options<br/>
<br/>
start the viewer for controls cameras<br/>
<br/>
Expand All @@ -99,7 +99,7 @@ usage: /reg/g/pcds/engineering_tools/latest/scripts/camViewer options<br/>
<tr>
<td>check_host</td>
<td>
Usage: /reg/g/pcds/engineering_tools/latest/scripts/check_host HOSTNAME<br/>
Usage: /cds/group/pcds/engineering_tools/latest/scripts/check_host HOSTNAME<br/>
<br/>
Display host info and run some checks.</br>
</td>
Expand Down Expand Up @@ -178,7 +178,7 @@ Checks epicsArch files for mismatches of PVs and aliases, missing files, and unc
<br/>
<br/>
positional arguments:<br/>
filepath Full filepath of the file to check e.g /reg/g/pcds/dist/pds/xpp/misc/epicsArch.txt
filepath Full filepath of the file to check e.g /cds/group/pcds/dist/pds/xpp/misc/epicsArch.txt
<br/>
<br/>
optional arguments:<br/>
Expand Down Expand Up @@ -310,7 +310,7 @@ usage: grep_more_ioc [-h] [-d] patt hutch {print,search} <br/>
<tr>
<td>grep_pv</td>
<td>
GREP SEARCHES THROUGH ALL IOCs IN /reg/d/iocData/<br/>
GREP SEARCHES THROUGH ALL IOCs IN /cds/data/iocData/<br/>
FOR PVs THAT MATCH GIVEN KEYWORD/HANDLE.<br/>
Ideally, find_pv should be used as it gives a lot more information (but can be slow sometimes)<br/>
</td>
Expand Down Expand Up @@ -411,7 +411,7 @@ optional arguments:
&nbsp; $EPICS_SITE_TOP/ioc, or /cds/group/pcds/epics/ioc if
&nbsp; the environment variable is not set. With your current
&nbsp; environment variables, this defaults to
&nbsp; /reg/g/pcds/epics/ioc.
&nbsp; /cds/group/pcds/epics/ioc.
&nbsp; --path-override PATH_OVERRIDE, -p PATH_OVERRIDE
&nbsp; If provided, ignore all normal path-selection rules in
&nbsp; favor of the specific provided path. This will let you
Expand Down Expand Up @@ -456,7 +456,7 @@ optional arguments:
&nbsp; $EPICS_SITE_TOP/ioc, or /cds/group/pcds/epics/ioc if
&nbsp; the environment variable is not set. With your current
&nbsp; environment variables, this defaults to
&nbsp; /reg/g/pcds/epics/ioc.
&nbsp; /cds/group/pcds/epics/ioc.
&nbsp; --path-override PATH_OVERRIDE, -p PATH_OVERRIDE
&nbsp; If provided, ignore all normal path-selection rules in
&nbsp; favor of the specific provided path. This will let you
Expand Down
10 changes: 5 additions & 5 deletions rc/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ if [ -f "${HOME}/.pcds_setup.sh" ]; then
source "${HOME}/.pcds_setup.sh"
fi

source /reg/g/pcds/setup/pcds_shortcuts.sh
source /cds/group/pcds/setup/pcds_shortcuts.sh

export PATH=$PATH:/reg/g/pcds/engineering_tools/latest-released/scripts/
export PATH=$PATH:/cds/group/pcds/engineering_tools/latest-released/scripts/

########################################
### Specific PCDS environment logins ###
########################################
alias epicsenv='. /reg/g/pcds/setup/epicsenv-cur.sh'
alias ana_env='source /reg/g/psdm/psconda.sh'
alias plc_env='. /reg/g/pcds/setup/plcenv.sh'
alias epicsenv='. /cds/group/pcds/setup/epicsenv-cur.sh'
alias ana_env='source /cds/group/psdm/psconda.sh'
alias plc_env='. /cds/group/pcds/setup/plcenv.sh'
1 change: 0 additions & 1 deletion rc/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ au FileType python
\ autoindent
\ fileformat=unix
\ encoding=utf-8

4 changes: 2 additions & 2 deletions scripts/BLmotors
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/reg/g/pcds/pyps/conda/py36/envs/pcds-4.1.6/bin/python
#!/cds/group/pcds/pyps/conda/py36/envs/pcds-4.1.6/bin/python


"""
Expand Down Expand Up @@ -144,7 +144,7 @@ def assign_full_path(ioc_names):
"""
lists_path = []
for name in range(len(ioc_names)):
lists_path.append('/reg/d/iocData/' + ioc_names[name] +
lists_path.append('/cds/data/iocData/' + ioc_names[name] +
'/iocInfo/IOC.pvlist')
return lists_path

Expand Down
91 changes: 45 additions & 46 deletions scripts/ami_offline_psana
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
#! /bin/bash
usage()
{
cat << EOF
cat << EOF
usage: $0 options

We will run ami_offline

OPTIONS:
-e <expnumber>
-e <expnumber>
-R rebinning (binned to 640x640)
-n no plugins
EOF
}

if [[ ($1 == "--help") || ($1 == "-h") ]]; then
usage
exit 0
usage
exit 0
fi

USER=$(whoami)
ARGSTR='-Z'

while getopts "u:e:ntR" OPTION
do
while getopts "u:e:ntR" OPTION; do
case $OPTION in
e)
EXP=$OPTARG
;;
R)
REBIN=1
;;
n)
NOPLUG=1
;;
?)
usage
exit
;;
esac
e)
EXP=$OPTARG
;;
R)
REBIN=1
;;
n)
NOPLUG=1
;;
?)
usage
exit
;;
esac
done

if [ -z "$EXP" ]; then
echo getting the experiment "$EXP"
HUTCH=$(get_hutch_name)
if [ "$HUTCH" == 'unknown_hutch' ]; then
read -p 'please enter an experiment name: ' EXP
read -rp 'please enter an experiment name: ' EXP
else
EXP=$(get_curr_exp)
EXP=$(get_curr_exp)
fi
fi
HUTCH=${EXP:0:3}

if [ -z $REBIN ]; then
if [[ -z $REBIN ]]; then
ARGSTR=$ARGSTR' -R'
fi

Expand All @@ -66,64 +65,64 @@ if [[ $HUTCH == 'cxi' ]]; then
fi

#get executable
ami_base_path=$(grep ami_base_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep -v '#' | grep -v 'ami_base_path+' | tail -n 1 | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g)
ami_path=$ami_base_path$(grep ami_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+//g | sed s/\'//g)
ami_base_path=$(grep ami_base_path /cds/group/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep -v '#' | grep -v 'ami_base_path+' | tail -n 1 | awk 'BEGIN { FS = "=" }; { print $2}' | sed s/\'//g)
ami_path=$ami_base_path$(grep ami_path /cds/group/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep -v 'ami_path+' | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+//g | sed s/\'//g)

if [ ! -f $ami_path/offline_ami ]; then
if [[ ! -f $ami_path/offline_ami ]]; then
echo "could not find offline_ami executable in ""$ami_path"
exit
fi

#plugin_path & plugin string.
pp=$(grep plugin_path /reg/g/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep ami_base | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+//g | sed s/\'//g)
pp=$(grep plugin_path /cds/group/pcds/dist/pds/"$HUTCH"/scripts/"$CNF" | grep ami_base | grep -v '#' | awk 'BEGIN { FS = "= " }; { print $2}' | sed s/ami_base_path+//g | sed s/\'//g)
plugin_path=$ami_base_path$pp
plugin_str=$plugin_path'/libtimetooldbd.so'

if [ -z $NOPLUG ]; then
if [[ -z $NOPLUG ]]; then
ARGSTR=$ARGSTR' -L '$plugin_str
fi
#ARGSTR=$ARGSTR -X /reg/neh/operator/$HUTCH\opr/experiments
#ARGSTR=$ARGSTR -X /cds/home/opr/$HUTCH\opr/experiments

#check hostname - different path for recorder node.
if [ "${HOSTNAME:0:5}" == 'psana' ]; then
XTCDIR=/reg/d/psdm/$HUTCH/$EXP/xtc/
XTCDIR=/cds/data/psdm/$HUTCH/$EXP/xtc/
HAVE_RUNS=$(find "$XTCDIR"/*r* | wc -l)
if [ "$HAVE_RUNS" == 0 ]; then
echo 'did not find any xtc files in /reg/d/psdm/'"$HUTCH"'/'"$EXP"', will exit'
exit
fi
echo 'did not find any xtc files in /cds/data/psdm/'"$HUTCH"'/'"$EXP"', will exit'
exit
fi
elif [ "${HOSTNAME:0:3}" == 'drp' ]; then
XTCDIR=/cds/data/drpsrcf/$HUTCH/$EXP/xtc/
HAVE_RUNS=$(find "$XTCDIR"/*r* | wc -l)
if [ "$HAVE_RUNS" == 0 ]; then
echo 'did not find any xtc files in /cds/data/drpsrcf/'"$HUTCH"'/'"$EXP"', will exit'
exit
fi
elif [ "${HOSTNAME:8:3}" == 'rec' ]; then
echo 'did not find any xtc files in /cds/data/drpsrcf/'"$HUTCH"'/'"$EXP"', will exit'
exit
fi
elif [ "${HOSTNAME:8:3}" == 'rec' ]; then
XTCDIR=/u2/REC/daq/xtc/
elif [ "${HOSTNAME:8:3}" == 'dss' ]; then
elif [ "${HOSTNAME:8:3}" == 'dss' ]; then
EXPID=$(get_info --setExp "$EXP" --experimentNumber)
XTCDIR=/u2/pcds/pds/"$HUTCH"/e"$EXPID"/
XTCDIR=/u2/pcds/pds/"$HUTCH"/e"$EXPID"/
else
echo 'Please ssh to a psana, recorder or dss node to see data'
exit
fi

#change to temporary directory where we'll need the favorites file (&maybe
if [ ! -d /tmp/ami_offline_"$USER" ] ; then
if [ ! -d /tmp/ami_offline_"$USER" ]; then
mkdir /tmp/ami_offline_"$USER"
fi

ln -sf /reg/neh/operator/"$HUTCH"opr/.ami_favorites ~/.
ln -sf /cds/home/opr/"$HUTCH"opr/.ami_favorites ~/.

#not sure this is necessary either.
source /reg/g/pcds/setup/pathmunge.sh
ldpathmunge /reg/g/pcds/dist/pds/"$HUTCH"/ami-current/build/ami/lib/x86_64-linux-opt
source /cds/group/pcds/setup/pathmunge.sh
ldpathmunge /cds/group/pcds/dist/pds/"$HUTCH"/ami-current/build/ami/lib/x86_64-linux-opt

LD_LIBRARY_PATH=/reg/g/pcds/dist/pds/"$HUTCH"/current/build/pds/lib/x86_64-linux/:/reg/g/pcds/dist/pds/xpp/current/build/pdsdata/lib/x86_64-linux/:/reg/g/pcds/dist/pds/xpp/current/build/pdsalg/lib/x86_64-linux/:/reg/g/pcds/dist/pds/xpp/current/build/pdsapp/lib/x86_64-linux/:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=/cds/group/pcds/dist/pds/"$HUTCH"/current/build/pds/lib/x86_64-linux/:/cds/group/pcds/dist/pds/xpp/current/build/pdsdata/lib/x86_64-linux/:/cds/group/pcds/dist/pds/xpp/current/build/pdsalg/lib/x86_64-linux/:/cds/group/pcds/dist/pds/xpp/current/build/pdsapp/lib/x86_64-linux/:$LD_LIBRARY_PATH

#ARGSTR='-p '$XTCDIR $ARGSTR
echo '----------------------------------------------'
echo "$ami_path"/offline_ami $ARGSTR -p $XTCDIR
echo "$ami_path"/offline_ami "$ARGSTR" -p "$XTCDIR"
echo '----------------------------------------------'
$ami_path/offline_ami $ARGSTR -p $XTCDIR
"$ami_path"/offline_ami "$ARGSTR" -p "$XTCDIR"
6 changes: 3 additions & 3 deletions scripts/archive-resume
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
usage()
{
cat << EOF
cat << EOF
usage: $0 <PV>

Resume archiving of a PV in the archiver, e.g. $0 GDET:FEE1:241:ENRC
Expand All @@ -12,13 +12,13 @@ if [[ -z $1 ]]; then
usage
exit 1
fi

if [[ ($1 == "--help") || ($1 == "-h") ]]; then
usage
exit 0
fi

result=$(curl -s "http://pscaa01.slac.stanford.edu:17665/mgmt/bpl/resumeArchivingPV?pv=$1")
echo
echo $result | cut -d'{' -f2 | cut -d '}' -f1 | tr ',' '\n'
echo "$result" | cut -d'{' -f2 | cut -d '}' -f1 | tr ',' '\n'
echo
6 changes: 3 additions & 3 deletions scripts/archive-status
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
usage()
{
cat << EOF
cat << EOF
usage: $0 <PV>

Check on the status of a PV in the archiver, e.g. $0 GDET:FEE1:241:ENRC
Expand All @@ -12,13 +12,13 @@ if [[ -z $1 ]]; then
usage
exit 1
fi

if [[ ($1 == "--help") || ($1 == "-h") ]]; then
usage
exit 0
fi

result=$(curl -s "http://pscaa01.slac.stanford.edu:17665/mgmt/bpl/getPVStatus?pv=$1")
KaushikMalapati marked this conversation as resolved.
Show resolved Hide resolved
echo
echo $result | cut -d'{' -f2 | cut -d'}' -f1 | tr ',' '\n'
echo "$result" | cut -d'{' -f2 | cut -d'}' -f1 | tr ',' '\n'
echo
Loading