Skip to content

Commit

Permalink
generic installer. include update-rpi
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Mar 4, 2017
1 parent aece353 commit 9bedea2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
5 changes: 3 additions & 2 deletions fail2ban.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#
# See the variables on the top of the script for tweaking

set -xe

sudo su

NCLOG=/var/www/nextcloud/data/nextcloud.log # location of Nextcloud logs
BANTIME=600 # time to ban an IP that exceeded attempts
FINDTIME=600 # cooldown time for incorrect passwords
MAXRETRY=6 # bad attempts before banning an IP

set -x
set -e
set -xe


# INSTALLATION
Expand Down
5 changes: 3 additions & 2 deletions install-nextcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ EXTRACT=1 # Extract the image from zip, so start from 0
IMG=raspbian_lite_latest
INSTALL_SCRIPT=nextcloud.sh
IMGFILE="NextCloudPi_$( date "+%m-%d-%y" ).img-stage0"
IMGOUT="NextCloudPi_$( date "+%m-%d-%y" ).img"

source library.sh
source library.sh # initializes $IMGOUT

[[ "$DOWNLOAD" == "1" ]] && { wget https://downloads.raspberrypi.org/$IMG -O $IMG.zip || exit; }
[[ "$DOWNLOAD" == "1" ]] || [[ "$EXTRACT" == "1" ]] && {
Expand All @@ -30,6 +29,8 @@ source library.sh
qemu-img resize $IMGFILE +1G || exit
}

IMGOUT="NextCloudPi_$( date "+%m-%d-%y" ).img"

launch_install_qemu $INSTALL_SCRIPT $IMGFILE $IP || exit
pack_image $IMGFILE $IMGOUT

Expand Down
22 changes: 12 additions & 10 deletions install-fail2ban.sh → installer.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/bin/bash

# fail2ban installation on QEMU emulated Raspbian image
# TODO
# Nextcloud installation on QEMU emulated Raspbian image
# Tested with 2017-01-11-raspbian-jessie.img (and lite)
#
# 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:
# ./install-fail2ban.sh <img> <IP> # Use the IP of your running QEMU Raspbian image


IMGFILE=$1 # First argument is the image file to start from
IP=$2 # Second argument is the QEMU Raspbian IP address
INSTALL_SCRIPT=fail2ban.sh
IMGOUT=$( basename $IMGFILE .img )_fail2ban.img

source library.sh
# ./install-nextcloud.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

INSTALL_SCRIPT=$1
IMGFILE=$2 # First argument is the image file to start from
IP=$3 # Second argument is the QEMU Raspbian IP address

source library.sh # initializes $IMGOUT

launch_install_qemu $INSTALL_SCRIPT $IMGFILE $IP || exit
pack_image $IMGFILE $IMGOUT
Expand Down
5 changes: 4 additions & 1 deletion library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# 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!


IMGOUT=$( basename $IMGFILE .img )_$( basename $INSTALL_SCRIPT .sh ).img

SSH=( ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o ServerAliveInterval=5 -o ConnectTimeout=1 -o LogLevel=quiet )

function launch_install_qemu()
Expand Down Expand Up @@ -43,7 +46,7 @@ function launch_qemu()
test -d qemu-raspbian-network || git clone https://github.com/nachoparker/qemu-raspbian-network.git
sed -i '30s/NO_NETWORK=1/NO_NETWORK=0/' qemu-raspbian-network/qemu-pi.sh
echo "Starting QEMU image $IMG"
( cd qemu-raspbian-network && sudo ./qemu-pi.sh ../$IMG )
( cd qemu-raspbian-network && sudo ./qemu-pi.sh ../$IMG 2>/dev/null )
}

function wait_SSH()
Expand Down
8 changes: 5 additions & 3 deletions nextcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# it is required to save the state of the installation. See variable $STATE_FILE
# It will be necessary to invoke this a number of times for a complete installation

set -xe

sudo su

VER=11.0.1
Expand All @@ -27,8 +29,7 @@ DBPASSWD=ownyourbits
MAX_FILESIZE=1G
STATE_FILE=/home/pi/.installation_state

set -x
set -e
set -xe

test -f $STATE_FILE && STATE=$( cat $STATE_FILE 2>/dev/null )
if [ "$STATE" == "" ]; then
Expand All @@ -52,7 +53,8 @@ elif [ "$STATE" == "0" ]; then
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get autoremove
apt-get install rpi-update -y
echo -e "y\n" | rpi-update

echo 1 > $STATE_FILE
reboot
Expand Down

0 comments on commit 9bedea2

Please sign in to comment.