DOWNLOAD_URL=
SHA1_SUM=
TARGET_JAR=
+NEED_RESTART='n'
DESCRIPTION=$( cat <<-EOF
Update Micraft server .jar file.
eval ${cmd}
fi
CHOWN "${MC_USER}:${MC_GROUP}" "${TARGET_JAR}"
+ NEED_RESTART='y'
}
}
+#------------------------------------------------------------------------------
+fix_symlinks() {
+
+ info "Checking symlink in '${CYAN}${MC_BACKUP_DIR}${NORMAL}' ..."
+
+ if [[ -e "${MC_SERVER_CUR_LINK_BASE}" ]] ; then
+ if [[ ! -h "${MC_SERVER_CUR_LINK_BASE}" ]] ; then
+ error "Path '${RED}/${MC_SERVER_CUR_LINK_BASE}${NORMAL}' exists, but is not a symlink."
+ exit 7
+ fi
+ if [[ ! -f "${MC_SERVER_CUR_LINK_BASE}" ]] ; then
+ error "Symlink '${RED}/${MC_SERVER_CUR_LINK_BASE}${NORMAL}' exists, but shows not to a regular file."
+ exit 7
+ fi
+
+ local link_target=$( readlink -e "${MC_SERVER_CUR_LINK_BASE}" )
+ debug "Current symlink points to '${CYAN}${link_target}${NORMAL}'."
+ local canon_path_target_jar=$( readlink -e "${TARGET_JAR}" )
+ debug "Absolute path of target jar file: '${CYAN}${canon_path_target_jar}${NORMAL}'."
+
+ if [[ "${link_target}" != "${canon_path_target_jar}" ]] ; then
+ info "Symlink '${CYAN}${MC_SERVER_CUR_LINK_BASE}${NORMAL}' must be corrected."
+ LN -sf "${TARGET_JAR}" "${MC_SERVER_CUR_LINK_BASE}"
+ NEED_RESTART='y'
+ fi
+
+ else
+
+ info "Symlink '${CYAN}${MC_SERVER_CUR_LINK_BASE}${NORMAL}' does not exists, will be created."
+ LN -sf "${TARGET_JAR}" "${MC_SERVER_CUR_LINK_BASE}"
+ NEED_RESTART='y'
+
+ fi
+
+}
+
+#------------------------------------------------------------------------------
+restart_service() {
+
+ local -a services=()
+ local service=
+
+ for service in $( systemctl --plain --type=service --state=running --no-legend --no-pager | \
+ grep '^minecraft' | awk '{print $1}' ) ; do
+ services+=( "${service}" )
+ done
+
+ if [[ "${#services[*]}" == 0 ]] ; then
+ info "No services found to restart."
+ return
+ fi
+
+ empty_line
+ for service in "${ervices[@]}" ; do
+ info "Restarting '${CYAN}${service}${NORMAL}' ..."
+ if [[ "${SIMULATE}" != "y" ]] ; then
+ systemctl restart "${service}"
+ fi
+ done
+
+ sleep 15
+
+ for service in "${ervices[@]}" ; do
+ empty_line
+ info "Status of '${CYAN}${service}${NORMAL}':"
+ systemctl status "${service}"
+ done
+
+}
+
#------------------------------------------------------------------------------
main() {
check_preferences
detecting_cur_version
get_upstream_info
- if [[ -f "${TARGET_JAR}" ]] ; then
- check_sha1
- fi
- if [[ "${UPSTREAM_VERSION}" == "${CURRENT_VERSION}" ]] ; then
- info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update."
- exit 0
+ if [[ ! -f "${TARGET_JAR}" ]] ; then
+ do_download
fi
- do_download
+ # if [[ "${UPSTREAM_VERSION}" == "${CURRENT_VERSION}" ]] ; then
+ # info "Version '${GREEN}${UPSTREAM_VERSION}${NORMAL}' not changed, no update."
+ # exit 0
+ # fi
check_sha1
+ fix_symlinks
+
+ if [[ "${NEED_RESTART}" == "y" ]] ; then
+ restart_service
+ fi
}