Skip to content

Commit d5c1f00

Browse files
committed
rework to use JSON based cfg and more
1 parent 21fee19 commit d5c1f00

File tree

138 files changed

+2123
-1250
lines changed

Some content is hidden

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

138 files changed

+2123
-1250
lines changed

Vagrantfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Vagrant.configure("2") do |config|
4040
4141
# cleanup
4242
source etc/library.sh
43-
install_script post-inst.sh
43+
run_app post-inst.sh
4444
cd -
4545
rm -r /tmp/nextcloudpi
4646
systemctl disable sshd

armbian.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ cd /tmp/overlay
2929
echo -e "\nInstalling NextCloudPi"
3030
source etc/library.sh
3131

32-
install_script lamp.sh
33-
install_script etc/ncp-config.d/nc-nextcloud.sh
34-
activate_script etc/ncp-config.d/nc-nextcloud.sh
35-
install_script ncp.sh
36-
activate_script etc/ncp-config.d/nc-init.sh
37-
install_script post-inst.sh
32+
install_app lamp.sh
33+
install_app etc/ncp-config.d/nc-nextcloud.sh
34+
run_app etc/ncp-config.d/nc-nextcloud.sh
35+
install_app ncp.sh
36+
run_app etc/ncp-config.d/nc-init.sh
37+
run_app post-inst.sh
3838

3939
cd -
4040

bin/ncp-config

+87-46
Original file line numberDiff line numberDiff line change
@@ -11,63 +11,104 @@
1111
# More at https://ownyourbits.com/2017/03/13/nextcloudpi-gets-nextcloudpi-config/
1212
#
1313

14+
BINDIR=/usr/local/bin/ncp
15+
1416
source /usr/local/etc/library.sh
1517
{
18+
# ask for update if outdated
19+
ncp-test-updates 2>/dev/null && {
20+
[[ -f "$chlogfile" ]] && local changelog=$( head -4 "$chlogfile" )
21+
22+
whiptail --backtitle "$backtitle $ncpversion" \
23+
--title "NextCloudPi update available" \
24+
--clear --yesno "Update to $latest_ver?\n\n$changelog" \
25+
15 70
26+
27+
[[ $? -eq $dialog_ok ]] && ncp-update
28+
}
29+
30+
function generate_list()
31+
{
32+
local dir="$1"
33+
unset list
34+
for item in "$dir"/*; do
35+
36+
# directories
37+
[[ -d "$item" ]] && {
38+
local dir="$( basename "$item" )"
39+
list+=(" $dir" "")
40+
continue
41+
}
42+
43+
[[ "$item" =~ ".sh" ]] || continue
44+
45+
# regular ncp_apps
46+
local app="$( basename "$item" .sh )"
47+
local cfg="$cfgdir/$app".cfg
48+
49+
[[ -f "$cfg" ]] && local desc=$( jq -r .description "$cfg" ) || local desc="No description."
50+
is_active_app "$app" "$dir" && local on="*" || local on=" "
1651

17-
function nextcloud-config()
52+
list+=( "$on $app" "$desc" )
53+
done
54+
}
55+
56+
function config_menu()
1857
{
19-
local DIALOG_OK=0
20-
local VERFILE=/var/run/.ncp-latest-version
21-
local BACKTITLE="NextCloudPi configuration ver. "
22-
local CONFDIR=/usr/local/etc/ncp-config.d/
23-
local DESC
24-
25-
# ask for update if outdated
26-
test -f /usr/local/etc/ncp-changelog && \
27-
local CHANGELOG=$( head -4 /usr/local/etc/ncp-changelog )
28-
ncp-test-updates 2>/dev/null && \
29-
whiptail --backtitle "$BACKTITLE $( cat /usr/local/etc/ncp-version )" \
30-
--title "NextCloudPi update available" \
31-
--clear --yesno "Update to $( cat $VERFILE )?\n\n$CHANGELOG" \
32-
15 70
33-
[[ $? -eq $DIALOG_OK ]] && ncp-update
34-
35-
while true; do
36-
37-
# fill options
38-
local LIST=()
39-
for item in $CONFDIR/*.sh; do
40-
DESC=$( grep "DESCRIPTION=" "$item" | sed 's|^DESCRIPTION="||;s|"$||' )
41-
is_active_script "$item" &>/dev/null && local ON="*" || local ON=" "
42-
LIST+=( "$ON $( basename "$item" .sh )" "$DESC" )
43-
done
44-
45-
# launch the selection menu
46-
local script
47-
script=$( whiptail --backtitle "$BACKTITLE $( cat /usr/local/etc/ncp-version )" \
48-
--title "NextCloudPi Software Configuration Tool (ncp-config)" \
49-
--cancel-button Finish --ok-button Select \
50-
--menu "Select program to configure and activate:" 20 105 10 \
51-
"${LIST[@]}" \
52-
3>&1 1>&2 2>&3 )
53-
54-
[[ $? -ne $DIALOG_OK ]] || [[ "$script" == "" ]] && return 0
55-
56-
# remove ✓ and spaces
57-
script=$( sed 's=*\| ==g' <<< "$script" )
58-
59-
# launch selected script
60-
info_script "$script".sh || continue;
61-
configure_script "$script".sh && { echo "Done. Press any key..."; read -r; }
62-
done
58+
local dir="$1"
59+
local backtitle="NextCloudPi configuration ver. "
60+
local latest_ver="$(cat /var/run/.ncp-latest-version)"
61+
local ncpversion="$(cat /usr/local/etc/ncp-version )"
62+
local cfgdir=/usr/local/etc/ncp-config.d
63+
local chlogfile=/usr/local/etc/ncp-changelog
64+
local dialog_ok=0
65+
local desc cfg ncp_app
66+
67+
while true; do
68+
69+
# menu items
70+
generate_list "$dir"
71+
72+
# launch the selection menu
73+
[[ "$dir" == "$BINDIR" ]] && local cancel_btn="Finish" || local cancel_btn="Back"
74+
ncp_app=$( whiptail --backtitle "$backtitle $ncpversion" \
75+
--title "NextCloudPi Configuration Tool (ncp-config)" \
76+
--cancel-button $cancel_btn --ok-button Select \
77+
--menu "Select ncp-app to configure or activate:" 20 105 10 \
78+
"${list[@]}" \
79+
3>&1 1>&2 2>&3 )
80+
81+
[[ $? -ne $dialog_ok ]] || [[ "$ncp_app" == "" ]] && {
82+
[[ "$dir" == "$BINDIR" ]] && return 0
83+
dir="$(dirname "$dir")"
84+
continue
85+
}
86+
87+
# remove * and spaces
88+
ncp_app=$( sed 's=*\| ==g' <<< "$ncp_app" )
89+
90+
# directory selection
91+
[[ -d "$dir/$ncp_app" ]] && {
92+
dir="$dir/$ncp_app"
93+
config_menu "$dir"
94+
return
95+
}
96+
97+
# launch selected ncp_app
98+
info_app "$ncp_app" || continue
99+
configure_app "$ncp_app" || continue
100+
run_app "$ncp_app"
101+
echo "Done. Press any key..."
102+
read -r
103+
done
63104
}
64105

65106
if [[ ${EUID} -ne 0 ]]; then
66107
printf "Must be run as root. Try 'sudo $( basename "$0" )'\n"
67108
exit 1
68109
fi
69110

70-
nextcloud-config
111+
config_menu "$BINDIR"
71112

72113
exit $?
73114
} # force to read the whole thing into memory, as its contents might change in update.sh

bin/ncp-diag

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ test -d "$DATADIR" || DIRINFO=" (doesn't exist)"
2323
USBDEVS="$( lsblk -S -o NAME,TRAN | awk '{ if ( $2 == "usb" ) print $1; }' | tr '\n' ' ' )"
2424
[[ "$USBDEVS" == "" ]] && USBDEVS="none"
2525

26-
[[ -f /usr/local/etc/ncp-config.d/nc-automount.sh ]] && echo "automount|$( grep "^ACTIVE_" /usr/local/etc/ncp-config.d/nc-automount.sh | cut -d'=' -f2 )"
26+
am_cfg="/usr/local/etc/nc-automount.cfg"
27+
[[ -f "$am_cfg" ]] && [[ "$(jq -r ".params[0].value" "$am_cfg")" == "yes" ]] && echo "automount|yes" || echo "automount|no"
2728
echo "USB devices|$USBDEVS"
2829
echo "datadir|$DATADIR$DIRINFO"
2930
[[ "$DIRINFO" == "" ]] && {

bin/ncp-provisioning.sh

+1-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
## redis provisioning
66

77
CFG=/var/www/nextcloud/config/config.php
8-
CONFDIR=/usr/local/etc/ncp-config.d/
98
REDISPASS="$( grep "^requirepass" /etc/redis/redis.conf | cut -f2 -d' ' )"
109

1110
### IF redis password is the default one, generate a new one
@@ -51,9 +50,7 @@ EOF
5150
## nc.limits.sh (auto)adjustments: number of threads, memory limits...
5251

5352
source /usr/local/etc/library.sh
54-
cd "$CONFDIR" &>/dev/null
55-
activate_script nc-limits.sh
56-
cd - &>/dev/null
53+
run_app nc-limits
5754

5855
## Check for interrupted upgrades and rollback
5956
BKP="$( ls -1t /var/www/nextcloud-bkp_*.tar.gz 2>/dev/null | head -1 )"
@@ -62,11 +59,4 @@ BKP="$( ls -1t /var/www/nextcloud-bkp_*.tar.gz 2>/dev/null | head -1 )"
6259
ncp-restore "$BKP" && rm "$BKP"
6360
}
6461

65-
## Fix permissions on NCP folders. The main reason for this is to make devel docker container work
66-
[[ -e $CONFDIR ]] && {
67-
chown -R root:www-data "$CONFDIR"/*
68-
chmod 660 "$CONFDIR"/*
69-
chmod 750 "$CONFDIR"/l10n
70-
}
71-
7262
exit 0

bin/ncp-suggestions

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
OUT="$@"
1616

17-
DNSMASQ_ON="$( grep "^ACTIVE_=" /usr/local/etc/ncp-config.d/dnsmasq.sh | cut -d'=' -f2 )"
17+
source /usr/local/etc/library.sh
1818

1919
grep -q "distribution|.*bian GNU/Linux 9,*" <<<"$OUT" || \
2020
echo -e "You are using an unsupported distro release. Please upgrade to latest Debian/Raspbian"
2121

22-
[[ $DNSMASQ_ON != "yes" ]] && \
22+
is_active_app dnsmasq && \
2323
grep -q "NAT loopback|no" <<<"$OUT" && \
2424
echo -e "\nYou should enable dnsmasq to use your domain inside home"
2525

etc/ncp-config.d/nc-backup-auto.sh bin/ncp/BACKUPS/nc-backup-auto.sh

+3-12
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,9 @@
77
# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
88
#
99

10-
11-
ACTIVE_=no
12-
DESTDIR_=/media/USBdrive/ncp-backups
13-
INCLUDEDATA_=no
14-
COMPRESS_=no
15-
BACKUPDAYS_=7
16-
BACKUPLIMIT_=4
17-
DESCRIPTION="Periodic backups"
18-
1910
configure()
2011
{
21-
[[ $ACTIVE_ != "yes" ]] && {
12+
[[ $ACTIVE != "yes" ]] && {
2213
rm -f /etc/cron.d/ncp-backup-auto
2314
service cron restart
2415
echo "automatic backups disabled"
@@ -28,12 +19,12 @@ configure()
2819
cat > /usr/local/bin/ncp-backup-auto <<EOF
2920
#!/bin/bash
3021
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --on
31-
/usr/local/bin/ncp-backup "$DESTDIR_" "$INCLUDEDATA_" "$COMPRESS_" "$BACKUPLIMIT_"
22+
/usr/local/bin/ncp-backup "$DESTDIR" "$INCLUDEDATA" "$COMPRESS" "$BACKUPLIMIT"
3223
sudo -u www-data php /var/www/nextcloud/occ maintenance:mode --off
3324
EOF
3425
chmod +x /usr/local/bin/ncp-backup-auto
3526

36-
echo "0 3 */${BACKUPDAYS_} * * root /usr/local/bin/ncp-backup-auto" > /etc/cron.d/ncp-backup-auto
27+
echo "0 3 */${BACKUPDAYS} * * root /usr/local/bin/ncp-backup-auto" > /etc/cron.d/ncp-backup-auto
3728
service cron restart
3829

3930
echo "automatic backups enabled"

etc/ncp-config.d/nc-backup.sh bin/ncp/BACKUPS/nc-backup.sh

+1-8
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
# More at https://ownyourbits.com/2017/02/13/nextcloud-ready-raspberry-pi-image/
88
#
99

10-
11-
DESTDIR_=/media/USBdrive/ncp-backups
12-
INCLUDEDATA_=no
13-
COMPRESS_=no
14-
BACKUPLIMIT_=4
15-
DESCRIPTION="Backup this NC instance to a file"
16-
1710
install()
1811
{
1912
cat > /usr/local/bin/ncp-backup <<'EOF'
@@ -110,7 +103,7 @@ EOF
110103

111104
configure()
112105
{
113-
ncp-backup "$DESTDIR_" "$INCLUDEDATA_" "$COMPRESS_" "$BACKUPLIMIT_"
106+
ncp-backup "$DESTDIR" "$INCLUDEDATA" "$COMPRESS" "$BACKUPLIMIT"
114107
}
115108

116109
# License

etc/ncp-config.d/nc-export-ncp.sh bin/ncp/BACKUPS/nc-export-ncp.sh

+6-21
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,20 @@
77
# GPL licensed (see end of file) * Use at your own risk!
88
#
99

10-
DIR_=/media/USBdrive/
1110

12-
DESCRIPTION="Export NextCloudPi configuration"
1311

1412
configure()
1513
{
16-
[[ -d "$DIR_" ]] || { echo "directory $DIR_ does not exist"; return 1; }
14+
[[ -d "$DIR" ]] || { echo "directory $DIR does not exist"; return 1; }
1715

18-
local DESTFILE="$DIR_"/ncp-config_$( date +"%Y%m%d" ).tar
19-
rm -rf /tmp/ncp-export
20-
mkdir -p /tmp/ncp-export
21-
cd /tmp/ncp-export || return 1
22-
23-
for file in /usr/local/etc/ncp-config.d/*; do
24-
VARS=( $( grep "^[[:alpha:]]\+_=" "$file" | cut -d= -f1 | sed 's|_$||' ) )
25-
VALS=( $( grep "^[[:alpha:]]\+_=" "$file" | cut -d= -f2 ) )
26-
local CONFIG=""
27-
for i in $( seq 0 1 $(( ${#VARS[@]} - 1 )) ); do
28-
CONFIG+="${VARS[$i]}=${VALS[$i]}\n"
29-
done
30-
echo -e "$CONFIG" > "$( basename "$file" .sh ).cfg"
31-
done
32-
33-
tar -cf "$DESTFILE" *
34-
chmod 600 "$DESTFILE"
16+
local destfile="$DIR"/ncp-config_$( date +"%Y%m%d" ).tar
17+
18+
tar -cf "$destfile" -C /usr/local/etc/ncp-config.d .
19+
chmod 600 "$destfile"
3520

3621
cd $OLDPWD
3722
rm -rf /tmp/ncp-export
38-
echo -e "configuration exported to $DESTFILE"
23+
echo -e "configuration exported to $destfile"
3924
}
4025

4126
install() { :; }

etc/ncp-config.d/nc-import-ncp.sh bin/ncp/BACKUPS/nc-import-ncp.sh

+9-28
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,30 @@
77
# GPL licensed (see end of file) * Use at your own risk!
88
#
99

10-
FILE_=/media/USBdrive/ncp-config_xxxxxx.cfg
1110

12-
DESCRIPTION="Import NextCloudPi configuration from file"
11+
12+
CFGDIR="/usr/local/etc/ncp-config.d"
1313

1414
configure()
1515
{
16-
[[ -f "$FILE_" ]] || { echo "export file $FILE_ does not exist"; return 1; }
16+
[[ -f "$FILE" ]] || { echo "export file $FILE does not exist"; return 1; }
1717

1818
source /usr/local/etc/library.sh || return 1
19-
cd /usr/local/etc/ncp-config.d || return 1
19+
cd "$CFGDIR" || return 1
2020

2121
# extract export
22-
local TMP="/tmp/ncp-export"
23-
rm -rf "$TMP"
24-
mkdir -p "$TMP"
25-
tar -xf "$FILE_" -C "$TMP"
22+
tar -xf "$FILE" -C "$CFGDIR"
2623

2724
# UGLY workaround to prevent apache from restarting upon activating some extras
2825
# which leads to the operation appearing to fail in ncp-web
29-
echo "invalid_op" >> /etc/apache2/sites-available/000-default.conf
30-
31-
# restore configuration and activate
32-
for file in /"$TMP"/*; do
33-
local SCRIPT="$( basename "$file" .cfg ).sh"
34-
35-
# restore
36-
[ -f /usr/local/etc/ncp-config.d/"$SCRIPT" ] && {
37-
local VARS=( $( grep "^[[:alpha:]]\+=" "$file" | cut -d= -f1 ) )
38-
local VALS=( $( grep "^[[:alpha:]]\+=" "$file" | cut -d= -f2 ) )
39-
for i in $( seq 0 1 ${#VARS[@]} ); do
40-
sed -i "s|^${VARS[$i]}_=.*|${VARS[$i]}_=${VALS[$i]}|" "$SCRIPT"
41-
done
42-
}
26+
#echo "invalid_op" >> /etc/apache2/sites-available/000-default.conf
4327

44-
# activate
45-
grep -q "^ACTIVE_=yes" "$SCRIPT" && echo && activate_script "$SCRIPT"
46-
done
28+
# activate
29+
# TODO
4730

4831
# Fix invalid configuration
49-
sed -i "/^invalid_op/d" /etc/apache2/sites-available/000-default.conf
32+
#sed -i "/^invalid_op/d" /etc/apache2/sites-available/000-default.conf
5033

51-
# cleanup
52-
rm -rf "$TMP"
5334
echo -e "\nconfiguration restored"
5435

5536
# delayed in bg so it does not kill the connection, and we get AJAX response

0 commit comments

Comments
 (0)