Skip to content

Commit

Permalink
Upgrading to support DSM 5.x
Browse files Browse the repository at this point in the history
- install script now detects DSM version and changes path accordingly.
  • Loading branch information
song31 committed Jan 21, 2015
1 parent 4fb375a commit 403257d
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 68 deletions.
33 changes: 20 additions & 13 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ This guide is written based on Synology DSM version 4.1, but menus and features
DiskStation> ./install.sh
```

The installer does everything for you, even restarts Apache HTTP Server. Now you can add your comix-server in the AirComics app. Use **Enter Address Manually** and put the server name, IP address, and the port number. The default port numer is 31257.
The installer does everything for you: detects DSM version to determine configuration file path, updates Apahe and PHP configuration, installs comix-server, and restarts Apache HTTP Server. Now you can add your comix-server in the AirComics app. Use **Enter Address Manually** and put the server name, IP address, and the port number. The default port numer is 31257.


## Uninstallation using uninstaller
Expand Down Expand Up @@ -102,7 +102,7 @@ The uninstaller removes only comix-server's files and configuration. **It does N
## Manual installation (optional)

This section describes how to install comix-server manually without using installer. **If you already installed comix-server using installer, skip this section.**
Most of the Apache configuration will be done on the Linux shell so you need to prepare an SSH client to connect to your Synology server. Any command starting with DistStation> in this guide should be run on the shell in the Synology server.
Most of the Apache configuration will be done on the Linux shell so you need to prepare an SSH client to connect to your Synology server. Any command starting with "DistStation>" in this guide should be run on the shell in the Synology server.

- Connect to your Synology NAS as *root* using an SSH client. The password of the *root* account is same as the admin user's in DSM.

Expand Down Expand Up @@ -130,7 +130,7 @@ Most of the Apache configuration will be done on the Linux shell so you need to
DiskStation> cp /var/services/web/comix-server/conf/httpd.conf-comix /usr/syno/apache/conf/httpd.conf-comix
```

- Open /usr/syno/apache/conf/httpd.conf-user using a text editor, I guess the only option is vi, and add the following line, Include /usr/syno/apache/conf/httpd.conf-comix, at the end of the file. The httpd.conf-user file is a template for httpd.conf, which is the actual configuration file for Apache. The httpd.conf file is regenerated based on the template file whenever the Synology server boots up.
- Open /usr/syno/apache/conf/httpd.conf-user using a text editor, I guess the only option is vi, and add the following line, "Include /usr/syno/apache/conf/httpd.conf-comix", at the end of the file. The httpd.conf-user file is a template for httpd.conf, which is the actual configuration file for Apache. The httpd.conf file is regenerated based on the template file whenever the Synology server boots up.

