Created
March 17, 2013 16:29
-
-
Save osadalakmal/5182286 to your computer and use it in GitHub Desktop.
A bash script for adding build tags to an ELF file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
date_format_str="" | |
git_describe="" | |
user_name="" | |
version_str="" | |
while getopts "d:g:u:v:h?" opt; do | |
case "$opt" in | |
d) | |
date_format_str=$OPTARG | |
;; | |
g) | |
git_describe=$OPTARG | |
;; | |
u) | |
user_name=$OPTARG | |
;; | |
v) | |
version_str=$OPTARG | |
;; | |
h|?) | |
echo "Help!! Please write a help string" | |
exit | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
tmpfile=$(mktemp) | |
echo "BuildTags ver0.1" >> $tmpfile | |
if [[ ! -z "$date_format_str" ]]; then | |
echo "Build Time:" $date_format_str >> $tmpfile | |
fi | |
if [[ ! -z "$git_describe" ]]; then | |
echo "Git Describe:" $git_describe >> $tmpfile | |
fi | |
if [[ ! -z "$user_name" ]]; then | |
echo "using user name" | |
echo "User Name:" $user_name >> $tmpfile/tmp/tmp.urNJtFf7cf | |
fi | |
if [[ ! -z "$version_str" ]]; then | |
echo "Version:" $version_str >> $tmpfile | |
fi | |
if [[ -z "$1" || ! -f $1 ]]; then | |
echo "File does not exist. Exiting" | |
exit | |
fi | |
tmpfile_elf=$(mktemp) | |
objcopy --add-section BuildTags=$tmpfile $1 $tmpfile_elf | |
mv $tmpfile_elf $1.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment