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 11 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]
2 changes: 1 addition & 1 deletion .shellcheckrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
disable=SC1091 # allow sourcing files that can't immediately be found (pcds_conda)
disable=SC1091,SC2018,SC2019,SC2164 # allow sourcing files that can't immediately be found (pcds_conda), disable warnings about supporting accents and foreign languages, disable cd warning
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we deprecate this in favor of our shared dotfiles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should, or we could at least include instructions in here for updating to the full shared dotfiles. This is a reasonable follow-up issue.

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
1 change: 0 additions & 1 deletion scripts/afs-remote-fix
KaushikMalapati marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

53 changes: 53 additions & 0 deletions scripts/afs-remote-fix
KaushikMalapati marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python3
"""
afs-remote-fix is a script for repointing your afs git remotes towards github.

It will check if you're currently in a git ioc repo with an afs remote as your origin,
switching it to your fork and adding an upstream remote to pcdshub.

An afs remote is a git remote with a path that looks something like this:
/afs/slac.stanford.edu/g/cd/swe/git/repos/package/epics/ioc/common/ims.git

If this path is your origin, after running the script you will instead have:

origin git@github.com:your-username/ioc-common-ims.git
upstream git@github.com:pcdshub/ioc-common-ims.git

If the origin is not an afs path, this script will exit without taking any action.

The script will prompt you for your github username, which is not necessarily
the same as your slac username.
"""

import subprocess


def main() -> int:
origin = subprocess.check_output(
["git", "remote", "get-url", "origin"], universal_newlines=True
).strip()
if not origin.startswith("/afs/"):
print(f"Your origin {origin} is not an afs repo.")
return 1
elif "/ioc/" not in origin:
print(f"Your origin {origin} is not an ioc repo.")
return 1
_, ioc_path = origin.split("/ioc/")
repo_name = f"ioc-{ioc_path.replace('/', '-', 1)}"
username = input("Please input your github username:\n")
new_origin = f"git@github.com:{username}/{repo_name}"
new_upstream = f"git@github.com:pcdshub/{repo_name}"
print("\nPlanning to set:")
print(f"origin to {new_origin}")
print(f"upstream to {new_upstream}")
confirm = input("Confirm? y/n\n")
if not confirm.lower().startswith("y"):
return 1
subprocess.run(["git", "remote", "set-url", "origin", new_origin])
subprocess.run(["git", "remote", "add", "upstream", new_upstream])
subprocess.run(["git", "remote", "-v"])
return 0


if __name__ == "__main__":
exit(main())
Loading