```
DiskStation> cd /usr/syno/apache/conf
Expand All @@ -145,25 +145,32 @@ Most of the Apache configuration will be done on the Linux shell so you need to
- Also add the same line to /usr/syno/apache/conf/httpd.conf to apply it without rebooting.

- Open /usr/syno/etc/php/user-setting.ini and add the *web* and *manga* directorys full path at the end of the *open_basedir* variable. **Note that you should put a colon in front of each path**.
- Open /usr/syno/etc/php/user-setting.ini and add the *web* and *manga* directory's full path at the end of the *open_basedir* variable. **Note that you should put a colon in front of each path**.

```
DiskStation> cd /usr/syno/etc/php
DiskStation> vi user-setting.ini
```

> open_basedir = xxxyyyyzzzz:/var/services/web/comix-server:/volume1/maa
> open_basedir = xxxyyyyzzzz:/var/services/web/comix-server:/volume1/manga
Note that the *manga* directory's path, /volume1/manga, might be different in your server. Make sure you are entering the correct path. See Customization section if you have a different path.

- Make sure your *manga* directory has the right Linux file permission so comix-server can access it.

```
DiskStation> chmod 755 /volume1/manga
```

- Restart httpd to apply configuration change, or you can reboot the system using DSM menu.
- Find httpd parent processs PID.
- Find httpd parent process's PID.

```
DiskStation> ps | grep HAVE_PHP
```
In the result, the first number followed by root is the PID like below.
In the result, the first number followed by "root" is the PID like below.
```
10442 root 65032 S /usr/syno/apache/bin/httpd -DHAVE_PHP
Expand Down Expand Up @@ -297,8 +304,8 @@ Now the server-side password is enabled. You need to enter the password (e.g., 1
## Troubleshooting
1. If you cannot connect to comix-server or get Can not connect to server error message, check the following list.
- Httpd processes. There should be a few /usr/syno/apache/bin/httpd -DHAVE_PHP processes running on the Synology server.
1. If you cannot connect to comix-server or get "Can not connect to server" error message, check the following list.
- Httpd processes. There should be a few "/usr/syno/apache/bin/httpd -DHAVE_PHP" processes running on the Synology server.
- Correct port number.
- Correct password, if server-side password is enabled.
Expand All @@ -308,14 +315,14 @@ Now the server-side password is enabled. You need to enter the password (e.g., 1
You can test comix-server using a web browser. Open a web browser and go to http://\<your synology ip\>:31257. The browser should display the name of your manga directory.
4. If you dont see the list of directories and files after you click the *manga* directory, check the following list.
4. If you don't see the list of directories and files after you click the *manga* directory, check the following list.
- *Manga* directory configuration. See Customization section to know how to configure/change the *manga* directory.
- Linux permission of the directories and files. Apache HTTP Server runs as nobody so all users should have execution permission (x) on all directories from root to any subdirectories under your manga directory. All users should also have read permission (r) on all your manga files. Change permission carefully using the chmod command on the shell.
- PHP open_basedir configuration. By default, PHP can open files in any directories, but the access is limited to specific directories by setting the open_basedir variable. In Synology, you should add your *manga* directory in /usr/syno/etc/php/user-setting.ini because this limitation is on by default. In Linux, open_basedir is usually not set on and you dont need to add your directories in it. Refer to http://php.net/manual/en/ini.core.php for more information.
- Linux permission of the directories and files. Apache HTTP Server runs as nobody (or http) so all users should have execution permission (x) on all directories from root to any subdirectories under your manga directory. All users should also have read permission (r) on all your manga files. Change permission carefully using the chmod command on the shell. **Note that in DSM 5.x, default permision of shared directories is 000 so you need to run 'chmod 755 /volume1/manga' after creating your *manga* directory.**
- PHP open_basedir configuration. By default, PHP can open files in any directories, but the access is limited to specific directories by setting the open_basedir variable. In Synology, you should add your *manga* directory in /usr/syno/etc/php/user-setting.ini because this limitation is on by default. In Linux, open_basedir is usually not set on and you don't need to add your directories in it. Refer to http://php.net/manual/en/ini.core.php for more information.
You can test comix-server using a web browser. Open a web browser and go to http://\<your synology ip\>:31257/manga. The directories or files under your manga folder will show up in the browser.
Lets say we have a file, /volume1/manga/folder1/01.zip and 01.zip contains 01.jpg to 10.jpg. Requesting http://\<your synology ip\>:31257/manga will show folder1 in the browser and requesting http://\<your synology ip\>:31257/manga/folder1 will show 01.zip. Requesting http://\<your synology ip\>:31257/manga/folder1/01.zip will return the list of files in the ZIP file: 01.jpg to 10.jpg. Finally, requesting http://\<your synology ip\>:31257/manga/folder1/01.zip/01.jpg will display the actual image in the browser.
Let's say we have a file, /volume1/manga/folder1/01.zip and 01.zip contains 01.jpg to 10.jpg. Requesting http://\<your synology ip\>:31257/manga will show folder1 in the browser and requesting http://\<your synology ip\>:31257/manga/folder1 will show 01.zip. Requesting http://\<your synology ip\>:31257/manga/folder1/01.zip will return the list of files in the ZIP file: 01.jpg to 10.jpg. Finally, requesting http://\<your synology ip\>:31257/manga/folder1/01.zip/01.jpg will display the actual image in the browser.
5. If you see "can't open xxxxx.zip" when you request a ZIP file from a web browser, check the *open_basedir* variable in the user-setting.ini file. Make sure you correctly add your *manga* directory in the list. Also check whether each path in the list is separated by colons.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Comix-server is compatible with both AirComix (old version) and AirComics

## How to install

- Please note that install script was only tested on Synology DSM 4.x. You might need to change the path of apache or php to run it on DSM 5.x.
- Installer now supports both **DSM 5.x** and 4.x.
- Log in to the Synology DSM and make a shared folder, for example,
named "manga". This directory will be your manga directory.
- Enable SSH and Web Station.
Expand All @@ -33,7 +33,7 @@ Comix-server is compatible with both AirComix (old version) and AirComics
DiskStation> ./install.sh
```

For more information, please refer to the [step-by-step guide](https://github.com/song31/comix-server/wiki/Step-by-Step-Configuration-Guide).
For more information about installation, please refer to the [INSTALL.md](https://github.com/song31/comix-server/blob/master/INSTALL.md).


## How to uninstall
Expand Down Expand Up @@ -64,6 +64,9 @@ Bug reports and pull requests are always welcome.

## FAQ

Q) Which Synology DSM versions are supported?
A) The install script was tested only on DSM 5.x and 4.x. However, comix-server itself is just a web application written in PHP so it should run on any platforms with HTTPD & PHP.

Q) Which file formats are supported?
A) Comix-server supports archive formats such as ZIP, RAR, CBZ, and CBR.
Also it supports most image formats such as JPG, GIF, PNG, and TIFF.
Expand Down
106 changes: 72 additions & 34 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,72 @@
#!/bin/sh

############################################################################
######################################################################
# !!! modify MANGA_DIR as your manga directory!!!
############################################################################
######################################################################
MANGA_DIR="/volume1/manga"
############################################################################
######################################################################


############################################################################
MANGA_DIR_NAME=`basename ${MANGA_DIR}`
MANGA_PARENT_PATH=`dirname ${MANGA_DIR}`
######################################################################
WEB_DIR="/var/services/web/comix-server"
APACHE_CONF="/usr/syno/apache/conf/httpd.conf"
PHP_CONF="/usr/syno/etc/php/user-setting.ini"
APACHE_CMD="/usr/syno/apache/bin/httpd -DHAVE_PHP"
TEMP_DIR="/tmp"
SOURCE="https://github.com/song31/comix-server/archive/master.zip"
############################################################################

MANGA_DIR_NAME=`basename ${MANGA_DIR}`
MANGA_PARENT_PATH=`dirname ${MANGA_DIR}`
######################################################################
chmod 755 ${MANGA_DIR}
rm -rf ${WEB_DIR}
mkdir -p ${WEB_DIR}


echo "::::::::::::::::::::::::"
echo " 1. Download Scripts"
echo "::::::::::::::::::::::::"

echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 1. Detecting DSM Version"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
DSM_VERSION=`grep majorversion /etc/VERSION |awk -F'=' '{print $2}' |awk -F'"' '{print $2}'`
if [ "$DSM_VERSION" == "4" ]
then
APACHE_CONF="/usr/syno/apache/conf/httpd.conf"
PHP_CONF="/usr/syno/etc/php/user-setting.ini"
APACHE_CMD="/usr/syno/apache/bin/httpd -DHAVE_PHP"
elif [ "$DSM_VERSION" == "5" ]
then
APACHE_CONF="/etc/httpd/conf/httpd.conf"
PHP_CONF="/etc/php/conf.d/user-settings.ini"
APACHE_CMD="/usr/bin/httpd -DHAVE_PHP"
else
echo "ERROR: Cannot detect DSM Version. Exiting..."
exit
fi
echo "Detected DSM version: $DSM_VERSION"
echo ""


echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 2. Backing up current configuration"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
BACKUP_DIR="/root/comix-server-backup"
mkdir -p ${BACKUP_DIR}
cp ${APACHE_CONF} ${BACKUP_DIR}
cp ${APACHE_CONF}-user ${BACKUP_DIR}
cp ${PHP_CONF} ${BACKUP_DIR}
echo "Backup location: $BACKUP_DIR"


echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 3. Downloading comix-server from github"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
cd ${TEMP_DIR}
wget --no-check-certificate -O comix-server-master.zip ${SOURCE}
unzip comix-server-master.zip
cp -rf comix-server-master/* ${WEB_DIR}
rm -rf comix-server-master.zip comix-server-master
echo "Downloaded from: $SOURCE"
echo ""


echo "::::::::::::::::::::::::"
echo " 2. Configure comix"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 4. Configuring comix-server"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
cp ${WEB_DIR}/index.php ${WEB_DIR}/index.php.org
sed -e 's/\"manga\"/\"'"${MANGA_DIR_NAME}"'\"/' ${WEB_DIR}/index.php.org > ${WEB_DIR}/index.php

Expand All @@ -45,12 +76,13 @@ sed -e 's/\"\/volume1\"/\"'"${TMP}"'\"/' ${WEB_DIR}/handler.php.org > ${WEB_DIR}

cp ${WEB_DIR}/conf/httpd.conf-comix ${WEB_DIR}/conf/httpd.conf-comix.org
sed -e 's/manga/'"${MANGA_DIR_NAME}"'/' ${WEB_DIR}/conf/httpd.conf-comix.org > ${WEB_DIR}/conf/httpd.conf-comix
echo "Installed at $WEB_DIR"
echo ""


echo "::::::::::::::::::::::::"
echo " 3. Configure Apache"
echo "::::::::::::::::::::::::"

echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 5. Configuring Apache HTTPD"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
if [ -f ${APACHE_CONF}-user ]
then
cp ${WEB_DIR}/conf/httpd.conf-comix ${APACHE_CONF}-comix
Expand Down Expand Up @@ -79,35 +111,41 @@ then
else
echo "ERROR: File ${APACHE_CONF} does not exist."
fi

echo "Modified ${APACHE_CONF} and ${APACHE_CONF}-user"
echo ""

echo "::::::::::::::::::::::::"
echo " 4. Configure PHP"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 6. Configuring PHP"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

if [ -f ${PHP_CONF} ]
then
if grep -qs "$WEB_DIR:$MANGA_DIR" ${PHP_CONF}
then
echo "File ${PHP_CONF} already configured."
else
mv ${PHP_CONF} ${PHP_CONF}.org
cp ${PHP_CONF} ${PHP_CONF}.org
OLD_LINE=`grep open_basedir ${PHP_CONF}.org`
NEW_LINE=$OLD_LINE":"$WEB_DIR":"$MANGA_DIR
echo $NEW_LINE > ${PHP_CONF}
sed 1d ${PHP_CONF}.org >> ${PHP_CONF}
sed -i "/open_basedir/c\\$NEW_LINE" ${PHP_CONF}
fi
else
echo "ERROR: File ${PHP_CONF} does not exist."
fi
echo "Modified ${PHP_CONF}"
echo ""


echo "::::::::::::::::::::::::"
echo " 5. Restart HTTPD"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 7. Restarting Apache HTTPD"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

kill `ps | grep HAVE_PHP | grep root | grep -v grep | awk '{print $1}'`
echo "Wait 5 seconds... "
echo "Waiting for 5 seconds..."
sleep 5
${APACHE_CMD}

if [ `ps | grep HAVE_PHP | grep root | grep -v grep | wc -l` -eq 0 ];
then
${APACHE_CMD}
fi
echo "Comix-server installed. Enjoy!"
59 changes: 40 additions & 19 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
#!/bin/sh

############################################################################
######################################################################
WEB_DIR="/var/services/web/comix-server"
APACHE_CONF="/usr/syno/apache/conf/httpd.conf"
PHP_CONF="/usr/syno/etc/php/user-setting.ini"
APACHE_CMD="/usr/syno/apache/bin/httpd -DHAVE_PHP"
############################################################################
######################################################################

echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 1. Detecting DSM Version"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
DSM_VERSION=`grep majorversion /etc/VERSION |awk -F'=' '{print $2}' |awk -F'"' '{print $2}'`
if [ "$DSM_VERSION" == "4" ]
then
APACHE_CONF="/usr/syno/apache/conf/httpd.conf"
PHP_CONF="/usr/syno/etc/php/user-setting.ini"
APACHE_CMD="/usr/syno/apache/bin/httpd -DHAVE_PHP"
elif [ "$DSM_VERSION" == "5" ]
then
APACHE_CONF="/etc/httpd/conf/httpd.conf"
PHP_CONF="/etc/php/conf.d/user-settings.ini"
APACHE_CMD="/usr/bin/httpd -DHAVE_PHP"
else
echo "ERROR: Cannot detect DSM Version. Exiting..."
exit
fi
echo "Detected DSM version: $DSM_VERSION"

echo "::::::::::::::::::::::::"
echo "1. Remove comix-server"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 2. Removing comix-server"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

if [ -f ${WEB_DIR} ]
if [ -e ${WEB_DIR} ]
then
rm -rf ${WEB_DIR}
fi


echo "::::::::::::::::::::::::"
echo "2. Undo Configure Apache"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 3. Restoring Apache HTTPD"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

if [ -f ${APACHE_CONF}-comix ]
then
Expand All @@ -38,21 +54,26 @@ then
fi


echo "::::::::::::::::::::::::"
echo "3. Undo Configure PHP"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 4. Restoring PHP"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

if [ -f ${PHP_CONF}.org ]
then
mv -f ${PHP_CONF}.org ${PHP_CONF}
fi


echo "::::::::::::::::::::::::"
echo "4. Restart HTTPD"
echo "::::::::::::::::::::::::"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo " 5. Restarting Apache HTTPD"
echo ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"

kill `ps | grep HAVE_PHP | grep root | grep -v grep | awk '{print $1}'`
echo "Waiting for 5 seconds... "
sleep 5
${APACHE_CMD}

if [ `ps | grep HAVE_PHP | grep root | grep -v grep | wc -l` -eq 0 ];
then
${APACHE_CMD}
fi
echo "Comix-server uninstalled."

0 comments on commit 403257d

Please sign in to comment.