Skip to content

Instantly share code, notes, and snippets.

@Beep6581
Created September 27, 2017 08:58
Show Gist options
  • Save Beep6581/c6e783207b03136dd1089f41a522efe9 to your computer and use it in GitHub Desktop.
Save Beep6581/c6e783207b03136dd1089f41a522efe9 to your computer and use it in GitHub Desktop.
Clones Geeqie source and compiles
#!/usr/bin/env bash
# By Morgan Hardwood
# This script gets the latest source code for the given program and compiles it.
# The name of the program, used for the folder names:
prog="geeqie"
# The name of the compiled executable:
exe="${prog}"
# The name of the sub-folder relative to the install prefix where the executable resides, if any,
# e.g. if the executable is put into a folder called "bin" then set exeRelativePath="bin"
exeRelativePath="bin"
# The path to the repository:
repo="git://www.geeqie.org/geeqie.git"
# No touching below this line -------------------------------------------------
buildOnly="false"
buildType="release"
exePath="${exeRelativePath}/${exe}"
printf '%s\n' "" "Program name: ${prog}" "Build type: ${buildType}" "Build without updating: ${buildOnly}" ""
# Command-line arguments
OPTIND=1
while getopts "bdh?-" opt; do
case "${opt}" in
b) buildOnly="true"
;;
d) buildType="debug"
;;
h|\?|-) printf '%s\n' "This script gets the latest source code for ${prog} and compiles it." \
"" \
" -b" \
" Optional. If specified, the script only compiles the source, it does not try to update the source. If not specified, the source will be updated first." \
" -d" \
" Optional. Compile a \"debug\" build. If not specified, a \"release\" build will be made." \
""
exit 0
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
# Clone if needed
cloned="false"
updates="false"
if [[ ! -d "$HOME/programs/code-${prog}" ]]; then
mkdir "$HOME/programs"
git clone "$repo" "$HOME/programs/code-${prog}" || exit 1
pushd "$HOME/programs/code-${prog}" || exit 1
cloned="true"
else
pushd "$HOME/programs/code-${prog}" || exit 1
git fetch
if [[ $(git rev-parse HEAD) != $(git rev-parse @{u}) ]]; then
updates="true"
fi
fi
# Pull updates if necessary
if [[ "$updates" = "true" && "$buildOnly" = "false" ]]; then
git pull || exit 1
fi
existsExe="false"
if [[ -e "$HOME/programs/${prog}/${exePath}" ]]; then
existsExe="true"
fi
# Quit if no updates and build-only flag not set
if [[ "$cloned" = "false" && "$buildOnly" = "false" && "$updates" = "false" && "$existsExe" = "true" ]]; then
printf '%s\n' "No updates, nothing to do."
exit 0
fi
# Compile
rm -rf "$HOME/programs/${prog}"
cd "$HOME/programs/code-${prog}" || exit 1
./autogen.sh --prefix="$HOME/programs/${prog}" || exit 1
make install || exit 1
printf "%s\n" "" "To run ${prog} type:" "~/programs/${prog}/${exePath}" ""
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment