Last active
May 9, 2025 13:34
-
-
Save a7md0/b2f3d179375df911200c1f0d242d2443 to your computer and use it in GitHub Desktop.
[RaspberryPi] Create personal cloud using ownCloud (Dec 28, 2018) Bahrain Polytechnic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Note that all commands and configuration files are pre-prepared by myself, collected from several sources which I will refer to them at the end of the description. Done on RPi3 on Dec 28, 2018 during studies in Bahrain Polytechnic | |
| =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= | |
| The idea itself: https://www.avoiderrors.com/raspberry-pi-3-into-a-personal-cloud-storage-2017/ | |
| Tutorial for installation: https://www.avoiderrors.com/owncloud-10-raspberry-pi-3-raspbian-stretch/ | |
| (Offical download page of the ownCloud software: https://owncloud.org/download/ | |
| Official installation documentation: https://doc.owncloud.org/server/latest/admin_manual/installation/ | |
| System requirements: https://doc.owncloud.org/server/latest/admin_manual/installation/system_requirements.html | |
| =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= | |
| Access Point tutorial: https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md | |
| Install PHP7.2: https://www.rosehosting.com/blog/how-to-install-php-7-2-on-debian-9/ | |
| Configure Nginx web-server with ownCloud: https://doc.owncloud.org/server/10.0/admin_manual/installation/nginx_configuration.html | |
| =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= | |
| Dnsmasq tutorial: https://www.youtube.com/watch?v=Nfs0UDK4I2I + https://www.youtube.com/watch?v=Nfs0UDK4I2I | |
| Dnsmasq releated: | |
| https://stackoverflow.com/questions/9326438/dnsmasq-serve-different-ip-addresses-based-on-interface-used | |
| https://www.raspberrypi.org/forums/viewtopic.php?t=198319 | |
| http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2005q2/000302.html | |
| https://serverfault.com/questions/163542/how-do-you-get-dnsmasq-to-specify-alternate-dns-servers | |
| https://www.raspberrypi.org/forums/viewtopic.php?t=194439 | |
| https://stackoverflow.com/questions/22313142/wildcard-subdomains-with-dnsmasq | |
| https://serverfault.com/questions/136332/setting-up-dnsmasq-for-a-local-network |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set nocompatible | |
| set number | |
| set backspace=indent,eol,start | |
| set tabstop=4 | |
| set autoindent | |
| :inoremap <Esc>Oq 1 | |
| :inoremap <Esc>Or 2 | |
| :inoremap <Esc>Os 3 | |
| :inoremap <Esc>Ot 4 | |
| :inoremap <Esc>Ou 5 | |
| :inoremap <Esc>Ov 6 | |
| :inoremap <Esc>Ow 7 | |
| :inoremap <Esc>Ox 8 | |
| :inoremap <Esc>Oy 9 | |
| :inoremap <Esc>Op 0 | |
| :inoremap <Esc>On . | |
| :inoremap <Esc>OQ / | |
| :inoremap <Esc>OR * | |
| :inoremap <Esc>Ol + | |
| :inoremap <Esc>OS - | |
| :inoremap <Esc>OM <Enter> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ### BEGIN INIT INFO | |
| # Provides: dnsmasq | |
| # Required-Start: $network $remote_fs $syslog | |
| # Required-Stop: $network $remote_fs $syslog | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Description: DHCP and DNS server | |
| ### END INIT INFO | |
| # Don't exit on error status | |
| set +e | |
| PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
| DAEMON=/usr/sbin/dnsmasq | |
| NAME=dnsmasq | |
| DESC="DNS forwarder and DHCP server" | |
| CONFIG_FILE="/etc/dnsmasq.s/dnsmasq-wlan0.conf" | |
| # Most configuration options in /etc/default/dnsmasq are deprecated | |
| # but still honoured. | |
| ENABLED=1 | |
| # if [ -r /etc/default/$NAME ]; then | |
| # . /etc/default/$NAME | |
| # fi | |
| # Get the system locale, so that messages are in the correct language, and the | |
| # charset for IDN is correct | |
| if [ -r /etc/default/locale ]; then | |
| . /etc/default/locale | |
| export LANG | |
| fi | |
| # The following test ensures the dnsmasq service is not started, when the | |
| # package 'dnsmasq' is removed but not purged, even if the dnsmasq-base | |
| # package is still in place. | |
| test -e /usr/share/dnsmasq/installed-marker || exit 0 | |
| test -x $DAEMON || exit 0 | |
| # Provide skeleton LSB log functions for backports which don't have LSB functions. | |
| if [ -f /lib/lsb/init-functions ]; then | |
| . /lib/lsb/init-functions | |
| else | |
| log_warning_msg () { | |
| echo "${@}." | |
| } | |
| log_success_msg () { | |
| echo "${@}." | |
| } | |
| log_daemon_msg () { | |
| echo -n "${1}: $2" | |
| } | |
| log_end_msg () { | |
| if [ $1 -eq 0 ]; then | |
| echo "." | |
| elif [ $1 -eq 255 ]; then | |
| /bin/echo -e " (warning)." | |
| else | |
| /bin/echo -e " failed!" | |
| fi | |
| } | |
| fi | |
| # RESOLV_CONF: | |
| # If the resolvconf package is installed then use the resolv conf file | |
| # that it provides as the default. Otherwise use /etc/resolv.conf as | |
| # the default. | |
| # | |
| # If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit | |
| # filename is set there then this inhibits the use of the resolvconf-provided | |
| # information. | |
| # | |
| # Note that if the resolvconf package is installed it is not possible to | |
| # override it just by configuration in /etc/dnsmasq.conf, it is necessary | |
| # to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq. | |
| if [ ! "$RESOLV_CONF" ] && | |
| [ "$IGNORE_RESOLVCONF" != "yes" ] && | |
| [ -x /sbin/resolvconf ] | |
| then | |
| RESOLV_CONF=/run/dnsmasq/resolv.conf | |
| fi | |
| for INTERFACE in $DNSMASQ_INTERFACE; do | |
| DNSMASQ_INTERFACES="$DNSMASQ_INTERFACES -i $INTERFACE" | |
| done | |
| for INTERFACE in $DNSMASQ_EXCEPT; do | |
| DNSMASQ_INTERFACES="$DNSMASQ_INTERFACES -I $INTERFACE" | |
| done | |
| if [ ! "$DNSMASQ_USER" ]; then | |
| DNSMASQ_USER="dnsmasq" | |
| fi | |
| # This tells dnsmasq to ignore DNS requests that don't come from a local network. | |
| # It's automatically ignored if --interface --except-interface, --listen-address | |
| # or --auth-server exist in the configuration, so for most installations, it will | |
| # have no effect, but for otherwise-unconfigured installations, it stops dnsmasq | |
| # from being vulnerable to DNS-reflection attacks. | |
| DNSMASQ_OPTS="$DNSMASQ_OPTS --local-service" | |
| # If the dns-root-data package is installed, then the trust anchors will be | |
| # available in $ROOT_DS, in BIND zone-file format. Reformat as dnsmasq | |
| # --trust-anchor options. | |
| ROOT_DS="/usr/share/dns/root.ds" | |
| if [ -f $ROOT_DS ]; then | |
| DNSMASQ_OPTS="$DNSMASQ_OPTS `sed -e s/". IN DS "/--trust-anchor=.,/ -e s/" "/,/g $ROOT_DS | tr '\n' ' '`" | |
| fi | |
| start() | |
| { | |
| # Return | |
| # 0 if daemon has been started | |
| # 1 if daemon was already running | |
| # 2 if daemon could not be started | |
| # /run may be volatile, so we need to ensure that | |
| # /run/dnsmasq exists here as well as in postinst | |
| if [ ! -d /run/dnsmasq ]; then | |
| mkdir /run/dnsmasq || return 2 | |
| chown dnsmasq:nogroup /run/dnsmasq || return 2 | |
| fi | |
| start-stop-daemon --start --quiet --pidfile /run/dnsmasq/$NAME.pid --exec $DAEMON --test > /dev/null || return 1 | |
| start-stop-daemon --start --quiet --pidfile /run/dnsmasq/$NAME.pid --exec $DAEMON --conf-file=$CONFIG_FILE -- \ | |
| -x /run/dnsmasq/$NAME.pid \ | |
| ${MAILHOSTNAME:+ -m $MAILHOSTNAME} \ | |
| ${MAILTARGET:+ -t $MAILTARGET} \ | |
| ${DNSMASQ_USER:+ -u $DNSMASQ_USER} \ | |
| ${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \ | |
| ${DHCP_LEASE:+ -l $DHCP_LEASE} \ | |
| ${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \ | |
| ${RESOLV_CONF:+ -r $RESOLV_CONF} \ | |
| ${CACHESIZE:+ -c $CACHESIZE} \ | |
| ${CONFIG_DIR:+ -7 $CONFIG_DIR} \ | |
| ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} \ | |
| || return 2 | |
| } | |
| start_resolvconf() | |
| { | |
| # If interface "lo" is explicitly disabled in /etc/default/dnsmasq | |
| # Then dnsmasq won't be providing local DNS, so don't add it to | |
| # the resolvconf server set. | |
| for interface in $DNSMASQ_EXCEPT | |
| do | |
| [ $interface = lo ] && return | |
| done | |
| # Also skip this if DNS functionality is disabled in /etc/dnsmasq.conf | |
| if grep -qs '^port=0' /etc/dnsmasq.conf; then | |
| return | |
| fi | |
| if [ -x /sbin/resolvconf ] ; then | |
| echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME | |
| fi | |
| return 0 | |
| } | |
| stop() | |
| { | |
| # Return | |
| # 0 if daemon has been stopped | |
| # 1 if daemon was already stopped | |
| # 2 if daemon could not be stopped | |
| # other if a failure occurred | |
| start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile /run/dnsmasq/$NAME.pid --name $NAME | |
| } | |
| stop_resolvconf() | |
| { | |
| if [ -x /sbin/resolvconf ] ; then | |
| /sbin/resolvconf -d lo.$NAME | |
| fi | |
| return 0 | |
| } | |
| status() | |
| { | |
| # Return | |
| # 0 if daemon is running | |
| # 1 if daemon is dead and pid file exists | |
| # 3 if daemon is not running | |
| # 4 if daemon status is unknown | |
| start-stop-daemon --start --quiet --pidfile /run/dnsmasq/$NAME.pid --exec $DAEMON --test > /dev/null | |
| case "$?" in | |
| 0) [ -e "/run/dnsmasq/$NAME.pid" ] && return 1 ; return 3 ;; | |
| 1) return 0 ;; | |
| *) return 4 ;; | |
| esac | |
| } | |
| case "$1" in | |
| start) | |
| test "$ENABLED" != "0" || exit 0 | |
| log_daemon_msg "Starting $DESC" "$NAME" | |
| start | |
| case "$?" in | |
| 0) | |
| log_end_msg 0 | |
| start_resolvconf | |
| exit 0 | |
| ;; | |
| 1) | |
| log_success_msg "(already running)" | |
| exit 0 | |
| ;; | |
| *) | |
| log_end_msg 1 | |
| exit 1 | |
| ;; | |
| esac | |
| ;; | |
| stop) | |
| stop_resolvconf | |
| if [ "$ENABLED" != "0" ]; then | |
| log_daemon_msg "Stopping $DESC" "$NAME" | |
| fi | |
| stop | |
| RETVAL="$?" | |
| if [ "$ENABLED" = "0" ]; then | |
| case "$RETVAL" in | |
| 0) log_daemon_msg "Stopping $DESC" "$NAME"; log_end_msg 0 ;; | |
| esac | |
| exit 0 | |
| fi | |
| case "$RETVAL" in | |
| 0) log_end_msg 0 ; exit 0 ;; | |
| 1) log_warning_msg "(not running)" ; exit 0 ;; | |
| *) log_end_msg 1; exit 1 ;; | |
| esac | |
| ;; | |
| restart|force-reload) | |
| test "$ENABLED" != "0" || exit 1 | |
| $DAEMON --test ${CONFIG_DIR:+ -7 $CONFIG_DIR} ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} >/dev/null 2>&1 | |
| if [ $? -ne 0 ]; then | |
| NAME="configuration syntax check" | |
| RETVAL="2" | |
| else | |
| stop_resolvconf | |
| stop | |
| RETVAL="$?" | |
| fi | |
| log_daemon_msg "Restarting $DESC" "$NAME" | |
| case "$RETVAL" in | |
| 0|1) | |
| sleep 2 | |
| start | |
| case "$?" in | |
| 0) | |
| log_end_msg 0 | |
| start_resolvconf | |
| exit 0 | |
| ;; | |
| *) | |
| log_end_msg 1 | |
| exit 1 | |
| ;; | |
| esac | |
| ;; | |
| *) | |
| log_end_msg 1 | |
| exit 1 | |
| ;; | |
| esac | |
| ;; | |
| status) | |
| log_daemon_msg "Checking $DESC" "$NAME" | |
| status | |
| case "$?" in | |
| 0) log_success_msg "(running)" ; exit 0 ;; | |
| 1) log_success_msg "(dead, pid file exists)" ; exit 1 ;; | |
| 3) log_success_msg "(not running)" ; exit 3 ;; | |
| *) log_success_msg "(unknown)" ; exit 4 ;; | |
| esac | |
| ;; | |
| dump-stats) | |
| kill -s USR1 `cat /run/dnsmasq/$NAME.pid` | |
| ;; | |
| systemd-start-resolvconf) | |
| start_resolvconf | |
| ;; | |
| systemd-stop-resolvconf) | |
| stop_resolvconf | |
| ;; | |
| systemd-exec) | |
| # /run may be volatile, so we need to ensure that | |
| # /run/dnsmasq exists here as well as in postinst | |
| if [ ! -d /run/dnsmasq ]; then | |
| mkdir /run/dnsmasq || return 2 | |
| chown dnsmasq:nogroup /run/dnsmasq || return 2 | |
| fi | |
| exec $DAEMON --conf-file=$CONFIG_FILE -x /run/dnsmasq/$NAME.pid \ | |
| ${MAILHOSTNAME:+ -m $MAILHOSTNAME} \ | |
| ${MAILTARGET:+ -t $MAILTARGET} \ | |
| ${DNSMASQ_USER:+ -u $DNSMASQ_USER} \ | |
| ${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \ | |
| ${DHCP_LEASE:+ -l $DHCP_LEASE} \ | |
| ${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \ | |
| ${RESOLV_CONF:+ -r $RESOLV_CONF} \ | |
| ${CACHESIZE:+ -c $CACHESIZE} \ | |
| ${CONFIG_DIR:+ -7 $CONFIG_DIR} \ | |
| ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} | |
| ;; | |
| *) | |
| echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|dump-stats|status}" >&2 | |
| exit 3 | |
| ;; | |
| esac | |
| exit 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /etc/dnsmasq.s/dnsmasq-eth0.conf | |
| interface=eth0 | |
| except-interface=lo | |
| # listen-address=192.168.200.106 | |
| #bind-interfaces | |
| bind-dynamic | |
| # Custom DNS record | |
| address=/raspberry.pi/192.168.200.106 | |
| # Don't read host file record | |
| no-hosts | |
| # Dont'read resolv.conf | |
| no-resolv | |
| # Use Google public DNS | |
| server=8.8.8.8 | |
| server=8.8.4.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /etc/dnsmasq.s/dnsmasq-wlan0.conf | |
| interface=wlan0 | |
| except-interface=lo | |
| # listen-address=192.168.4.1 | |
| #bind-interfaces | |
| bind-dynamic | |
| # Access Point configuration | |
| # DHCP settings | |
| dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,1h | |
| # DNS nameserver ip # 5 for IPs | 6 for Domains | |
| dhcp-option=5,192.168.4.1 | |
| # Custom DNS record | |
| address=/raspberry.pi/192.168.4.1 | |
| # Don't read host file record | |
| no-hosts | |
| # Dont'read resolv.conf | |
| no-resolv | |
| # Use Google public DNS | |
| server=8.8.8.8 | |
| server=8.8.4.4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /lib/systemd/system/dnsmasq.service | |
| [Unit] | |
| Description=dnsmasq - A lightweight DHCP and caching DNS server | |
| Requires=network.target | |
| Wants=nss-lookup.target | |
| Before=nss-lookup.target | |
| After=network.target | |
| [Service] | |
| Type=forking | |
| PIDFile=/run/dnsmasq/dnsmasq.pid | |
| # Test the config file and refuse starting if it is not valid. | |
| ExecStartPre=/usr/sbin/dnsmasq --test | |
| # We run dnsmasq via the /etc/init.d/dnsmasq script which acts as a | |
| # wrapper picking up extra configuration files and then execs dnsmasq | |
| # itself, when called with the "systemd-exec" function. | |
| ExecStart=/etc/init.d/dnsmasq systemd-exec | |
| # The systemd-*-resolvconf functions configure (and deconfigure) | |
| # resolvconf to work with the dnsmasq DNS server. They're called liek | |
| # this to get correct error handling (ie don't start-resolvconf if the | |
| # dnsmasq daemon fails to start. | |
| ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf | |
| ExecStop=/etc/init.d/dnsmasq systemd-stop-resolvconf | |
| ExecReload=/bin/kill -HUP $MAINPID | |
| [Install] | |
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| ### BEGIN INIT INFO | |
| # Provides: dnsmasq | |
| # Required-Start: $network $remote_fs $syslog | |
| # Required-Stop: $network $remote_fs $syslog | |
| # Default-Start: 2 3 4 5 | |
| # Default-Stop: 0 1 6 | |
| # Description: DHCP and DNS server | |
| ### END INIT INFO | |
| # Don't exit on error status | |
| set +e | |
| PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
| DAEMON=/usr/sbin/dnsmasq | |
| NAME=dnsmasq2 | |
| DESC="DNS forwarder and DHCP server" | |
| CONFIG_FILE="/etc/dnsmasq.s/dnsmasq-eth0.conf" | |
| # Most configuration options in /etc/default/dnsmasq are deprecated | |
| # but still honoured. | |
| ENABLED=1 | |
| # if [ -r /etc/default/$NAME ]; then | |
| # . /etc/default/$NAME | |
| # fi | |
| # Get the system locale, so that messages are in the correct language, and the | |
| # charset for IDN is correct | |
| if [ -r /etc/default/locale ]; then | |
| . /etc/default/locale | |
| export LANG | |
| fi | |
| # The following test ensures the dnsmasq service is not started, when the | |
| # package 'dnsmasq' is removed but not purged, even if the dnsmasq-base | |
| # package is still in place. | |
| test -e /usr/share/dnsmasq/installed-marker || exit 0 | |
| test -x $DAEMON || exit 0 | |
| # Provide skeleton LSB log functions for backports which don't have LSB functions. | |
| if [ -f /lib/lsb/init-functions ]; then | |
| . /lib/lsb/init-functions | |
| else | |
| log_warning_msg () { | |
| echo "${@}." | |
| } | |
| log_success_msg () { | |
| echo "${@}." | |
| } | |
| log_daemon_msg () { | |
| echo -n "${1}: $2" | |
| } | |
| log_end_msg () { | |
| if [ $1 -eq 0 ]; then | |
| echo "." | |
| elif [ $1 -eq 255 ]; then | |
| /bin/echo -e " (warning)." | |
| else | |
| /bin/echo -e " failed!" | |
| fi | |
| } | |
| fi | |
| # RESOLV_CONF: | |
| # If the resolvconf package is installed then use the resolv conf file | |
| # that it provides as the default. Otherwise use /etc/resolv.conf as | |
| # the default. | |
| # | |
| # If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit | |
| # filename is set there then this inhibits the use of the resolvconf-provided | |
| # information. | |
| # | |
| # Note that if the resolvconf package is installed it is not possible to | |
| # override it just by configuration in /etc/dnsmasq.conf, it is necessary | |
| # to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq. | |
| if [ ! "$RESOLV_CONF" ] && | |
| [ "$IGNORE_RESOLVCONF" != "yes" ] && | |
| [ -x /sbin/resolvconf ] | |
| then | |
| RESOLV_CONF=/run/dnsmasq2/resolv.conf | |
| fi | |
| for INTERFACE in $DNSMASQ_INTERFACE; do | |
| DNSMASQ_INTERFACES="$DNSMASQ_INTERFACES -i $INTERFACE" | |
| done | |
| for INTERFACE in $DNSMASQ_EXCEPT; do | |
| DNSMASQ_INTERFACES="$DNSMASQ_INTERFACES -I $INTERFACE" | |
| done | |
| if [ ! "$DNSMASQ_USER" ]; then | |
| DNSMASQ_USER="dnsmasq" | |
| fi | |
| # This tells dnsmasq to ignore DNS requests that don't come from a local network. | |
| # It's automatically ignored if --interface --except-interface, --listen-address | |
| # or --auth-server exist in the configuration, so for most installations, it will | |
| # have no effect, but for otherwise-unconfigured installations, it stops dnsmasq | |
| # from being vulnerable to DNS-reflection attacks. | |
| DNSMASQ_OPTS="$DNSMASQ_OPTS --local-service" | |
| # If the dns-root-data package is installed, then the trust anchors will be | |
| # available in $ROOT_DS, in BIND zone-file format. Reformat as dnsmasq | |
| # --trust-anchor options. | |
| ROOT_DS="/usr/share/dns/root.ds" | |
| if [ -f $ROOT_DS ]; then | |
| DNSMASQ_OPTS="$DNSMASQ_OPTS `sed -e s/". IN DS "/--trust-anchor=.,/ -e s/" "/,/g $ROOT_DS | tr '\n' ' '`" | |
| fi | |
| start() | |
| { | |
| # Return | |
| # 0 if daemon has been started | |
| # 1 if daemon was already running | |
| # 2 if daemon could not be started | |
| # /run may be volatile, so we need to ensure that | |
| # /run/dnsmasq exists here as well as in postinst | |
| if [ ! -d /run/dnsmasq2 ]; then | |
| mkdir /run/dnsmasq2 || return 2 | |
| chown dnsmasq:nogroup /run/dnsmasq2 || return 2 | |
| fi | |
| start-stop-daemon --start --quiet --pidfile /run/dnsmasq2/$NAME.pid --exec $DAEMON --test > /dev/null || return 1 | |
| start-stop-daemon --start --quiet --pidfile /run/dnsmasq2/$NAME.pid --exec $DAEMON --conf-file=$CONFIG_FILE -- \ | |
| -x /run/dnsmasq2/$NAME.pid \ | |
| ${MAILHOSTNAME:+ -m $MAILHOSTNAME} \ | |
| ${MAILTARGET:+ -t $MAILTARGET} \ | |
| ${DNSMASQ_USER:+ -u $DNSMASQ_USER} \ | |
| ${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \ | |
| ${DHCP_LEASE:+ -l $DHCP_LEASE} \ | |
| ${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \ | |
| ${RESOLV_CONF:+ -r $RESOLV_CONF} \ | |
| ${CACHESIZE:+ -c $CACHESIZE} \ | |
| ${CONFIG_DIR:+ -7 $CONFIG_DIR} \ | |
| ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} \ | |
| || return 2 | |
| } | |
| start_resolvconf() | |
| { | |
| # If interface "lo" is explicitly disabled in /etc/default/dnsmasq | |
| # Then dnsmasq won't be providing local DNS, so don't add it to | |
| # the resolvconf server set. | |
| for interface in $DNSMASQ_EXCEPT | |
| do | |
| [ $interface = lo ] && return | |
| done | |
| # Also skip this if DNS functionality is disabled in /etc/dnsmasq.conf | |
| if grep -qs '^port=0' /etc/dnsmasq.conf; then | |
| return | |
| fi | |
| if [ -x /sbin/resolvconf ] ; then | |
| echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME | |
| fi | |
| return 0 | |
| } | |
| stop() | |
| { | |
| # Return | |
| # 0 if daemon has been stopped | |
| # 1 if daemon was already stopped | |
| # 2 if daemon could not be stopped | |
| # other if a failure occurred | |
| start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile /run/dnsmasq2/$NAME.pid --name $NAME | |
| } | |
| stop_resolvconf() | |
| { | |
| if [ -x /sbin/resolvconf ] ; then | |
| /sbin/resolvconf -d lo.$NAME | |
| fi | |
| return 0 | |
| } | |
| status() | |
| { | |
| # Return | |
| # 0 if daemon is running | |
| # 1 if daemon is dead and pid file exists | |
| # 3 if daemon is not running | |
| # 4 if daemon status is unknown | |
| start-stop-daemon --start --quiet --pidfile /run/dnsmasq2/$NAME.pid --exec $DAEMON --test > /dev/null | |
| case "$?" in | |
| 0) [ -e "/run/dnsmasq2/$NAME.pid" ] && return 1 ; return 3 ;; | |
| 1) return 0 ;; | |
| *) return 4 ;; | |
| esac | |
| } | |
| case "$1" in | |
| start) | |
| test "$ENABLED" != "0" || exit 0 | |
| log_daemon_msg "Starting $DESC" "$NAME" | |
| start | |
| case "$?" in | |
| 0) | |
| log_end_msg 0 | |
| start_resolvconf | |
| exit 0 | |
| ;; | |
| 1) | |
| log_success_msg "(already running)" | |
| exit 0 | |
| ;; | |
| *) | |
| log_end_msg 1 | |
| exit 1 | |
| ;; | |
| esac | |
| ;; | |
| stop) | |
| stop_resolvconf | |
| if [ "$ENABLED" != "0" ]; then | |
| log_daemon_msg "Stopping $DESC" "$NAME" | |
| fi | |
| stop | |
| RETVAL="$?" | |
| if [ "$ENABLED" = "0" ]; then | |
| case "$RETVAL" in | |
| 0) log_daemon_msg "Stopping $DESC" "$NAME"; log_end_msg 0 ;; | |
| esac | |
| exit 0 | |
| fi | |
| case "$RETVAL" in | |
| 0) log_end_msg 0 ; exit 0 ;; | |
| 1) log_warning_msg "(not running)" ; exit 0 ;; | |
| *) log_end_msg 1; exit 1 ;; | |
| esac | |
| ;; | |
| restart|force-reload) | |
| test "$ENABLED" != "0" || exit 1 | |
| $DAEMON --test ${CONFIG_DIR:+ -7 $CONFIG_DIR} ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} >/dev/null 2>&1 | |
| if [ $? -ne 0 ]; then | |
| NAME="configuration syntax check" | |
| RETVAL="2" | |
| else | |
| stop_resolvconf | |
| stop | |
| RETVAL="$?" | |
| fi | |
| log_daemon_msg "Restarting $DESC" "$NAME" | |
| case "$RETVAL" in | |
| 0|1) | |
| sleep 2 | |
| start | |
| case "$?" in | |
| 0) | |
| log_end_msg 0 | |
| start_resolvconf | |
| exit 0 | |
| ;; | |
| *) | |
| log_end_msg 1 | |
| exit 1 | |
| ;; | |
| esac | |
| ;; | |
| *) | |
| log_end_msg 1 | |
| exit 1 | |
| ;; | |
| esac | |
| ;; | |
| status) | |
| log_daemon_msg "Checking $DESC" "$NAME" | |
| status | |
| case "$?" in | |
| 0) log_success_msg "(running)" ; exit 0 ;; | |
| 1) log_success_msg "(dead, pid file exists)" ; exit 1 ;; | |
| 3) log_success_msg "(not running)" ; exit 3 ;; | |
| *) log_success_msg "(unknown)" ; exit 4 ;; | |
| esac | |
| ;; | |
| dump-stats) | |
| kill -s USR1 `cat /run/dnsmasq2/$NAME.pid` | |
| ;; | |
| systemd-start-resolvconf) | |
| start_resolvconf | |
| ;; | |
| systemd-stop-resolvconf) | |
| stop_resolvconf | |
| ;; | |
| systemd-exec) | |
| # /run may be volatile, so we need to ensure that | |
| # /run/dnsmasq exists here as well as in postinst | |
| if [ ! -d /run/dnsmasq2 ]; then | |
| mkdir /run/dnsmasq2 || return 2 | |
| chown dnsmasq:nogroup /run/dnsmasq2 || return 2 | |
| fi | |
| exec $DAEMON --conf-file=$CONFIG_FILE -x /run/dnsmasq2/$NAME.pid \ | |
| ${MAILHOSTNAME:+ -m $MAILHOSTNAME} \ | |
| ${MAILTARGET:+ -t $MAILTARGET} \ | |
| ${DNSMASQ_USER:+ -u $DNSMASQ_USER} \ | |
| ${DNSMASQ_INTERFACES:+ $DNSMASQ_INTERFACES} \ | |
| ${DHCP_LEASE:+ -l $DHCP_LEASE} \ | |
| ${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \ | |
| ${RESOLV_CONF:+ -r $RESOLV_CONF} \ | |
| ${CACHESIZE:+ -c $CACHESIZE} \ | |
| ${CONFIG_DIR:+ -7 $CONFIG_DIR} \ | |
| ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} | |
| ;; | |
| *) | |
| echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload|dump-stats|status}" >&2 | |
| exit 3 | |
| ;; | |
| esac | |
| exit 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /lib/systemd/system/dnsmasq2.service | |
| [Unit] | |
| Description=dnsmasq2 - A lightweight DHCP and caching DNS server | |
| Requires=network.target | |
| Wants=nss-lookup.target | |
| Before=nss-lookup.target | |
| After=dnsmasq.service | |
| [Service] | |
| Type=forking | |
| PIDFile=/run/dnsmasq2/dnsmasq2.pid | |
| # Test the config file and refuse starting if it is not valid. | |
| ExecStartPre=/usr/sbin/dnsmasq --test | |
| # We run dnsmasq via the /etc/init.d/dnsmasq script which acts as a | |
| # wrapper picking up extra configuration files and then execs dnsmasq | |
| # itself, when called with the "systemd-exec" function. | |
| ExecStart=/etc/init.d/dnsmasq2 systemd-exec | |
| # The systemd-*-resolvconf functions configure (and deconfigure) | |
| # resolvconf to work with the dnsmasq DNS server. They're called liek | |
| # this to get correct error handling (ie don't start-resolvconf if the | |
| # dnsmasq daemon fails to start. | |
| ExecStartPost=/etc/init.d/dnsmasq2 systemd-start-resolvconf | |
| ExecStop=/etc/init.d/dnsmasq2 systemd-stop-resolvconf | |
| ExecReload=/bin/kill -HUP $MAINPID | |
| [Install] | |
| WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /etc/nginx/sites-available/ownCloud | |
| upstream php-handler { | |
| #server 127.0.0.1:9000; | |
| server unix:/var/run/php/php7.2-fpm.sock; | |
| # Depending on your used PHP version | |
| #server unix:/var/run/php5-fpm.sock; | |
| #server unix:/var/run/php7-fpm.sock; | |
| } | |
| # Own server configuration | |
| # | |
| server { | |
| listen 80; | |
| listen [::]:80; | |
| # SSL configuration | |
| # | |
| # listen 443 ssl default_server; | |
| # listen [::]:443 ssl default_server; | |
| # | |
| # Note: You should disable gzip for SSL traffic. | |
| # See: https://bugs.debian.org/773332 | |
| # | |
| # Read up on ssl_ciphers to ensure a secure configuration. | |
| # See: https://bugs.debian.org/765782 | |
| # | |
| # Self signed certs generated by the ssl-cert package | |
| # Don't use them in a production server! | |
| # | |
| # include snippets/snakeoil.conf; | |
| root /var/www/owncloud; | |
| # Add index.php to the list if you are using PHP | |
| index index.php index.html index.htm index.nginx-debian.html; | |
| server_name raspberry.pi; | |
| # set max upload size | |
| client_max_body_size 512M; | |
| fastcgi_buffers 8 4K; # Please see note 1 | |
| fastcgi_ignore_headers X-Accel-Buffering; # Please see note 2 | |
| # Disable gzip to avoid the removal of the ETag header | |
| # Enabling gzip would also make your server vulnerable to BREACH | |
| # if no additional measures are done. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=773332 | |
| gzip off; | |
| #location / { | |
| # try_files $uri $uri/ =404; | |
| #} | |
| # pass PHP scripts to FastCGI server | |
| # | |
| location ~ \.php$ { | |
| include snippets/fastcgi-php.conf; | |
| fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; | |
| } | |
| # deny access to .htaccess files, if Apache's document root | |
| # concurs with nginx's one | |
| # | |
| location ~ /\.ht { | |
| deny all; | |
| } | |
| location / { | |
| rewrite ^ /index.php$uri; | |
| } | |
| location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { | |
| return 404; | |
| } | |
| location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { | |
| return 404; | |
| } | |
| location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) { | |
| fastcgi_split_path_info ^(.+\.php)(/.*)$; | |
| include fastcgi_params; | |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
| fastcgi_param SCRIPT_NAME $fastcgi_script_name; # necessary for owncloud to detect the contextroot https://github.com/owncloud/core/blob/v10.0.0/lib/private/AppFramework/Http/Request.php#L603 | |
| fastcgi_param PATH_INFO $fastcgi_path_info; | |
| fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice | |
| fastcgi_param front_controller_active true; | |
| fastcgi_read_timeout 180; # increase default timeout e.g. for long running carddav/ caldav syncs with 1000+ entries | |
| fastcgi_pass php-handler; | |
| fastcgi_intercept_errors on; | |
| fastcgi_request_buffering off; #Available since NGINX 1.7.11 | |
| } | |
| location ~ ^/(?:updater|ocs-provider)(?:$|/) { | |
| try_files $uri $uri/ =404; | |
| index index.php; | |
| } | |
| # Adding the cache control header for js and css files | |
| # Make sure it is BELOW the PHP block | |
| location ~ \.(?:css|js)$ { | |
| try_files $uri /index.php$uri$is_args$args; | |
| add_header Cache-Control "max-age=15778463"; | |
| # Add headers to serve security related headers (It is intended to have those duplicated to the ones above) | |
| # Before enabling Strict-Transport-Security headers please read into this topic first. | |
| #add_header Strict-Transport-Security "max-age=15552000; includeSubDomains"; | |
| add_header X-Content-Type-Options nosniff; | |
| add_header X-Frame-Options "SAMEORIGIN"; | |
| add_header X-XSS-Protection "1; mode=block"; | |
| add_header X-Robots-Tag none; | |
| add_header X-Download-Options noopen; | |
| add_header X-Permitted-Cross-Domain-Policies none; | |
| # Optional: Don't log access to assets | |
| access_log off; | |
| } | |
| location ~ \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg|map)$ { | |
| add_header Cache-Control "public, max-age=7200"; | |
| try_files $uri /index.php$uri$is_args$args; | |
| # Optional: Don't log access to other assets | |
| access_log off; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Manually run commands, not bash script | |
| sudo -i | |
| # Add PHP7.2 repository and release key | |
| wget -q https://packages.sury.org/php/apt.gpg -O- | apt-key add - | |
| echo "deb https://packages.sury.org/php/ stretch main" > /etc/apt/sources.list.d/php.list | |
| # Add ownCloud repository and release key | |
| wget -q https://download.owncloud.org/download/repositories/stable/Debian_9.0/Release.key -O- | apt-key add - | |
| echo "deb http://download.owncloud.org/download/repositories/stable/Debian_9.0/ /" > /etc/apt/sources.list.d/owncloud.list | |
| # Update RaspberryPi packages and system | |
| apt update | |
| apt -y upgrade | |
| # Install required packages for ownCloud | |
| apt install -y nginx php7.2-fpm php7.2-common php7.2-cli php7.2-sqlite3 php7.2-zip php7.2-gmp php7.2-curl php7.2-intl php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml | |
| # Install ownCloud packages | |
| apt install -y owncloud-files | |
| # Change file owner and permission to NGINX user | |
| chown -R www-data:www-data /var/www/owncloud/ | |
| chmod -R 750 /var/www/owncloud/ | |
| # Install Wifi AccessPoint packages | |
| apt install -y dnsmasq hostapd | |
| systemctl stop dnsmasq | |
| systemctl stop hostapd | |
| # Re-Create partitios for external storage (optional) | |
| umount /dev/sda1 | |
| fdisk /dev/sda1 | |
| n | |
| default for all | |
| w | |
| # Format external storage as ext4 | |
| ls -l /dev/disk/by-uuid | |
| # .. Insert the USB | |
| ls -l /dev/disk/by-uuid | |
| umount /dev/sda1 | |
| mkfs.ext4 /dev/sda1 | |
| # Mount the external storage into specific path | |
| mkdir /media/ownCloudDrive | |
| mount /dev/sda1 /media/ownCloudDrive | |
| # Change file owner and permission to NGINX user | |
| chown -R www-data:www-data /media/ownCloudDrive | |
| chmod -R 750 /media/ownCloudDrive | |
| # Upload files | |
| # .. | |
| mv /home/pi/RasbperryPi-Conf.tar.gz / | |
| cd / | |
| tar -xzf RasbperryPi-Conf.tar.gz | |
| id -g www-data | |
| id -u www-data | |
| # List disks and enable auto-mount | |
| ls -l /dev/disk/by-uuid | |
| vi /etc/fstab | |
| UUID=a6c2a79f-a57b-4865-bc91-d9696e6beaca /media/ownCloudDrive auto nofail,uid=33,gid=33,umask=0027,dmask=0027,noatime 0 0 | |
| ## Configure files | |
| vi /etc/default/hostapd | |
| ## Add DAEMON_CONF="/etc/hostapd/hostapd.conf" | |
| vi /etc/hostapd/hostapd.conf | |
| ## Add | |
| interface=wlan0 | |
| driver=nl80211 | |
| ssid=PersonalCloud | |
| hw_mode=g | |
| channel=7 | |
| wmm_enabled=0 | |
| macaddr_acl=0 | |
| auth_algs=1 | |
| ignore_broadcast_ssid=0 | |
| wpa=2 | |
| wpa_passphrase=12345678 | |
| wpa_key_mgmt=WPA-PSK | |
| wpa_pairwise=TKIP | |
| rsn_pairwise=CCMP | |
| vi /etc/dhcpcd.conf | |
| ## Add | |
| interface wlan0 | |
| static ip_address=192.168.4.1/24 | |
| vi /etc/sysctl.conf | |
| # Change net.ipv4.ip_forward to = 1 | |
| mkdir /run/dnsmasq2 | |
| # | |
| # Route Wi-Fi traffic thorugh ethernet (eth0) | |
| iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | |
| iptables-save > /etc/iptables.ipv4.nat | |
| echo 1 >> /proc/sys/net/ipv4/ip_forward | |
| vi /etc/rc.local | |
| #Add | |
| iptables-restore < /etc/iptables.ipv4.nat | |
| # Enable ownCloud configuration | |
| ln -s /etc/nginx/sites-available/ownCloud /etc/nginx/sites-enabled/ | |
| rm /etc/nginx/sites-enabled/default | |
| # Assing default ip | |
| ifconfig wlan0 192.168.4.1 | |
| # (Re-)Start and enable services | |
| /etc/init.d/networking restart | |
| systemctl restart nginx.service | |
| service dhcpcd restart | |
| service ssh restart | |
| systemctl start hostapd | |
| systemctl start dnsmasq | |
| systemctl start dnsmasq2 | |
| # Enable auto-start services | |
| update-rc.d hostapd enable | |
| systemctl enable nginx.service | |
| systemctl enable dnsmasq.service | |
| systemctl enable dnsmasq2.service | |
| systemctl enable php7.2-fpm | |
| reboot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://download.owncloud.org/download/repositories/stable/owncloud/index.html | |
| https://www.avoiderrors.com/raspberry-pi-3-into-a-personal-cloud-storage-2017/ | |
| https://www.avoiderrors.com/owncloud-10-raspberry-pi-3-raspbian-stretch/ | |
| https://github.com/SurferTim/documentation/blob/6bc583965254fa292a470990c40b145f553f6b34/configuration/wireless/access-point.md | |
| https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md | |
| http://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router/ | |
| https://www.rosehosting.com/blog/how-to-install-php-7-2-on-debian-9/ | |
| https://doc.owncloud.org/server/10.0/admin_manual/installation/nginx_configuration.html | |
| https://stackoverflow.com/questions/9326438/dnsmasq-serve-different-ip-addresses-based-on-interface-used | |
| https://www.raspberrypi.org/forums/viewtopic.php?t=198319 | |
| http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2005q2/000302.html | |
| https://serverfault.com/questions/163542/how-do-you-get-dnsmasq-to-specify-alternate-dns-servers | |
| https://www.raspberrypi.org/forums/viewtopic.php?t=194439 | |
| https://stackoverflow.com/questions/22313142/wildcard-subdomains-with-dnsmasq | |
| https://serverfault.com/questions/136332/setting-up-dnsmasq-for-a-local-network | |
| https://www.youtube.com/watch?v=Nfs0UDK4I2I | |
| https://www.youtube.com/watch?v=Nfs0UDK4I2I | |
| https://www.raspberrypi.org/forums/viewtopic.php?t=198319 | |
| https://www.raspberrypi.org/forums/viewtopic.php?t=151435 | |
| https://www.instructables.com/id/Raspberry-Pi-Web-Server-Wireless-Access-Point-WAP/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment