Skip to content

Commit 30ca93c

Browse files
committed
build: add LXC/LXD support
Signed-off-by: nachoparker <[email protected]>
1 parent c037c11 commit 30ca93c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+355
-162
lines changed

.gitignore

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.*.swp
2-
qemu-raspbian-network/
3-
archive/
4-
output/
5-
cache/
6-
torrent/
7-
armbian/
8-
raspbian_root
9-
raspbian_boot
10-
ncp-web/wizard.cfg
11-
ncp-web/ncp-web.cfg
12-
docker-armhf/qemu-arm-static
13-
.vagrant/
2+
/qemu-raspbian-network/
3+
/archive/
4+
/output/
5+
/cache/
6+
/torrent/
7+
/armbian/
8+
/raspbian_root
9+
/raspbian_boot
10+
/ncp-web/wizard.cfg
11+
/ncp-web/ncp-web.cfg
12+
/docker-armhf/qemu-arm-static
13+
/.vagrant/

bin/ncp-provisioning.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# this script runs at startup to provide an unique random passwords for each instance
44

5+
source /usr/local/etc/library.sh
6+
57
## redis provisioning
68

79
CFG=/var/www/nextcloud/config/config.php
@@ -14,7 +16,7 @@ REDISPASS="$( grep "^requirepass" /etc/redis/redis.conf | cut -f2 -d' ' )"
1416
echo Provisioning Redis password
1517
sed -i -E "s|^requirepass .*|requirepass $REDISPASS|" /etc/redis/redis.conf
1618
chown redis:redis /etc/redis/redis.conf
17-
[[ "$DOCKERBUILD" != 1 ]] && systemctl restart redis
19+
is_docker || systemctl restart redis
1820
}
1921

2022
### If there exists already a configuration adjust the password

bin/ncp/CONFIG/nc-nextcloud.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ install()
1919
# During build, this step is run before ncp.sh. Avoid executing twice
2020
[[ -f /usr/lib/systemd/system/nc-provisioning.service ]] && return 0
2121

22-
source /usr/local/etc/library.sh # sets PHPVER RELEASE
23-
2422
# Optional packets for Nextcloud and Apps
2523
apt-get update
26-
$APTINSTALL lbzip2 iputils-ping jq
24+
$APTINSTALL lbzip2 iputils-ping jq wget
2725
$APTINSTALL -t $RELEASE php-smbclient exfat-fuse exfat-utils # for external storage
2826
$APTINSTALL -t $RELEASE php${PHPVER}-exif # for gallery
2927
$APTINSTALL -t $RELEASE php${PHPVER}-gmp # for bookmarks
@@ -56,6 +54,16 @@ install()
5654
echo "maxmemory $REDIS_MEM" >> $REDIS_CONF
5755
echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
5856

57+
if is_lxc; then
58+
# Otherwise it fails to start in Buster LXC container
59+
mkdir -p /etc/systemd/system/redis-server.service.d
60+
cat > /etc/systemd/system/redis-server.service.d/lxc_fix.conf <<'EOF'
61+
[Service]
62+
ReadOnlyDirectories=
63+
EOF
64+
systemctl daemon-reload
65+
fi
66+
5967
chown redis: "$REDIS_CONF"
6068
usermod -a -G redis www-data
6169

bin/ncp/NETWORKING/letsencrypt.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ install()
3535
rm -f /etc/cron.d/certbot
3636
mkdir -p /etc/letsencrypt/live
3737

