summaryrefslogtreecommitdiffstats
path: root/setup.sh
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-12-25 13:25:16 +0100
committermanuel <manuel@mausz.at>2013-12-25 13:25:16 +0100
commit0c8c9ad976879f7c90f9915a60845ccb0cdb337d (patch)
tree162951b4713f3836f4114958a423e2c90ecf9c6b /setup.sh
downloadwebiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.gz
webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.tar.bz2
webiopi-0c8c9ad976879f7c90f9915a60845ccb0cdb337d.zip
initial commit
Diffstat (limited to 'setup.sh')
-rwxr-xr-xsetup.sh126
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
4SEARCH="python python3"
5FOUND=""
6INSTALLED=""
7
8if [ "$#" = "1" ]; then
9 command="$1"
10else
11 command="none"
12fi
13
14echo
15echo "Installing WebIOPi..."
16echo
17
18if [ "$command" != "skip-apt" ]; then
19 echo "Updating apt package list..."
20 apt-get update
21 echo
22fi
23
24# Install Python library
25cd python
26
27# Look up for installed python
28for 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
57done
58
59# Go back to the root folder
60cd ..
61
62# Ensure WebIOPi is installed to continue
63if [ -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
71fi
72
73# Select greater python version
74for python in $INSTALLED; do
75 echo $python > /dev/null
76done
77
78# Update HTML resources
79echo "Copying HTML resources..."
80mkdir /usr/share/webiopi 2>/dev/null 1>/dev/null
81cp -rfv htdocs /usr/share/webiopi
82echo
83
84# Add config file if it does not exist
85if [ ! -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
89fi
90
91# Add passwd file if it does not exist
92if [ ! -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
96fi
97
98# Add service/daemon script
99#if [ ! -f "/etc/init.d/webiopi" ]; then
100echo "Installing startup script..."
101cp -rf python/webiopi.init.sh /etc/init.d/webiopi
102sed -i "s/python/$python/g" /etc/init.d/webiopi
103chmod 0755 /etc/init.d/webiopi
104
105# Add webiopi command
106echo "Installing webiopi command..."
107cp -rf python/webiopi.sh /usr/bin/webiopi
108sed -i "s/python/$python/g" /usr/bin/webiopi
109chmod 0755 /usr/bin/webiopi
110
111# Add webiopi-passwd command
112echo "Installing webiopi-passwd command..."
113cp -rf python/webiopi-passwd.py /usr/bin/webiopi-passwd
114sed -i "s/python/$python/g" /usr/bin/webiopi-passwd
115chmod 0755 /usr/bin/webiopi-passwd
116
117# Display WebIOPi usages
118echo
119echo "WebIOPi successfully installed"
120echo "* To start WebIOPi foreground\t: sudo webiopi [-h] [-c config] [-l log] [-s script] [-d] [port]"
121echo
122echo "* To start WebIOPi background\t: sudo /etc/init.d/webiopi start"
123echo "* To start WebIOPi at boot\t: sudo update-rc.d webiopi defaults"
124echo
125echo "* Look in `pwd`/examples for Python library usage examples"
126echo