Skip to content
This repository was archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
Tiny improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyCrawl committed Sep 24, 2018
1 parent d12a2e3 commit dc3e7ca
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 51 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ In the unlikely case that you can't reach the web UI, installation most likely f
3. Install the latest version (see the [installation](#installation) section).
* __Note:__ at this point, you may have to perform some manual modifications (e.g. the bookmarklet mentioned above) again.

If you get a warning saying that `configuration file needs to be upgraded manually`, you must have previously made manual modifications to Coldsweat's configuration file and the program can not upgrade it automatically. In such an event, your old configuration file will have been saved in the [data folder](https://github.com/SkyCrawl/qcoldsweat/wiki) and I kindly ask you to:
1. Merge the saved configuration file (e.g. `config.5AE3`) into the new one (named `config`).
Furthermore, if you get a certain warning while installing or upgrading QColdsweat, you must have previously made manual modifications to Coldsweat's configuration file and the program can not install or upgrade automatically. In such an event, your old configuration file will have been saved in the [data folder](https://github.com/SkyCrawl/qcoldsweat/wiki) and I kindly ask you to:
1. Merge the backed-up configuration file (e.g. `config.5AE3`) into the new one (named `config`).
2. SSH into your QNAP and run the following two commands (excluding the initial '$' character):
```
$ INSTALL_PATH="$(/sbin/getcfg QColdsweat Install_Path -f /etc/config/qpkg.conf)"
Expand Down
67 changes: 34 additions & 33 deletions package_routines
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

## Entware dependency QPKG name.
ENTWARE_NAME="Entware"
CNF_CHKSM_NAME="config-checksum"
CNF_CHKSM_NAME="config.checksum"

## Installation log file.
QPKG_LOG_FILE="/var/log/coldsweat-install-tmp.log"
Expand Down Expand Up @@ -218,7 +218,7 @@ pkg_check_requirement()
{
# the same requirement is specified in 'qpkg.cfg' but it doesn't hurt to really make sure
if [ -z "$($CMD_GETCFG $ENTWARE_NAME $SYS_QPKG_CONF_FIELD_NAME -f $SYS_QPKG_CONFIG_FILE)" ]; then
err_log "$ENTWARE_NAME is not installed. See 'https://github.com/Entware/Entware/wiki/Install-on-QNAP-NAS'."
my_exit "$ENTWARE_NAME is not installed. See 'https://github.com/Entware/Entware/wiki/Install-on-QNAP-NAS'."
else
$CMD_ECHO -e "--- $ENTWARE_NAME... found"
fi
Expand Down Expand Up @@ -374,24 +374,34 @@ pkg_install()
# install/upgrade Coldsweat dependencies
$CMD_TAR xf "lib/coldsweat-0.9.7.tar.gz"
$CMD_MV "coldsweat-0.9.7" "coldsweat"
$CMD_ECHO -e "\n[Installing Coldsweat dependencies...]"
$CMD_PIP install -r "coldsweat/requirements.txt"
if [ ! -z "$IS_UPGRADE" ]; then
if [ -z "$IS_UPGRADE" ]; then
# if package is being installed
$CMD_ECHO -e "\n[Installing Coldsweat dependencies...]"
$CMD_PIP install -r "coldsweat/requirements.txt"
else
# if package is being upgraded/downgraded, upgrade Coldsweat's dependencies
$CMD_ECHO -e "\n[Upgrading Coldsweat dependencies...]"
$CMD_PIP install -r --upgrade "coldsweat/requirements.txt"
fi

# install Coldsweat configuration file
# install Coldsweat's configuration file
$CMD_ECHO -e "\n[Configuring and patching Coldsweat...]"
$CMD_ECHO -e "--- Preparing the configuration file"
$CMD_ECHO -e "--- Installing the configuration file"
# Note: use external folder so that important files may survive NAS restart or QPKG uninstall
# Note: if the external configuration file already exists, back it up using a random sequence
CNF_NEW="config"
CNF_BACKED_UP=false
if [ -f "$CS_DATA_FOLDER/config" ]; then
RAND_SEQ=$(openssl rand -hex 4)
CNF_NEW="config.$RAND_SEQ"
$CMD_MV "$CS_DATA_FOLDER/config" "$CS_DATA_FOLDER/$CNF_NEW"
CNF_CHKSM_OLD=$($CMD_CAT "$CS_DATA_FOLDER/$CNF_CHKSM_NAME")
CNF_CHKSM_NOW=$($CMD_MD5SUM "$CS_DATA_FOLDER/config" | /bin/dd count=32 bs=1 2>/dev/null)
if [ ! -f "$CS_DATA_FOLDER/$CNF_CHKSM_NAME" -o $CNF_CHKSM_OLD != $CNF_CHKSM_NOW ]; then
# if manual modifications were made or we don't have a way to compare, backup the old configuration file
RAND_SEQ=$(/usr/bin/openssl rand -hex 4)
$CMD_MV "$CS_DATA_FOLDER/config" "$CS_DATA_FOLDER/config.$RAND_SEQ"
CNF_BACKED_UP=true
else
# if no manual modifications were made, replace the old configuration file
$CMD_RM "$CS_DATA_FOLDER/config"
fi
fi
$CMD_MV "lib/coldsweat-config" "$CS_DATA_FOLDER/config"

Expand All @@ -404,30 +414,21 @@ pkg_install()
$CMD_ECHO -e "--- Patching Coldsweat to find the configuration file"
$CMD_SED -i "s:os.path.join(installation_dir, 'etc/config'):'$CS_DATA_FOLDER/config':" "coldsweat/coldsweat/__init__.py"

# sometimes, we could also upgrade the database automatically
# sorry but this is going to be a little complicated...
if [ ! -z "$IS_UPGRADE" ]; then
# if package is being upgraded/downgraded...
CNF_CHKSM_NOW=$($CMD_MD5SUM "$CS_DATA_FOLDER/config" | dd count=32 bs=1 2>/dev/null)
CNF_CHKSM_OLD=$($CMD_CAT "$CS_DATA_FOLDER/$CNF_CHKSM_NAME")
if [ "$CNF_CHKSM_NOW" = "$CNF_CHKSM_OLD" ]; then
# if user HASN'T made any modifications to the config file...
$CMD_ECHO -e "\n[Upgrading Coldsweat's database...]"
# upgrade the database
# if package is being upgraded/downgraded (not installed)
if [ $CNF_BACKED_UP = false ]; then
# if user HASN'T made any modifications to the configuration file
$CMD_ECHO -e "--- Automatically upgrading Coldsweat's database..."
$CMD_PYTHON "coldsweat/sweat.py" upgrade
# and get rid of the previous config file
if [ "$CNF_NEW" != "config" ]; then
$CMD_RM "$CS_DATA_FOLDER/$CNF_NEW"
fi
else
# if user HAS made Modifications to the config file...
warn_log "Configuration file needs to be upgraded manually. See 'https://github.com/SkyCrawl/QColdsweat'."
# if user HAS made modifications to the configuration file
warn_log "QColdsweat: Some manual actions are needed. Please read 'https://github.com/SkyCrawl/qcoldsweat/tree/0.9.7-3#upgrading'."
fi
fi

# everything's ready to (maybe) init Coldsweat and create a default account
if [ -z "$IS_UPGRADE" ] && [ ! -f "$CS_DATA_FOLDER/sqlite.db" ]; then
elif [ ! -f "$CS_DATA_FOLDER/sqlite.db" ]; then
# if package is being installed (not upgraded/downgraded) AND the database doesn't exist yet
$CMD_ECHO -e "--- Creating default account"
$CMD_ECHO -e "--- Creating SQLite database and default account..."
# create database and a default account
# Note: no leading white-spaces on lines between the EOF boundaries
$CMD_PYTHON "coldsweat/sweat.py" setup -u "$CS_DEFAULT_USERNAME" <<EOF
$CS_DEFAULT_EMAIL
Expand All @@ -439,9 +440,9 @@ EOF
# announce the final phase
$CMD_ECHO -e "\n[Finalizing installation...]"

# backup a checksum of the configuration file now (useful when we're upgrading)
# backup a checksum of the configuration file (useful above)
$CMD_ECHO -e "--- Backing up configuration file checksum"
$CMD_MD5SUM "$CS_DATA_FOLDER/config" | dd count=32 bs=1 2>/dev/null > "$CS_DATA_FOLDER/$CNF_CHKSM_NAME"
$CMD_MD5SUM "$CS_DATA_FOLDER/config" | /bin/dd count=32 bs=1 2>/dev/null > "$CS_DATA_FOLDER/$CNF_CHKSM_NAME"

# patch entware to always find our own installed software
# $CMD_ECHO -e "--- Patching $ENTWARE_NAME to find our own compiled/installed software"
Expand Down
36 changes: 20 additions & 16 deletions shared/QColdsweat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ function is_coldsweat_running()
# basic check
if [ ! -f "$CS_PID_FILE" ]; then
# DEBUG msg: echo "PID file doesn't exist" >> "$LOG_FILE"
echo "0"
/bin/echo "0"
return
fi

# "$()" spawns a new process - must use `` instead (PID would be incorrect otherwise)
PID=`cat "$CS_PID_FILE"`
if [ -z "$PID" ]; then
echo "0"
/bin/echo "0"
return
fi

Expand All @@ -65,10 +65,10 @@ function is_coldsweat_running()

# and finally...
if [ -z "$PID_INFO" ]; then
echo "0"
/bin/echo "0"
# DEBUG msg: echo "The $PID PID could not be matched against a running instance" >> "$LOG_FILE"
else
echo "1"
/bin/echo "1"
fi
}

Expand Down Expand Up @@ -101,10 +101,14 @@ COMMENT
# perform the given action
case "$1" in
start)
# disabled QPKG has no right to start...
ENABLED="$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $QPKG_CONF)"
if [ "$ENABLED" != "TRUE" ]; then
echo "$QPKG_NAME is disabled."
# determine and check status
QPKG_ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $QPKG_CONF)
if [ "$QPKG_ENABLED" = "UNKNOWN" ]; then
# do enable the QPKG
/sbin/setcfg "$QPKG_NAME" Enable TRUE -f "$QPKG_CONF"
elif [ "$QPKG_ENABLED" != "TRUE" ]; then
# disabled QPKG has no right to start...
/bin/echo "$QPKG_NAME is disabled."
exit 1
fi

Expand All @@ -114,7 +118,7 @@ case "$1" in
# Luckily, Coldsweat is smart enough to automatically eliminate subsequent running
# instances.
if [ "$(is_coldsweat_running)" == "1" ]; then
echo "Stopping the current instance..."
/bin/echo "Stopping the current instance..."
./$0 stop
# Note: doesn't work properly without these additional commands...
/bin/sleep 5
Expand All @@ -126,9 +130,9 @@ case "$1" in
# v0.9.6 to v0.9.7 contains a bug that prevents Coldsweat from being launched from a different folder...
cd "$CS_DIST_ROOT"
$CMD_PYTHON sweat.py serve -r -p "$QPKG_PORT" &> "$CS_LOG_ACCESS" &
echo $! > "$CS_PID_FILE"
/bin/echo $! > "$CS_PID_FILE"
else
echo "$APP_NAME is already running."
/bin/echo "$APP_NAME is already running."
exit 1
fi
;;
Expand All @@ -138,19 +142,19 @@ case "$1" in
if [ "$(is_coldsweat_running)" == "1" ]; then
# "$()" spawns a new process - must use `` instead (PID would be incorrect otherwise)
PID=`cat "$CS_PID_FILE"`
kill $PID
/bin/kill $PID
else
echo "$APP_NAME is not running."
/bin/echo "$APP_NAME is not running."
exit 1
fi
;;

test)
# test whether the service is running
if [ "$(is_coldsweat_running)" == "1" ]; then
echo "$APP_NAME is running."
/bin/echo "$APP_NAME is running."
else
echo "$APP_NAME is NOT running."
/bin/echo "$APP_NAME is NOT running."
fi
;;

Expand All @@ -163,7 +167,7 @@ case "$1" in
;;

*)
echo "Usage: $0 {start|stop|restart|test}"
/bin/echo "Usage: $0 {start|stop|restart|test}"
exit 1
esac

Expand Down

0 comments on commit dc3e7ca

Please sign in to comment.