38-
[[ "$DOCKERBUILD" == 1 ]] && {
38+
is_docker && {
3939
# execute before lamp stack
4040
cat > /etc/services-available.d/009letsencrypt <<EOF
4141
#!/bin/bash
@@ -125,7 +125,7 @@ EOF
125125
rm -rf $ncdir/.well-known
126126

127127
# Update configuration
128-
[[ "$DOCKERBUILD" == 1 ]] && update-rc.d letsencrypt enable
128+
is_docker && update-rc.d letsencrypt enable
129129

130130
return 0
131131
}

bin/ncp/SYSTEM/nc-swapfile.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ configure()
4747

4848
install()
4949
{
50-
apt-get update
51-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends dphys-swapfile
50+
apt_install dphys-swapfile
5251
}
5352

5453

Vagrantfile renamed to build/Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Vagrant.configure("2") do |config|
2626
BRANCH=master
2727
#BRANCH=devel # uncomment to install devel
2828
apt-get update
29-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git
29+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git ca-certificates
3030
3131
# install
3232
git clone -b "$BRANCH" https://github.com/nextcloud/nextcloudpi.git /tmp/nextcloudpi

armbian.sh renamed to build/armbian/armbian.sh

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,16 @@ touch /.ncp-image
3232
# install NCP
3333
echo -e "\nInstalling NextCloudPi"
3434

35-
mkdir -p /usr/local/etc/ncp-config.d/
36-
cp etc/ncp-config.d/nc-nextcloud.cfg /usr/local/etc/ncp-config.d/
37-
cp etc/library.sh /usr/local/etc/
38-
cp etc/ncp.cfg /usr/local/etc/
39-
4035
hostname -F /etc/hostname # fix 'sudo resolve host' errors
41-
install_app lamp.sh
42-
install_app bin/ncp/CONFIG/nc-nextcloud.sh
43-
run_app_unsafe bin/ncp/CONFIG/nc-nextcloud.sh
44-
rm /usr/local/etc/ncp-config.d/nc-nextcloud.cfg # armbian overlay is ro
45-
install_app ncp.sh
46-
run_app_unsafe bin/ncp/CONFIG/nc-init.sh
47-
run_app_unsafe post-inst.sh
4836

49-
cd -
37+
CODE_DIR="$(pwd)" bash install.sh
38+
run_app_unsafe post-inst.sh
5039

5140
# disable SSH by default, it can be enabled through ncp-web
5241
systemctl disable ssh
5342

43+
cd -
44+
5445

5546
# License
5647
#
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

batch.sh renamed to build/batch.sh

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
#
99

1010
set -e
11-
12-
version=$(git describe --tags --always)
13-
version=${version%-*-*}
11+
source build/buildlib.sh # initializes $IMGNAME
1412

1513
## BUILDING
16-
source buildlib.sh # initializes $IMGNAME
1714

1815
[[ "$FTPPASS" == "" ]] && {
1916
echo -e "\e[1mNo FTPPASS variable found, FTP won't work.\nYou can ^C to cancel now\e[0m"
@@ -29,27 +26,27 @@ sleep 5
2926
rm -f ncp-web/wizard.cfg
3027

3128
# Raspbian
32-
./build-SD-rpi.sh
29+
build/build-SD-rpi.sh
3330
IMG="$( ls -1t tmp/*.img | head -1 )"
34-
./build-SD-berryboot.sh "$IMG"
31+
build/build-SD-berryboot.sh "$IMG"
3532

3633
# Armbian
37-
./build-SD-armbian.sh odroidxu4 OdroidHC2
38-
./build-SD-armbian.sh rockpro64 RockPro64
39-
./build-SD-armbian.sh rock64 Rock64
40-
./build-SD-armbian.sh bananapi Bananapi
41-
./build-SD-armbian.sh odroidhc4 OdroidHC4
42-
./build-SD-armbian.sh odroidc4 OdroidC4
43-
./build-SD-armbian.sh odroidc2 OdroidC2
44-
#./build-SD-armbian.sh orangepizeroplus2-h5 OrangePiZeroPlus2
34+
build/build-SD-armbian.sh odroidxu4 OdroidHC2
35+
build/build-SD-armbian.sh rockpro64 RockPro64
36+
build/build-SD-armbian.sh rock64 Rock64
37+
build/build-SD-armbian.sh bananapi Bananapi
38+
build/build-SD-armbian.sh odroidhc4 OdroidHC4
39+
build/build-SD-armbian.sh odroidc4 OdroidC4
40+
build/build-SD-armbian.sh odroidc2 OdroidC2
41+
#build/build-SD-armbian.sh orangepizeroplus2-h5 OrangePiZeroPlus2
4542

4643
# VM
47-
./build-VM.sh
44+
build/build-VM.sh
4845

4946
# Docker
50-
./build-docker.sh x86
51-
./build-docker.sh armhf
52-
./build-docker.sh arm64
47+
build/build-docker.sh x86
48+
build/build-docker.sh armhf
49+
build/build-docker.sh arm64
5350

5451
[[ "$FTPPASS" == "" ]] && exit
5552

build/build-LXC.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# Batch creation of NextCloudPi LXC image
4+
#
5+
# Copyleft 2021 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
6+
# GPL licensed (see end of file) * Use at your own risk!
7+
#
8+
# Usage:
9+
#
10+
11+
set -e
12+
source build/buildlib.sh
13+
14+
#CLEAN=0 # Pass this envvar to skip cleaning download cache
15+
IMG="NextCloudPi_LXC_$( date "+%m-%d-%y" ).img"
16+
IMG=tmp/"$IMG"
17+
18+
TAR=output/"$( basename "$IMG" .img ).tar.bz2"
19+
20+
test -f "$TAR" && { echo "$TAR already exists. Skipping... "; exit 0; }
21+
22+
##############################################################################
23+
24+
## preparations
25+
26+
test -f "$TAR" && { echo "$TAR already exists. Skipping... "; exit 0; }
27+
set -e
28+
prepare_dirs # tmp cache output
29+
30+
## BUILD NCP
31+
32+
echo -e "\e[1m\n[ Build NCP ]\e[0m"
33+
34+
# TODO sudo
35+
sudo lxc-destroy ncp -f
36+
sudo lxc-create -n ncp -t download -B btrfs -- --dist debian --release buster --arch amd64 # TODO vars for distro and stuff
37+
sudo cp lxc_config /var/lib/lxc/ncp/config
38+
sudo lxc-start -n ncp
39+
sudo lxc-attach -n ncp --clear-env -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
40+
sudo lxc-attach -n ncp --clear-env -- bash /build/install.sh
41+
sudo lxc-attach -n ncp --clear-env -- poweroff
42+
43+
exit 0 # TODO
44+
45+
## pack
46+
pack_image "$IMG" "$TAR"
47+
48+
## test
49+
#set_static_IP "$IMG" "$IP"
50+
#test_image "$IMG" "$IP" # TODO fix tests
51+
52+
# upload
53+
create_torrent "$TAR"
54+
upload_ftp "$( basename "$TAR" .tar.bz2 )"
55+
56+
57+
# License
58+
#
59+
# This script is free software; you can redistribute it and/or modify it
60+
# under the terms of the GNU General Public License as published by
61+
# the Free Software Foundation; either version 2 of the License, or
62+
# (at your option) any later version.
63+
#
64+
# This script is distributed in the hope that it will be useful,
65+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
66+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67+
# GNU General Public License for more details.
68+
#
69+
# You should have received a copy of the GNU General Public License
70+
# along with this script; if not, write to the
71+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
72+
# Boston, MA 02111-1307 USA

build/build-LXD.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Batch creation of NextCloudPi LXD image
4+
#
5+
# Copyleft 2021 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
6+
# GPL licensed (see end of file) * Use at your own risk!
7+
#
8+
# Usage:
9+
#
10+
11+
set -e
12+
source build/buildlib.sh
13+
14+
#CLEAN=0 # Pass this envvar to skip cleaning download cache
15+
IMG="NextCloudPi_LXD_$( date "+%m-%d-%y" ).img"
16+
IMG=tmp/"$IMG"
17+
18+
TAR=output/"$( basename "$IMG" .img ).tar.bz2"
19+
20+
test -f "$TAR" && { echo "$TAR already exists. Skipping... "; exit 0; }
21+
22+
##############################################################################
23+
24+
## preparations
25+
26+
test -f "$TAR" && { echo "$TAR already exists. Skipping... "; exit 0; }
27+
set -e
28+
prepare_dirs # tmp cache output
29+
30+
## BUILD NCP
31+
32+
echo -e "\e[1m\n[ Build NCP ]\e[0m"
33+
34+
lxc delete -f ncp 2>/dev/null || true
35+
lxc launch images:debian/buster ncp -c security.privileged=true # TODO this is privileged
36+
lxc config device add ncp buildcode disk source="$(pwd)" path=/build
37+
lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
38+
lxc exec ncp -- bash -c 'CODE_DIR=/build bash /build/install.sh'
39+
lxc exec ncp -- bash -c 'source /build/etc/library.sh; run_app_unsafe /build/post-inst.sh'
40+
lxc config device remove ncp buildcode
41+
lxc publish ncp -f --alias ncp:"${version}"
42+
lxc export ncp "$TAR"
43+
44+
# TODO set up auto testing
45+
46+
exit 0 # TODO
47+
48+
## pack
49+
pack_image "$IMG" "$TAR"
50+
51+
## test
52+
#set_static_IP "$IMG" "$IP"
53+
#test_image "$IMG" "$IP" # TODO fix tests
54+
55+
# upload
56+
create_torrent "$TAR"
57+
upload_ftp "$( basename "$TAR" .tar.bz2 )"
58+
59+
60+
# License
61+
#
62+
# This script is free software; you can redistribute it and/or modify it
63+
# under the terms of the GNU General Public License as published by
64+
# the Free Software Foundation; either version 2 of the License, or
65+
# (at your option) any later version.
66+
#
67+
# This script is distributed in the hope that it will be useful,
68+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
69+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70+
# GNU General Public License for more details.
71+
#
72+
# You should have received a copy of the GNU General Public License
73+
# along with this script; if not, write to the
74+
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
75+
# Boston, MA 02111-1307 USA

build-SD-armbian.sh renamed to build/build-SD-armbian.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ IMG="NextCloudPi_${BNAME}_$( date "+%m-%d-%y" ).img"
1717
IMG=tmp/"$IMG"
1818
TAR=output/"$( basename "$IMG" .img ).tar.bz2"
1919

20+
set -e
21+
source build/buildlib.sh
22+
2023
test -f "$TAR" && { echo "$TAR already exists. Skipping... "; exit 0; }
2124

22-
set -e
23-
source buildlib.sh
2425
source etc/library.sh # sets RELEASE
2526

2627
prepare_dirs # tmp cache output
@@ -32,7 +33,7 @@ prepare_dirs # tmp cache output
3233
# add NCP modifications
3334
mkdir -p armbian/userpatches armbian/userpatches/overlay
3435
rm -f ncp-web/{wizard.cfg,ncp-web.cfg}
35-
cp armbian.sh armbian/userpatches/customize-image.sh
36+
cp build/armbian/armbian.sh armbian/userpatches/customize-image.sh
3637
rsync -Aax --delete --exclude-from .gitignore --exclude *.img --exclude *.bz2 . armbian/userpatches/overlay/
3738

3839
# GENERATE IMAGE

build-SD-berryboot.sh renamed to build/build-SD-berryboot.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
# Usage: ./build-SD-berryboot.sh <img>
99
#
1010

11+
set -e
12+
source build/buildlib.sh
13+
1114
SRC="$1"
1215
IMG="NextCloudPi_RPi_Berryboot_$( date "+%m-%d-%y" ).img"
1316
TAR=output/"$( basename "$IMG" .img ).tar.bz2"
1417

15-
set -e
16-
source buildlib.sh
17-
1818
test -f "$TAR" && { echo "$TAR already exists. Skipping... "; exit 0; }
1919

2020
[[ -f "$SRC" ]] || { echo "$SRC not found"; exit 1; }

0 commit comments

Comments
 (0)