Last active
December 17, 2015 12:19
-
-
Save Kedrigern/5608511 to your computer and use it in GitHub Desktop.
vcmi installation script
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 | |
#============================================================================== | |
# | |
# FILE: homam-install.sh | |
# | |
# USAGE: homam-install.sh --data original_data [-v vcmi_version] dir | |
# | |
# DESCRIPTION: Installation script for vcmi | |
# | |
# AUTHOR: Ondřej Profant, ondrej.profant <> gmail.com | |
# | |
# VERSION: 0.5 | |
# | |
# HOMEPAGE: https://gist.github.com/Kedrigern | |
# | |
# LINKS: http://wiki.vcmi.eu/index.php?title=Installation_on_Linux | |
# README.linux from vcmi source code | |
# | |
# TESTED: Ubuntu 13.04 Raring Ringtail | |
# Fedora 17 Verne | |
# | |
# CREATED: 18. 05. 2013 | |
# | |
# TODO: - Fix permissions - for checkinstall is root required, | |
# but other parts can be run as user. | |
# If the script is run under root ~/.vcmi has wrong owner. | |
# | |
#============================================================================== | |
# Global variables / config | |
vcmi_version=0.93 # vcmi version (subversion tag) | |
data_dir= # path to original data files | |
work_dir=vcmi_src # working dir | |
log_file=/dev/null # log file | |
original_data_tip=http://www.ulozto.cz/x3MTCHm/heroes-of-might-and-magic-iii-complete-rar # link | |
#=== FUNCTION =============================================================== | |
# NAME: os dependency | |
# DESCRIPTION: Install operation system specific dependency, | |
# see README.linux for source codes | |
#============================================================================== | |
function dependency() { | |
if dpkg --version &> /dev/null; then | |
# Debian distros | |
sudo apt-get install subversion cmake g++ libsdl1.2debian libsdl-image1.2-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev zlib1g-dev libavformat-dev libswscale-dev libboost-dev libboost-filesystem-dev libboost-system-dev libboost-thread-dev libboost-program-options-dev >> "$log_file" | |
fi; | |
if yum --version &> /dev/null; then | |
# RPM distros | |
sudo yum -y install subversion cmake gcc-c++ SDL-devel SDL_image-devel SDL_ttf-devel SDL_mixer-devel boost boost-devel boost-filesystem boost-system boost-thread boost-program-options zlib-devel ffmpeg-devel ffmpeg-libs >> "$log_file" | |
fi; | |
echo -e "\e[1;32m[success]\e[00m os/distribution dependency"; | |
} | |
#=== FUNCTION =============================================================== | |
# NAME: download source codes | |
# DESCRIPTION: From svn download source codes by given tag (version) | |
#============================================================================== | |
function sourcecode() { | |
rm -rf src | |
if svn co https://vcmi.svn.sourceforge.net/svnroot/vcmi/tags/${vcmi_version}/ src >> "$log_file"; then | |
echo -e "\e[1;32m[success]\e[00m fetch the source codes from svn" | |
else | |
echo "Fetch source codes via svn fail." >&2 | |
exit 1; | |
fi; | |
} | |
#=== FUNCTION =============================================================== | |
# NAME: create package | |
# DESCRIPTION: Prepare distribution specific package and install it | |
#============================================================================== | |
function createpackage() { | |
if sudo checkinstall --install -y \ | |
--pkgname "vcmi" \ | |
--pkgversion "$vcmi_version" \ | |
--pkgaltsource "https://vcmi.svn.sourceforge.net/svnroot/vcmi/trunk" \ | |
--maintainer "Ondřej Profant via checkinstall" >> "$log_file"; then | |
echo -e "\e[1;32m[success]\e[00m OS package and installation" | |
else | |
echo "Checkinstall fail" >&2 | |
exit 1; | |
fi; | |
} | |
#=== FUNCTION =============================================================== | |
# NAME: prepare make | |
# DESCRIPTION: | |
#============================================================================== | |
function preparemake() { | |
if cmake ../src >> "$log_file"; then | |
echo -e "\e[1;32m[success]\e[00m cmake" | |
else | |
echo "Cmake fail." >&2 | |
exit 1; | |
fi; | |
} | |
#=== FUNCTION =============================================================== | |
# NAME: do make | |
# DESCRIPTION: | |
#============================================================================== | |
function domake() { | |
if make -j2 &>> "$log_file"; then | |
echo -e "\e[1;32m[success]\e[00m make" | |
else | |
echo "Make fail." >&2 | |
exit 1; | |
fi; | |
} | |
#=== FUNCTION =============================================================== | |
# NAME: required args | |
# DESCRIPTION: Check if the variables are set correct | |
#============================================================================== | |
function requiredargs() { | |
if [ -n "$data_dir" ]; then | |
: | |
else | |
echo "Parameter -d is required, see $0 --help for more information"; | |
exit 1; | |
fi; | |
} | |
#=== FUNCTION =============================================================== | |
# NAME: help | |
# DESCRIPTION: Show help | |
#============================================================================== | |
function help () { | |
echo -e "${0}" | |
echo "" | |
echo -e "Parameters:" | |
echo -e "\t-d\t--orig-data <dir>\tdir with the original HOMAM 3 Complete data" | |
echo -e "\t-t\t--target-dir <dir>\tworking dir" | |
echo -e "\t-v\t--vcmi-version\t<tag>\ttag from vcmi subversion repository" | |
echo -e "\t-l\t--log <filename>\tactivate log to the file" | |
echo -e "\t-h\t--help\t\t\tshow this help" | |
echo "" | |
echo -e "Description:" | |
echo -e "\tDownload source code, build it and install to os." | |
echo -e "\tGame data are placed in ~/.vcmi" | |
echo "" | |
echo -e "Tips:" | |
echo -e "\tUseable data files: $original_data_tip" | |
echo "" | |
echo -e "Author:" | |
echo -e "\tOndřej Profant 2013, ondrej.profant <> gmail.com" | |
} | |
#============================================================================== | |
# PARAMETER PARSING | |
#============================================================================== | |
while [ $# -gt 0 ]; do | |
case $1 in | |
-d | --orig-data ) | |
data_dir=`readlink -f "$2"`; | |
shift 2; | |
;; | |
-h | --help ) | |
help; | |
exit 0; | |
;; | |
-l | --log ) | |
log_file=`readlink -f "$2"`; | |
shift 2; | |
;; | |
-t | --target-dir ) | |
work_dir="$2"; | |
shift 2; | |
;; | |
-v | --vcmi-version ) | |
vcmi_version="$2" | |
shift 2; | |
;; | |
* ) | |
echo "Unknow parametr $1. Use help ($0 --help) for usage."; | |
exit 0; | |
;; | |
esac; | |
done; | |
requiredargs; | |
dependency; | |
# Create dir for source codes and buil | |
mkdir -p "$work_dir" && cd "$work_dir" ; | |
# Download source codes | |
sourcecode; | |
mkdir -p build && cd build; | |
# Prepare Makefile | |
preparemake; | |
# Make from source (j2 is number of cpu) | |
domake; | |
# Create os package and install game into the system (like /usr/share/vcmi) | |
createpackage; | |
# Clean temporaly files | |
make clean >> "$log_file" | |
if vcmibuilder --download --data "$data_dir" >> "$log_file"; then | |
echo -e "\e[1;32m[success]\e[00m game data prepared to ~/.vcmi"; | |
else | |
echo "vcmibuilder fail" >&2 | |
exit 1; | |
fi; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment