diff options
| author | manuel <manuel@mausz.at> | 2013-12-25 13:25:16 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2013-12-25 13:25:16 +0100 |
| commit | 0c8c9ad976879f7c90f9915a60845ccb0cdb337d (patch) | |
| tree | 162951b4713f3836f4114958a423e2c90ecf9c6b /setup.sh | |
| download | webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.gz webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.bz2 webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.zip | |
initial commit
Diffstat (limited to 'setup.sh')
| -rwxr-xr-x | setup.sh | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..865c6fe --- /dev/null +++ b/setup.sh | |||
| @@ -0,0 +1,126 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # WebIOPi setup script | ||
| 3 | |||
| 4 | SEARCH="python python3" | ||
| 5 | FOUND="" | ||
| 6 | INSTALLED="" | ||
| 7 | |||
| 8 | if [ "$#" = "1" ]; then | ||
| 9 | command="$1" | ||
| 10 | else | ||
| 11 | command="none" | ||
| 12 | fi | ||
| 13 | |||
| 14 | echo | ||
| 15 | echo "Installing WebIOPi..." | ||
| 16 | echo | ||
| 17 | |||
| 18 | if [ "$command" != "skip-apt" ]; then | ||
| 19 | echo "Updating apt package list..." | ||
| 20 | apt-get update | ||
| 21 | echo | ||
| 22 | fi | ||
| 23 | |||
| 24 | # Install Python library | ||
| 25 | cd python | ||
| 26 | |||
| 27 | # Look up for installed python | ||
| 28 | for python in $SEARCH; do | ||
| 29 | program="/usr/bin/$python" | ||
| 30 | if [ -x $program ]; then | ||
| 31 | FOUND="$FOUND $python" | ||
| 32 | version=`$python -V 2>&1` | ||
| 33 | include=`$python -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_inc())"` | ||
| 34 | echo "Found $version... " | ||
| 35 | |||
| 36 | if [ "$command" != "skip-apt" ]; then | ||
| 37 | # Install required dev header and setuptools | ||
| 38 | echo "Trying to install $python-dev using apt-get" | ||
| 39 | apt-get install -y $python-dev $python-setuptools | ||
| 40 | fi | ||
| 41 | |||
| 42 | # Try to compile and install for the current python | ||
| 43 | if [ -f "$include/Python.h" ]; then | ||
| 44 | echo "Trying to install WebIOPi for $version" | ||
| 45 | $python setup.py install | ||
| 46 | if [ "$?" -ne "0" ]; then | ||
| 47 | # Sub setup error, continue with next python | ||
| 48 | echo "Build for $version failed\n" | ||
| 49 | continue | ||
| 50 | fi | ||
| 51 | echo "WebIOPi installed for $version\n" | ||
| 52 | INSTALLED="$INSTALLED $python" | ||
| 53 | else | ||
| 54 | echo "Cannot install for $version : missing development headers\n" | ||
| 55 | fi | ||
| 56 | fi | ||
| 57 | done | ||
| 58 | |||
| 59 | # Go back to the root folder | ||
| 60 | cd .. | ||
| 61 | |||
| 62 | # Ensure WebIOPi is installed to continue | ||
| 63 | if [ -z "$INSTALLED" ]; then | ||
| 64 | if [ -z "$FOUND" ]; then | ||
| 65 | echo "ERROR: WebIOPi cannot be installed - neither python or python3 found" | ||
| 66 | exit 1 | ||
| 67 | else | ||
| 68 | echo "ERROR: WebIOPi cannot be installed - please check errors above" | ||
| 69 | exit 2 | ||
| 70 | fi | ||
| 71 | fi | ||
| 72 | |||
| 73 | # Select greater python version | ||
| 74 | for python in $INSTALLED; do | ||
| 75 | echo $python > /dev/null | ||
| 76 | done | ||
| 77 | |||
| 78 | # Update HTML resources | ||
| 79 | echo "Copying HTML resources..." | ||
| 80 | mkdir /usr/share/webiopi 2>/dev/null 1>/dev/null | ||
| 81 | cp -rfv htdocs /usr/share/webiopi | ||
| 82 | echo | ||
| 83 | |||
| 84 | # Add config file if it does not exist | ||
| 85 | if [ ! -f "/etc/webiopi/config" ]; then | ||
| 86 | echo "Copying default config file..." | ||
| 87 | mkdir /etc/webiopi 2>/dev/null 1>/dev/null | ||
| 88 | cp -v python/config /etc/webiopi/config | ||
| 89 | fi | ||
| 90 | |||
| 91 | # Add passwd file if it does not exist | ||
| 92 | if [ ! -f "/etc/webiopi/passwd" ]; then | ||
| 93 | echo "Copying default passwd file..." | ||
| 94 | mkdir /etc/webiopi 2>/dev/null 1>/dev/null | ||
| 95 | cp -v python/passwd /etc/webiopi/passwd | ||
| 96 | fi | ||
| 97 | |||
| 98 | # Add service/daemon script | ||
| 99 | #if [ ! -f "/etc/init.d/webiopi" ]; then | ||
| 100 | echo "Installing startup script..." | ||
| 101 | cp -rf python/webiopi.init.sh /etc/init.d/webiopi | ||
| 102 | sed -i "s/python/$python/g" /etc/init.d/webiopi | ||
| 103 | chmod 0755 /etc/init.d/webiopi | ||
| 104 | |||
| 105 | # Add webiopi command | ||
| 106 | echo "Installing webiopi command..." | ||
| 107 | cp -rf python/webiopi.sh /usr/bin/webiopi | ||
| 108 | sed -i "s/python/$python/g" /usr/bin/webiopi | ||
| 109 | chmod 0755 /usr/bin/webiopi | ||
| 110 | |||
| 111 | # Add webiopi-passwd command | ||
| 112 | echo "Installing webiopi-passwd command..." | ||
| 113 | cp -rf python/webiopi-passwd.py /usr/bin/webiopi-passwd | ||
| 114 | sed -i "s/python/$python/g" /usr/bin/webiopi-passwd | ||
| 115 | chmod 0755 /usr/bin/webiopi-passwd | ||
| 116 | |||
| 117 | # Display WebIOPi usages | ||
| 118 | echo | ||
| 119 | echo "WebIOPi successfully installed" | ||
| 120 | echo "* To start WebIOPi foreground\t: sudo webiopi [-h] [-c config] [-l log] [-s script] [-d] [port]" | ||
| 121 | echo | ||
| 122 | echo "* To start WebIOPi background\t: sudo /etc/init.d/webiopi start" | ||
| 123 | echo "* To start WebIOPi at boot\t: sudo update-rc.d webiopi defaults" | ||
| 124 | echo | ||
| 125 | echo "* Look in `pwd`/examples for Python library usage examples" | ||
| 126 | echo | ||
