Skip to content

Instantly share code, notes, and snippets.

@cxxxr
Last active September 16, 2015 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cxxxr/de027a2e062a77e79bea to your computer and use it in GitHub Desktop.
Save cxxxr/de027a2e062a77e79bea to your computer and use it in GitHub Desktop.
#!/bin/sh
# The MIT License (MIT)
#
# Copyright (c) 2015 bpyamasinn.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
INSTALL_DIR="$HOME/opt"
NETHACK_TARFILE="/tmp/nethack-src.tgz"
JNETHACK_FILE="/tmp/jnethack.diff.gz"
NETHACK_SOURCE_URL='http://osdn.jp/frs/redir.php?m=iij&f=%2Fjnethack%2F9091%2Fnethack-343-src.tgz'
JNETHACK_URL='http://osdn.jp/frs/redir.php?m=iij&f=%2Fjnethack%2F58545%2Fjnethack-3.4.3-0.11.diff.gz'
MAKE_UPDATE_FLAG=`false`
download () {
wget $NETHACK_SOURCE_URL -O $NETHACK_TARFILE
wget $JNETHACK_URL -O $JNETHACK_FILE
}
prepare_dir () {
if [ ! -d $INSTALL_DIR ]; then
mkdir $INSTALL_DIR
fi
}
defreeze_and_patch () {
cd $INSTALL_DIR
dirname=`tar tf $NETHACK_TARFILE | grep -o "^[a-zA-Z0-9.-]*" | head -1`
tar zxf $NETHACK_TARFILE
cd $dirname
zcat $JNETHACK_FILE | patch -p1
sh sys/unix/setup.sh
}
replace_makefile () {
echo "replace makefile"
sed -i 's/^GAMEGRP.*/GAMEGRP = games/' Makefile
sed -i 's/^GAMEPERM.*/GAMEPERM = 02755/' Makefile
sed -i 's/^FILEPERM.*/FILEPERM = 0644/' Makefile
sed -i 's/^EXEPERM.*/EXEPERM = 755/' Makefile
sed -i 's/^DIRPERM.*/DIRPERM = 775/' Makefile
}
replace_src_makefile () {
echo "replace src/makefile"
cd src
sed -i 's/^CFLAGS.*/CFLAGS = -O2 -fomit-frame-pointer -I..\/include/' Makefile
cd ..
}
replace_util_makefile () {
echo "replace util/makefile"
cd util
sed -i 's/^CFLAGS.*/CFLAGS = -O2 -fomit-frame-pointer -I..\/include/' Makefile
cd ..
}
replace_include_unixconf_h () {
echo "replace include/unixconf.h"
cd include
sed -i 's/^.*#\s*define \s*SYSV\s.*/#define SYSV/' unixconf.h
sed -i 's/^.*#\s*define \s*LINUX\s.*/#define LINUX/' unixconf.h
sed -i 's/^.*#\s*define \s*TERMINFO\s.*/#define TERMINFO/' unixconf.h
sed -i 's/^.*#\s*define \s*TIMED_DELAY\s.*/#define TIMED_DELAY/' unixconf.h
cd ..
}
replace_include_config_h () {
echo "replace include/config.h"
cd include
sed -i 's/^.*#\s*define \s*DLB\W.*/#define DLB/' config.h
sed -i 's/^.*#\s*define \s*COMPRESS \s*"\/usr\/bin\/gzip".*/#define COMPRESS "\/bin\/gzip"/' config.h
sed -i 's/^.*#\s*define \s*XI18N.*//' config.h
cd ..
}
make_and_install () {
make all
if [ $MAKE_UPDATE_FLAG ]; then
sudo make update
else
sudo make install
sudo chmod g+w /usr/games/lib/jnethackdir/record
sudo chmod g+w /usr/games/lib/jnethackdir/logfile
fi
}
download
prepare_dir
defreeze_and_patch
replace_makefile
replace_src_makefile
replace_util_makefile
replace_include_unixconf_h
replace_include_config_h
make_and_install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment