]> gitweb @ CieloNegro.org - gregtech6.git/blob - Import
Import GregTech 6.07.16
[gregtech6.git] / Import
1 #!/usr/bin/env bash
2 set -o errexit -o nounset
3
4 # -----------------------------------------------------------------------------
5 # Configuration
6 #
7 readonly mc_version="1.7.10"
8 readonly master_site="https://gregtech.overminddl1.com/com/gregoriust/gregtech/gregtech_${mc_version}"
9 readonly workdir="_work"
10
11 # -----------------------------------------------------------------------------
12 # Argument parsing
13 #
14 declare gt_version
15 declare -i dry_run=0
16
17 function usage() {
18     echo >&2 "Usage: $0 [-d] VERSION"
19 }
20 while getopts dh OPT; do
21     case $OPT in
22         d)
23             dry_run=1;;
24         h)
25             usage; exit 0;;
26         \?)
27             usage; exit 1;;
28     esac
29 done
30 shift $((OPTIND - 1))
31
32 if (( $# == 0 )); then
33     usage; exit 1
34 else
35     gt_version="$1"
36 fi
37
38 # -----------------------------------------------------------------------------
39 # Utility functions
40 #
41 function run() {
42     # Is the /dev/stdout a tty?
43     if [[ -t 1 ]]; then
44         echo -ne "\e[1;32m" # bold + green
45         echo "$@"
46         echo -ne "\e[0m"
47     else
48         echo "$@"
49     fi
50
51     if (( ! $dry_run )); then
52         "$@"
53     fi
54 }
55
56 function msg() {
57     # Is the /dev/stdout a tty?
58     if [[ -t 1 ]]; then
59         echo -ne "\e[1;33m" # bold + yellow
60         echo "$@"
61         echo -ne "\e[0m"
62     else
63         echo "$@"
64     fi
65 }
66
67 # -----------------------------------------------------------------------------
68 # Downloading distribution files
69 #
70 msg "=> Importing GregTech ${gt_version}"
71 if (( $dry_run )); then
72     msg "=> -d (dry-run) is in effect. No actual changes will be made."
73 else
74     msg -n "=> Type [RET] to continue..."
75     read
76 fi
77
78 readonly mod_jar="gregtech_${mc_version}-${gt_version}.jar"
79 readonly api_jar="gregtech_${mc_version}-${gt_version}-sources.jar"
80 mkdir -p "${workdir}/dist"
81
82 msg "==> Downloading ${mod_jar}"
83 run curl "${master_site}/${gt_version}/${mod_jar}" -o "${workdir}/dist/${mod_jar}" --time-cond "${workdir}/dist/${mod_jar}" --continue-at -
84
85 msg "==> Downloading ${api_jar}"
86 run curl "${master_site}/${gt_version}/${api_jar}" -o "${workdir}/dist/${api_jar}" --time-cond "${workdir}/dist/${api_jar}" --continue-at -
87
88 # -----------------------------------------------------------------------------
89 # Decompiling the mod
90 #
91 msg "==> Decompiling ${mod_jar}"
92 run cfr "${workdir}/dist/${mod_jar}" --outputdir .
93
94 # -----------------------------------------------------------------------------
95 # Unpacking API sources
96 #
97 msg "==> Unpacking API sources"
98 run jar -xf "${workdir}/dist/${api_jar}" gregapi
99
100 # -----------------------------------------------------------------------------
101 # Unpacking assets
102 #
103 msg "==> Unpacking assets"
104 run jar -xf "${workdir}/dist/${mod_jar}" assets
105
106 # -----------------------------------------------------------------------------
107 # Creating a commit and a tag
108 #
109 msg "==> Creating a commit"
110 run git add .
111 run git status
112 run git commit --message "Import GregTech ${gt_version}"
113
114 msg "==> Tagging the commit"
115 run git tag --annotate --message "GregTech ${gt_version} (Official)" "GregTech-${gt_version}"