Debian Codegraph @

script/demo/download_demo_version.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 ###########################################################################
4 # fheroes2: https://github.com/ihhub/fheroes2 #
5 # Copyright (C) 2021 - 2023 #
6 # #
7 # This program is free software; you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation; either version 2 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program; if not, write to the #
19 # Free Software Foundation, Inc., #
20 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
21 ###########################################################################
22
23 set -e -o pipefail
24
25 H2DEMO_URL="https://archive.org/download/HeroesofMightandMagicIITheSuccessionWars_1020/h2demo.zip"
26 H2DEMO_SHA256="12048c8b03875c81e69534a3813aaf6340975e77b762dc1b79a4ff5514240e3c"
27
28 function echo_red {
29 echo -e "\033[0;31m$*\033[0m"
30 }
31
32 function echo_green {
33 echo -e "\033[0;32m$*\033[0m"
34 }
35
36 function echo_stage {
37 echo
38 echo_green "$*"
39 echo
40 }
41
42 echo_green "This script will download the demo version of the original Heroes of Might and Magic II"
43 echo_green "It may take a few minutes, please wait..."
44
45 echo_stage "[1/4] determining the destination directory"
46
47 DEST_PATH=""
48
49 if [[ -n "$1" ]]; then
50 DEST_PATH="$1"
51 elif [[ -f fheroes2 && -x fheroes2 ]]; then
52 DEST_PATH="."
53 elif [[ -d ../../src ]]; then
54 # Special hack for developers running this script from the source tree
55 DEST_PATH="../.."
56 fi
57
58 if [[ -z "$DEST_PATH" || ! -d "$DEST_PATH" || ! -w "$DEST_PATH" ]]; then
59 if [[ "$(uname 2> /dev/null)" == "Linux" ]]; then
60 DEST_PATH="${XDG_CONFIG_HOME:-$HOME/.local/share}/fheroes2"
61 elif [[ -z "$1" ]]; then
62 DEST_PATH="$HOME/.fheroes2"
63 fi
64 fi
65
66 echo_green "Destination directory: $DEST_PATH"
67
68 echo_stage "[2/4] downloading the demo version"
69
70 [[ ! -d "$DEST_PATH/demo" ]] && mkdir -p "$DEST_PATH/demo"
71
72 cd "$DEST_PATH/demo"
73
74 if [[ -n "$(command -v wget)" ]]; then
75 wget -O h2demo.zip "$H2DEMO_URL"
76 elif [[ -n "$(command -v curl)" ]]; then
77 curl -o h2demo.zip -L "$H2DEMO_URL"
78 else
79 echo_red "Neither wget nor curl were found in your system. Unable to download the demo version. Installation aborted."
80 exit 1
81 fi
82
83 echo "$H2DEMO_SHA256 *h2demo.zip" > checksums
84
85 if [[ -n "$(command -v shasum)" ]]; then
86 shasum --check --algorithm 256 checksums
87 elif [[ -n "$(command -v sha256sum)" ]]; then
88 sha256sum --check --strict checksums
89 else
90 echo_red "Neither shasum nor sha256sum were found in your system. Unable to verify the downloaded file. Installation aborted."
91 exit 1
92 fi
93
94 echo_stage "[3/4] unpacking archives"
95
96 unzip -o h2demo.zip
97
98 echo_stage "[4/4] copying files"
99
100 [[ ! -d ../data ]] && mkdir ../data
101 [[ ! -d ../maps ]] && mkdir ../maps
102
103 cp -r DATA/* ../data
104 cp -r MAPS/* ../maps