diff options
author | nachoparker <nacho@ownyourbits.com> | 2017-06-07 13:18:35 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2017-06-08 17:31:10 +0300 |
commit | 1357ed7240f47abbdce45c4fbd6673b2669afa3a (patch) | |
tree | d282a70e7dad7e088ea9e02979bb3224c560f705 | |
parent | 332523b9f91e846c00f6540cfcfdc4d774d9e6a5 (diff) |
refactor QEMU ncp construction
-rw-r--r-- | README.md | 17 | ||||
-rwxr-xr-x | batch.sh | 11 | ||||
-rw-r--r-- | docker/nextcloud.dockerfile | 2 | ||||
-rwxr-xr-x | docker/run-nc.sh | 2 | ||||
-rwxr-xr-x | etc/library.sh | 1 | ||||
-rw-r--r-- | etc/nc-init.sh (renamed from nc-init.sh) | 2 | ||||
-rwxr-xr-x | etc/nextcloudpi-config.d/nc-nextcloud.sh | 1 | ||||
-rwxr-xr-x | installer.sh | 2 | ||||
-rw-r--r-- | lamp.sh | 5 | ||||
-rw-r--r-- | nextcloudpi.sh | 3 | ||||
-rw-r--r--[-rwxr-xr-x] | prepare-img.sh (renamed from install-nextcloud.sh) | 13 | ||||
-rw-r--r-- | prepare.sh | 73 | ||||
-rw-r--r-- | prepare_img.sh | 35 |
13 files changed, 110 insertions, 57 deletions
@@ -6,6 +6,8 @@ This is the build code for [NextCloudPi](https://ownyourbits.com/2017/02/13/next NextCloudPi is a ready to use image for Raspberry Pi. +This code also generates the [NextCloudPi ARM docker image](https://hub.docker.com/r/ownyourbits/nextcloudpi/). + ## Features * Raspbian 8 Jessie @@ -58,10 +60,23 @@ Extras can be activated and configured using sudo nextcloudpi-config ``` +The docker image can be generated in an ARM environment with docker + +``` +git clone https://github.com/nextcloud/nextcloudpi.git +make -C nextcloudpi +``` + ![NCP-config](/resources/ncp-config.jpg) -## Download image +## Downloads Get the image, find details and more instructions at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ + +Pull the docker image + +https://ownyourbits.com/2017/06/08/nextcloudpi-docker-for-raspberry-pi/ + +https://hub.docker.com/r/ownyourbits/nextcloudpi/ @@ -19,13 +19,14 @@ IMGBASE="NextCloudPi_$( date "+%m-%d-%y" )_base.img" export NO_CONFIG=1 # skip interactive configuration -NO_HALT_STEP=1 ./install-nextcloud.sh $IP $IMGBASE - ./installer.sh $NC_INSTALL $IP $( ls -1t *.img | head -1 ) - ./installer.sh $NC_CONFIG $IP $( ls -1t *.img | head -1 ) - ./installer.sh nextcloudpi.sh $IP $( ls -1t *.img | head -1 ) +NO_HALT_STEP=1 ./prepare-img.sh $IP $IMGBASE || exit 1 + ./installer.sh lamp.sh $IP $( ls -1t *.img | head -1 ) || exit 1 + ./installer.sh $NC_INSTALL $IP $( ls -1t *.img | head -1 ) || exit 1 + ./installer.sh $NC_CONFIG $IP $( ls -1t *.img | head -1 ) || exit 1 + ./installer.sh nextcloudpi.sh $IP $( ls -1t *.img | head -1 ) || exit 1 IMGFILE=$( ls -1t *.img | head -1 ) -IMGOUT=$( basename "$IMGFILE" _base_nc-nextcloud_nextcloudpi.img ).img +IMGOUT=$( basename "$IMGFILE" _base_lamp_nc-nextcloud_nc-init_nextcloudpi.img ).img pack_image "$IMGFILE" "$IMGOUT" md5sum $( ls -1t *.img | head -1 ) diff --git a/docker/nextcloud.dockerfile b/docker/nextcloud.dockerfile index 49d7213e..7ab5672d 100644 --- a/docker/nextcloud.dockerfile +++ b/docker/nextcloud.dockerfile @@ -7,7 +7,7 @@ MAINTAINER Ignacio Núñez Hernanz <nacho@ownyourbits.com> SHELL ["/bin/bash", "-c"] -COPY etc/library.sh nc-init.sh etc/nextcloudpi-config.d/nc-nextcloud.sh /usr/local/etc/ +COPY etc/library.sh etc/nc-init.sh etc/nextcloudpi-config.d/nc-nextcloud.sh /usr/local/etc/ RUN apt-get update; apt-get install --no-install-recommends -y wget ca-certificates; \ source /usr/local/etc/library.sh; set +x; activate_script /usr/local/etc/nc-nextcloud.sh; \ diff --git a/docker/run-nc.sh b/docker/run-nc.sh index 013f5d86..f07e72b3 100755 --- a/docker/run-nc.sh +++ b/docker/run-nc.sh @@ -27,7 +27,7 @@ done test -d /data/app || { - echo "First run" + echo "[First run]" # INIT DATABASE AND NEXTCLOUD CONFIG source /usr/local/etc/library.sh diff --git a/etc/library.sh b/etc/library.sh index d623b1db..5cfd1cba 100755 --- a/etc/library.sh +++ b/etc/library.sh @@ -31,6 +31,7 @@ function launch_install_qemu() IMGOUT="$BASE-stage$NUM" cp -v $IMG $IMGOUT || return 1 # take a copy of the input image for processing ( append "-stage1" ) + pgrep qemu-system-arm &>/dev/null && { echo -e "QEMU instance already running. Abort..."; return 1; } launch_qemu $IMGOUT & sleep 10 wait_SSH $IP diff --git a/nc-init.sh b/etc/nc-init.sh index 67780b4d..28a71336 100644 --- a/nc-init.sh +++ b/etc/nc-init.sh @@ -51,7 +51,7 @@ EOF "$DBPASSWD_" --admin-user "$ADMINUSER_" --admin-pass "$DBPASSWD_" sudo -u www-data php occ background:cron - sed -i '$s|^.*$| '\''memcache.local'\'' => '\''\\\\OC\\\\Memcache\\\\APCu'\'',\n);|' /var/www/nextcloud/config/config.php + sed -i '$i\ \ '\''memcache.local'\'' => '\''\\\\OC\\\\Memcache\\\\APCu'\'',' /var/www/nextcloud/config/config.php } configure(){ :; } diff --git a/etc/nextcloudpi-config.d/nc-nextcloud.sh b/etc/nextcloudpi-config.d/nc-nextcloud.sh index 5c747b83..20d84b15 100755 --- a/etc/nextcloudpi-config.d/nc-nextcloud.sh +++ b/etc/nextcloudpi-config.d/nc-nextcloud.sh @@ -116,7 +116,6 @@ cleanup() rm -f /home/pi/.bash_history systemctl disable ssh - nohup halt &>/dev/null & } # License # diff --git a/installer.sh b/installer.sh index ac538aff..06a32cde 100755 --- a/installer.sh +++ b/installer.sh @@ -41,7 +41,7 @@ source etc/library.sh # initializes $IMGNAME config $INSTALL_SCRIPT || exit 1 if [[ "$IMGFILE" != "" ]]; then - launch_install_qemu "$IMGFILE" $IP || exit 1 # initializes $IMGOUT + launch_install_qemu "$IMGFILE" $IP || { sudo killall qemu-system-arm; exit 1; } # initializes $IMGOUT pack_image "$IMGOUT" "$IMGNAME" else launch_installation_online $IP @@ -8,7 +8,7 @@ # # Usage: # -# ./installer.sh nextcloud_lamp.sh <IP> (<img>) +# ./installer.sh lamp.sh <IP> (<img>) # # See installer.sh instructions for details # @@ -148,13 +148,12 @@ configure() { :; } cleanup() { - apt-get autoremove + apt-get autoremove -y apt-get clean rm /var/lib/apt/lists/* -r rm -f /home/pi/.bash_history systemctl disable ssh - nohup halt &>/dev/null & } # License diff --git a/nextcloudpi.sh b/nextcloudpi.sh index de0a3893..d56b3133 100644 --- a/nextcloudpi.sh +++ b/nextcloudpi.sh @@ -129,13 +129,12 @@ configure() { :; } cleanup() { - apt-get autoremove + apt-get autoremove -y apt-get clean rm /var/lib/apt/lists/* -r rm -f /home/pi/.bash_history systemctl disable ssh - nohup halt &>/dev/null & } # License diff --git a/install-nextcloud.sh b/prepare-img.sh index 00083529..c61f869e 100755..100644 --- a/install-nextcloud.sh +++ b/prepare-img.sh @@ -7,10 +7,11 @@ # GPL licensed (see end of file) * Use at your own risk! # # Usage: -# ./install-nextcloud.sh <IP> # Use the IP of your running QEMU Raspbian image +# ./prepare-img.sh <IP> # Use the IP of your running QEMU Raspbian image # # Notes: -# Set DOWNLOAD=0 if you have already downloaded an image. Rename it to nextcloudpi.img +# Set DOWNLOAD=0 if you have already downloaded an image. +# Set EXTRACT=0 if you have already extracted the image. # # More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/ # @@ -20,18 +21,18 @@ 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=lamp.sh +INSTALL_SCRIPT=prepare.sh source etc/library.sh # initializes $IMGNAME -[[ "$DOWNLOAD" == "1" ]] && { wget https://downloads.raspberrypi.org/$IMG -O $IMG.zip || exit; } +[[ "$DOWNLOAD" == "1" ]] && { wget https://downloads.raspberrypi.org/$IMG -O $IMG.zip || exit 1; } [[ "$DOWNLOAD" == "1" ]] || [[ "$EXTRACT" == "1" ]] && { unzip $IMG.zip && \ mv *-raspbian-*.img $IMGFILE && \ - qemu-img resize $IMGFILE +1G || exit + qemu-img resize $IMGFILE +1G || exit 1 } -config $INSTALL_SCRIPT || exit 1 +config $INSTALL_SCRIPT || exit 1 # Initializes $INSTALLATION_CODE launch_install_qemu "$IMGFILE" $IP || exit 1 # initializes $IMGOUT pack_image $IMGOUT $IMGFILE diff --git a/prepare.sh b/prepare.sh new file mode 100644 index 00000000..632fc813 --- /dev/null +++ b/prepare.sh @@ -0,0 +1,73 @@ +#!/bin/bish + +# Prepare a Raspbian image (download, resize and update) +# 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 prepare.sh <DHCP QEMU image IP> <image> +# + + +STATE_FILE=/home/pi/.installation_state +APTINSTALL="apt-get install -y --no-install-recommends" + +install() +{ + test -f $STATE_FILE && STATE=$( cat $STATE_FILE 2>/dev/null ) + if [ "$STATE" == "" ]; then + + # RESIZE IMAGE + ########################################## + + SECTOR=$( fdisk -l /dev/sda | grep Linux | awk '{ print $2 }' ) + echo -e "d\n2\nn\np\n2\n$SECTOR\n\nw\n" | fdisk /dev/sda || true + + echo 0 > $STATE_FILE + nohup reboot &>/dev/null & + elif [ "$STATE" == "0" ]; then + + # UPDATE EVERYTHING + ########################################## + resize2fs /dev/sda2 + + apt-get update + apt-get upgrade -y + apt-get dist-upgrade -y + $APTINSTALL rpi-update + echo -e "y\n" | PRUNE_MODULES=1 rpi-update + fi +} + +configure(){ :; } + +cleanup() +{ + [ "$STATE" != "0" ] && return + apt-get autoremove + apt-get clean + rm /var/lib/apt/lists/* -r + rm -f /home/pi/.bash_history + + systemctl disable ssh + rm $STATE_FILE + 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 diff --git a/prepare_img.sh b/prepare_img.sh deleted file mode 100644 index 468dfdd0..00000000 --- a/prepare_img.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bish - -# TODO - -STATE_FILE=/home/pi/.installation_state -APTINSTALL="apt-get install -y --no-install-recommends" - -install() -{ - test -f $STATE_FILE && STATE=$( cat $STATE_FILE 2>/dev/null ) - if [ "$STATE" == "" ]; then - - # RESIZE IMAGE - ########################################## - - SECTOR=$( fdisk -l /dev/sda | grep Linux | awk '{ print $2 }' ) - echo -e "d\n2\nn\np\n2\n$SECTOR\n\nw\n" | fdisk /dev/sda || true - - echo 0 > $STATE_FILE - nohup reboot &>/dev/null & - elif [ "$STATE" == "0" ]; then - - # UPDATE EVERYTHING - ########################################## - resize2fs /dev/sda2 - - apt-get update - apt-get upgrade -y - apt-get dist-upgrade -y - $APTINSTALL rpi-update - echo -e "y\n" | PRUNE_MODULES=1 rpi-update - - echo 1 > $STATE_FILE - nohup reboot &>/dev/null & - elif [ "$STATE" == "1" ]; then |