Difference between revisions of "Shell"
m (Update branch vetting script.) |
m (Add S3 upload script.) |
||
| Line 153: | Line 153: | ||
<!-- odne komentar --> | <!-- odne komentar --> | ||
| + | |||
| + | <!-- | ||
| + | |||
| + | #!/bin/bash | ||
| + | |||
| + | export AWS_PROFILE=prod | ||
| + | echo "starting, exporting AWS_PROFILE=$AWS_PROFILE . . ." | ||
| + | |||
| + | # aws s3api put-object --bucket edge-fota-images --key img-EPN687-MMMM.bin --body /home/ted/projects-sandbox/workspace-for-nexus/nexus-gateway-firmware/build/img-MMMM.bin | ||
| + | |||
| + | fname1=op-and-location--image-MMMM--pr-316.json | ||
| + | fname2=op-and-location--image-SSSS--pr-316.json | ||
| + | fname3=img-EPN687-MMMM-PR-310.bin | ||
| + | fname4=img-EPN687-SSSS-PR-310.bin | ||
| + | |||
| + | filenames="$fname1 $fname2 $fname3 $fname4" | ||
| + | |||
| + | i=1 | ||
| + | |||
| + | for filename in $filenames; do | ||
| + | echo "($i) to S3 uploading $filename . . ." | ||
| + | (( i++ )) | ||
| + | aws s3api put-object --bucket edge-fota-images \ | ||
| + | --key $filename \ | ||
| + | --body $filename | ||
| + | done | ||
| + | |||
| + | echo "done." | ||
| + | |||
| + | exit $? | ||
| + | |||
| + | --> | ||
Revision as of 19:27, 2 September 2025
Shell Scripting
^ OVERVIEW
This local page for Bash shell scripts and notes on shell scripting.
^ Bash Built-in Variables
Some links to useful articles discussing `bash` built-in variables:
- https://avpres.net/Bash/builtin_shell_variables
- https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html
Bash's built-in variables with short names, as listed in Kernigan and Ritchie's "Unix Programming" book and at the first linked article above:
$0
The first element passed to the shell is the command name.
$n
The nth argument passed on the command line. If n ≥ 10, then the syntax must be ${n}.
$*
All the arguments on the command line. The values are separated by the first character in the shell variable IFS: (${1} … ${n}). See also: the IFS entry in Other Shell Variables.
$@
All the arguments on the command line. The values are individually quoted: ("${1}" … "${n}").
$#
The number of command-line arguments.
$?
The exit value of the last executed command.
$_
The last argument of the previous command.
$!
The process ID of the most recent background process.
^ Rename Badly Named Files
How to produce a usable filename which contains <ESC> characters, and to rename that badly named file:
$ ls -i 9704871 $'\033\033' 9703029 CMakeLists.txt 10899590 dts 9708845 samples $ ls -q `find . -inum 9704871` './'$'\033\033' $ mv './'$'\033\033' betterfilename
^ Git Diff-tree Helper Script
A helper script for calling `git diff-tree`, which can be used to determine at which project commit one or more files have changed:
#!/bin/bash
CMD_GIT=/usr/bin/git
$CMD_GIT log --oneline | head | cut -d " " -f 1
echo "2024-01-31 git diff-tree helper script in progress . . ."
echo "got $# arguments, arg one single quoted is '$1'"
hashes=`$CMD_GIT log --oneline | head -n ${1} | cut -d " " -f 1`
echo "In $PWD found git commit hashes:"
echo " " $hashes
#i=1
#for hash in $hashes; do echo "("$i")" $hash; (( i++ )); done
#echo "Files changed between commit pairs youngest pairings to oldest:
#for hash in $hashes; do echo "Files changed in git commit:"; git diff-tree -r $hash; echo; done
for hash in $hashes
do echo "Files changed in git commit:"
git log -1 --oneline $hash
git diff-tree -r $hash
echo
done
echo "done"
exit 0
Script to test compilation of series of git commits:
#!/bin/bash
CMD_GIT=/usr/bin/git
VETTED_COMMITS_FILE="branch-commit-vetting-report.txt"
current_branch="NOT_SET"
hashes="NOT_SET"
function usage()
{
echo "How to use vet-branch.sh:":
echo
echo " $ vet-branches.sh n"
echo
echo "Argument 'n' is a number of commits to test in current git branch."
echo
}
#
# script starting point, akin to int main
#
echo "$0: starting"
if [ $# -lt 1 ]
then
echo "$0 called with too few arguments!"
usage
exit -1
fi
current_branch=`$CMD_GIT branch --show-current`
hashes=`$CMD_GIT log --oneline | head -n $1 | cut -d " " -f 1`
echo "Vetting $1 commits of branch ${current_branch}."
echo "Asked to test commits: $hashes"
echo
date >> $VETTED_COMMITS_FILE
echo "Testing compilation of $1 commits start at tip of '$current_branch':" >> $VETTED_COMMITS_FILE
for hash in $hashes
do
$CMD_GIT checkout --quiet $hash
echo
echo "At commit $hash, vetting script in progress"
echo "---------------------------------------------"
./scripts/docker-helper.sh build_both_debug
echo "$hash build result: $?" >> $VETTED_COMMITS_FILE
done
echo
echo "Restoring git checkout to starting branch:"
$CMD_GIT checkout $current_branch
echo "$0: done."
exit #?
^ To Research
[ ] Look up `git ls-files` and its options.
[ ] Review `xargs` called with the dash zero option.
Interesting header file from Zephyr RTOS 3.4.0:
`zephyr/include/zephyr/toolchain/xcc_missing_defs.h`