|
11 | 11 | # More at https://ownyourbits.com/2017/03/13/nextcloudpi-gets-nextcloudpi-config/
|
12 | 12 | #
|
13 | 13 |
|
| 14 | +BINDIR=/usr/local/bin/ncp |
| 15 | + |
14 | 16 | source /usr/local/etc/library.sh
|
15 | 17 | {
|
| 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=" " |
16 | 51 |
|
17 |
| -function nextcloud-config() |
| 52 | + list+=( "$on $app" "$desc" ) |
| 53 | + done |
| 54 | +} |
| 55 | + |
| 56 | +function config_menu() |
18 | 57 | {
|
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 |
63 | 104 | }
|
64 | 105 |
|
65 | 106 | if [[ ${EUID} -ne 0 ]]; then
|
66 | 107 | printf "Must be run as root. Try 'sudo $( basename "$0" )'\n"
|
67 | 108 | exit 1
|
68 | 109 | fi
|
69 | 110 |
|
70 |
| -nextcloud-config |
| 111 | +config_menu "$BINDIR" |
71 | 112 |
|
72 | 113 | exit $?
|
73 | 114 | } # force to read the whole thing into memory, as its contents might change in update.sh
|
|
0 commit comments