diff options
author | nachoparker <nacho@ownyourbits.com> | 2017-05-20 16:10:09 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2017-05-22 19:55:45 +0300 |
commit | 1df92f9eef9bea0935147c3e782c1fd63c1aa37f (patch) | |
tree | 5022290b84bb2f8a41dd68889374111c520d68b1 | |
parent | addd0a8bec9dde406fa80075226a374e7b0ba868 (diff) |
split building steps
-rwxr-xr-x | batch.sh | 7 | ||||
-rwxr-xr-x | install-nextcloud.sh | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | nextcloud_lamp.sh (renamed from nextcloud_base.sh) | 68 | ||||
-rw-r--r-- | nextcloudpi.sh | 150 |
4 files changed, 156 insertions, 71 deletions
@@ -15,11 +15,12 @@ IP=$1 # First argument is the QEMU Raspbian IP address IMGBASE="NextCloudPi_$( date "+%m-%d-%y" )_base.img" -NO_CONFIG=1 NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGBASE -NO_CONFIG=1 ./installer.sh nextcloud.sh $IP $( ls -1t *.img | head -1 ) +NO_CONFIG=1 NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGBASE +NO_CONFIG=1 ./installer.sh nextcloudpi.sh $IP $( ls -1t *.img | head -1 ) +NO_CONFIG=1 ./installer.sh nextcloud.sh $IP $( ls -1t *.img | head -1 ) IMGFILE=$( ls -1t *.img | head -1 ) -IMGOUT=$( basename "$IMGFILE" _base_nextcloud.img ).img +IMGOUT=$( basename "$IMGFILE" _base ).img pack_image "$IMGFILE" "$IMGOUT" md5sum $( ls -1t *.img | head -1 ) diff --git a/install-nextcloud.sh b/install-nextcloud.sh index 1ea466fe..4a4436f2 100755 --- a/install-nextcloud.sh +++ b/install-nextcloud.sh @@ -20,7 +20,7 @@ IMGFILE=$2 # Second argument is the name for the output image DOWNLOAD=1 # Download the latest image EXTRACT=1 # Extract the image from zip, so start from 0 IMG=raspbian_lite_latest -INSTALL_SCRIPT=nextcloud_base.sh +INSTALL_SCRIPT=nextcloud_lamp.sh source etc/library.sh # initializes $IMGNAME diff --git a/nextcloud_base.sh b/nextcloud_lamp.sh index 44a75f21..0469a943 100755..100644 --- a/nextcloud_base.sh +++ b/nextcloud_lamp.sh @@ -8,7 +8,7 @@ # # Usage: # -# ./installer.sh nextcloud_base.sh <IP> (<img>) +# ./installer.sh nextcloud_lamp.sh <IP> (<img>) # # See installer.sh instructions for details # @@ -164,72 +164,6 @@ CREATE USER '$DBADMIN_'@'localhost' IDENTIFIED BY '$DBPASSWD_'; GRANT ALL PRIVILEGES ON nextcloud.* TO $DBADMIN_@localhost; EXIT EOF - - # NEXTCLOUDPI-CONFIG - ########################################## - - $APTINSTALL dialog - mkdir -p $CONFDIR - sed -i '/Change User Password/i"0 NextCloudPi Configuration" "Configuration of NextCloudPi" \\\\' /usr/bin/raspi-config - sed -i '/1\\\\ \*) do_change_pass ;;/i0\\\\ *) nextcloudpi-config ;;' /usr/bin/raspi-config - - # NEXTCLOUDPI MOTD - ########################################## - mkdir /etc/update-motd.d - rm /etc/motd - ln -s /var/run/motd /etc/motd - - cat > /etc/update-motd.d/10logo <<EOF -#!/bin/sh -echo -cat /usr/local/etc/ncp-ascii.txt -EOF - - cat > /etc/update-motd.d/20updates <<'EOF' -#!/bin/bash -/usr/local/bin/ncp-check-updates -EOF - chmod a+x /etc/update-motd.d/* - - # NEXTCLOUDPI UPDATES - ########################################## - $APTINSTALL git - - cat > /etc/cron.daily/ncp-check-version <<EOF -#!/bin/sh -/usr/local/bin/ncp-check-version -EOF - chmod a+x /etc/cron.daily/ncp-check-version - - - cat > /usr/local/bin/ncp-update <<'EOF' -#!/bin/bash -{ - [ $(id -u) -ne 0 ] && { printf "Must be run as root. Try 'sudo $0'\n"; exit 1; } - ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } - echo -e "Downloading updates" - rm -rf /tmp/ncp-update-tmp - git clone -q --depth 1 https://github.com/nachoparker/nextcloud-raspbian-generator.git /tmp/ncp-update-tmp || exit 1 - cd /tmp/ncp-update-tmp - - echo -e "Performing updates" - ./update.sh - - VER=$( git describe --always --tags ) - echo $VER > /usr/local/etc/ncp-version - echo $VER > /var/run/.ncp-latest-version - - cd / - rm -rf /tmp/ncp-update-tmp - - echo -e "NextCloudPi updated to version \e[1m$VER\e[0m" - exit -} -EOF - chmod a+x /usr/local/bin/ncp-update - - # update to latest version from github as part of the build process - /usr/local/bin/ncp-update fi } diff --git a/nextcloudpi.sh b/nextcloudpi.sh new file mode 100644 index 00000000..1d364120 --- /dev/null +++ b/nextcloudpi.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +# NextcloudPi additions to Raspbian +# Tested with 2017-03-02-raspbian-jessie-lite.img +# +# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com> +# GPL licensed (see end of file) * Use at your own risk! +# +# Usage: +# +# ./installer.sh nextcloudpi.sh <IP> (<img>) +# +# See installer.sh instructions for details +# +# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ +# + +DBADMIN_=ncadmin +DBPASSWD_=ownyourbits +OPCACHEDIR=/var/www/nextcloud/data/.opcache +CONFDIR=/usr/local/etc/nextcloudpi-config.d/ +APTINSTALL="apt-get install -y --no-install-recommends" + + +install() +{ + + # NEXTCLOUDPI-CONFIG + ########################################## + apt-get update + $APTINSTALL dialog + mkdir -p $CONFDIR + sed -i '/Change User Password/i"0 NextCloudPi Configuration" "Configuration of NextCloudPi" \\\\' /usr/bin/raspi-config + sed -i '/1\\\\ \*) do_change_pass ;;/i0\\\\ *) nextcloudpi-config ;;' /usr/bin/raspi-config + + # NEXTCLOUDPI MOTD + ########################################## + mkdir /etc/update-motd.d + rm /etc/motd + ln -s /var/run/motd /etc/motd + +cat > /etc/update-motd.d/10logo <<EOF +#!/bin/sh +echo +cat /usr/local/etc/ncp-ascii.txt +EOF + + cat > /etc/update-motd.d/20updates <<'EOF' +#!/bin/bash +/usr/local/bin/ncp-check-updates +EOF + chmod a+x /etc/update-motd.d/* + + # NEXTCLOUDPI AUTO TRUSTED DOMAIN + ########################################## + mkdir -p /usr/lib/systemd/system + cat > /usr/lib/systemd/system/nextcloud-domain.service <<'EOF' +[Unit] +Description=Register Current IP as Nextcloud trusted domain +Requires=network.target +After=mysql.service + +[Service] +ExecStart=/bin/bash /usr/local/bin/nextcloud-domain.sh + +[Install] +WantedBy=multi-user.target +EOF + + cat > /usr/local/bin/nextcloud-domain.sh <<'EOF' +#!/bin/bash +IFACE=$( ip r | grep "default via" | awk '{ print $5 }' ) +IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) +cd /var/www/nextcloud +sudo -u www-data php occ config:system:set trusted_domains 1 --value=$IP +EOF + systemctl enable nextcloud-domain + + # NEXTCLOUDPI UPDATES + ########################################## + $APTINSTALL git + + cat > /etc/cron.daily/ncp-check-version <<EOF +#!/bin/sh +/usr/local/bin/ncp-check-version +EOF + chmod a+x /etc/cron.daily/ncp-check-version + + +cat > /usr/local/bin/ncp-update <<'EOF' +#!/bin/bash +{ +[ $(id -u) -ne 0 ] && { printf "Must be run as root. Try 'sudo $0'\n"; exit 1; } +ping -W 2 -w 1 -q github.com &>/dev/null || { echo "No internet connectivity"; exit 1; } +echo -e "Downloading updates" +rm -rf /tmp/ncp-update-tmp +git clone -q --depth 1 https://github.com/nachoparker/nextcloud-raspbian-generator.git /tmp/ncp-update-tmp || exit 1 +cd /tmp/ncp-update-tmp + +echo -e "Performing updates" +./update.sh + +VER=$( git describe --always --tags ) +echo $VER > /usr/local/etc/ncp-version +echo $VER > /var/run/.ncp-latest-version + +cd / +rm -rf /tmp/ncp-update-tmp + +echo -e "NextCloudPi updated to version \e[1m$VER\e[0m" +exit +} +EOF + chmod a+x /usr/local/bin/ncp-update + + # update to latest version from github as part of the build process + /usr/local/bin/ncp-update +} + +configure() { :; } + +cleanup() +{ + [ "$STATE" != "1" ] && return + apt-get autoremove + apt-get clean + rm /var/lib/apt/lists/* -r + rm -f /home/pi/.bash_history + + systemctl disable ssh + nohup halt &>/dev/null & +} + +# License +# +# This script is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This script is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this script; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place, Suite 330, +# Boston, MA 02111-1307 USA + |