coffin

secure lan file storage on a device
git clone git://parazyd.org/coffin.git
Log | Files | Refs | Submodules | README | LICENSE

setup_features.sh (2411B)


      1 #!/usr/bin/env zsh
      2 #
      3 # Copyright (c) 2016 Dyne.org Foundation
      4 # coffin is written and maintained by Ivan J. <parazyd@dyne.org>
      5 #
      6 # This file is part of coffin
      7 #
      8 # This source code is free software: you can redistribute it and/or modify
      9 # it under the terms of the GNU General Public License as published by
     10 # the Free Software Foundation, either version 3 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This software is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # You should have received a copy of the GNU General Public License
     19 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
     20 
     21 features="$@"
     22 
     23 [[ $UID = 0 ]] || { print "(!!) this script should be ran as root";exit 1 }
     24 
     25 if [[ $1 == install ]]; then
     26 	$(grep '^coffin' /etc/group) || groupadd coffin
     27 	[[ $features =~ webdav ]]    && setup-webdav on
     28 	[[ $features =~ ssh ]]       && setup-ssh on
     29 	#enable-sudoers
     30 elif [[ $1 == uninstall ]]; then
     31 	$(grep '^coffin' /etc/group) && groupdel coffin
     32 	[[ $features =~ webdav ]]    && setup-webdav off
     33 	[[ $features =~ ssh ]]       && setup-ssh off
     34 	#disable-sudoers
     35 fi
     36 
     37 
     38 ## {{{ webdav
     39 detect-webserver() {
     40 	command -v apache2  >/dev/null && webserver=apache && return 0
     41 	command -v nginx    >/dev/null && webserver=nginx  && return 1
     42 	command -v lighttpd >/dev/null && webserver=lighty && return 1
     43 
     44 	return 1
     45 }
     46 
     47 setup-webdav() {
     48 	detect-webserver || {
     49 		echo "(!!) no supported webservers found, sorry"
     50 		exit 1 }
     51 
     52 	if [[ $1 == on ]]; then
     53 		./$(dirname $0)/genssl.sh
     54 		${webserver}-enable
     55 	elif [[ $1 == off ]]; then
     56 		${webserver}-disable
     57 	fi
     58 }
     59 ## {{{ apache2
     60 apache-enable() {
     61 	echo "(*) setting up apache2"
     62 
     63 	cat <<EOF >> /etc/apache2/apache2.conf
     64 
     65 <Directory /media/>
     66 	Options Indexes
     67 	AllowOverride none
     68 	Require all granted
     69 </Directory>
     70 DAVLockDB /etc/apache2/DAV/DAVLock
     71 EOF
     72 
     73 	for i in ssl dav dav_fs dav_lock auth_digest; do
     74 		a2enmod $i
     75 	done
     76 }
     77 apache-disable() {
     78 	echo "(*) unsetting apache2"
     79 	for i in auth_digest dav_lock dav_fs dav ssl; do
     80 		a2dismod $i
     81 	done
     82 
     83 	echo "(*) to remove apache leftovers, remove <Directory /media/> and
     84 	      DAVLockDB parts from /etc/apache2/apache2.conf (at the bottom)"
     85 }
     86 ## }}}
     87 ## {{{ nginx
     88 ## }}}
     89 ## {{{ lighttpd
     90 ## }}}
     91 ## }}}
     92 
     93 ## {{{ ssh
     94 ## }}}