Skip to content

Commit

Permalink
Merge pull request #1923 from nextcloud/devel
Browse files Browse the repository at this point in the history
Detect db prefix dynamically
  • Loading branch information
theCalcaholic authored May 6, 2024
2 parents 3778e39 + 8c1dc9f commit 3f979ee
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 153 deletions.
248 changes: 125 additions & 123 deletions .github/workflows/build-lxd.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/lxd-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
lxd:
uses: ./.github/workflows/build-lxd.yml
with:
git_ref: "${{ github.ref }}"
git_ref: "${{ github.head_ref || github.ref_name }}"
2 changes: 1 addition & 1 deletion bin/ncp-update-nc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fi
# https://github.com/nextcloud/server/issues/10949
pgrep -cf cron.php &>/dev/null && { pkill -f cron.php; sleep 3; }
pgrep -cf cron.php &>/dev/null && { echo "cron.php running. Abort"; exit 1; }
mysql nextcloud <<<"UPDATE oc_jobs SET reserved_at=0;"
mysql nextcloud <<<"UPDATE ${DB_PREFIX}jobs SET reserved_at=0;"

# cleanup
####################
Expand Down
10 changes: 5 additions & 5 deletions bin/ncp/CONFIG/nc-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ EOF
}

mysql nextcloud <<EOF
replace into oc_appconfig values ( 'theming', 'name' , "NextCloudPi" , 2, null);
replace into oc_appconfig values ( 'theming', 'slogan' , "keep your data close" , 2, null);
replace into oc_appconfig values ( 'theming', 'url' , "https://nextcloudpi.com" , 2, null);
replace into oc_appconfig values ( 'theming', 'logoMime' , "image/svg+xml" , 2, null);
replace into oc_appconfig values ( 'theming', 'backgroundMime', "image/png" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'name' , "NextCloudPi" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'slogan' , "keep your data close" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'url' , "https://nextcloudpi.com" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'logoMime' , "image/svg+xml" , 2, null);
replace into ${DB_PREFIX}appconfig values ( 'theming', 'backgroundMime', "image/png" , 2, null);
EOF

# NCP app
Expand Down
2 changes: 1 addition & 1 deletion bin/ncp/TOOLS/nc-previews.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ configure()
}

rm -r "$datadir"/appdata_*/preview/* &>/dev/null
mysql nextcloud <<<"delete from oc_filecache where path like \"appdata_%/preview/%\""
mysql nextcloud <<<"delete from ${DB_PREFIX?}filecache where path like \"appdata_%/preview/%\""
ncc files:scan-app-data -n
}
Expand Down
36 changes: 21 additions & 15 deletions build/build-LXD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ prepare_dirs # tmp cache output

debian_version="$(. etc/library.sh > /dev/null 2>&1; echo "${RELEASE%%-security}")"

LXC_CMD=lxc
[[ "$USE_INCUS" == "yes" ]] && LXC_CMD=incus
LXC_CMD=(lxc)
[[ "$USE_INCUS" == "yes" ]] && LXC_CMD=(incus)

$LXC_CMD delete -f ncp 2>/dev/null || true
LXC_CREATE=($LXC_CMD init -p default)
"${LXC_CMD[@]}" info || LXC_CMD=(sudo "${LXC_CMD[0]}")

"${LXC_CMD[@]}" delete -f ncp 2>/dev/null || true
LXC_CREATE=("${LXC_CMD[@]}" init -p default)
[[ -n "$LXD_EXTRA_PROFILE" ]] && LXC_CREATE+=(-p "$LXD_EXTRA_PROFILE")
if [[ -n "$LXD_ARCH" ]] && [[ "$LXD_ARCH" != "x86" ]]
then
Expand All @@ -64,19 +66,23 @@ LXC_CREATE+=(ncp)
set -x
EXEC_ARGS=()
[[ -z "$BRANCH" ]] || EXEC_ARGS+=(--env "BRANCH=${BRANCH}")
systemd-run --user --scope -p "Delegate=yes" $LXC_CMD start ncp -q || \
sudo systemd-run --scope -p "Delegate=yes" $LXC_CMD start ncp -q
$LXC_CMD config device add ncp buildcode disk source="$(pwd)" path=/build
$LXC_CMD exec ncp "${EXEC_ARGS[@]}" -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
$LXC_CMD exec ncp "${EXEC_ARGS[@]}" -- bash -c 'CODE_DIR=/build DBG=x bash /build/install.sh'
$LXC_CMD exec ncp "${EXEC_ARGS[@]}" -- bash -c 'source /build/etc/library.sh; run_app_unsafe /build/post-inst.sh'
$LXC_CMD exec ncp "${EXEC_ARGS[@]}" -- bash -c "echo '$(basename "$IMG")' > /usr/local/etc/ncp-baseimage"
$LXC_CMD stop ncp
$LXC_CMD config device remove ncp buildcode
$LXC_CMD publish -q ncp -f --alias ncp/"${version}"
systemd-run --user --scope -p "Delegate=yes" "${LXC_CMD[@]}" start ncp -q || \
sudo systemd-run --scope -p "Delegate=yes" "${LXC_CMD[@]}" start ncp -q || {
rc=$?
"${LXC_CMD[@]}" info --show-log ncp
exit $rc
}
"${LXC_CMD[@]}" config device add ncp buildcode disk source="$(pwd)" path=/build
"${LXC_CMD[@]}" exec ncp "${EXEC_ARGS[@]}" -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
"${LXC_CMD[@]}" exec ncp "${EXEC_ARGS[@]}" -- bash -c 'CODE_DIR=/build DBG=x bash /build/install.sh'
"${LXC_CMD[@]}" exec ncp "${EXEC_ARGS[@]}" -- bash -c 'source /build/etc/library.sh; run_app_unsafe /build/post-inst.sh'
"${LXC_CMD[@]}" exec ncp "${EXEC_ARGS[@]}" -- bash -c "echo '$(basename "$IMG")' > /usr/local/etc/ncp-baseimage"
"${LXC_CMD[@]}" stop ncp
"${LXC_CMD[@]}" config device remove ncp buildcode
"${LXC_CMD[@]}" publish -q ncp -f --alias ncp/"${version}"

## pack
[[ " $* " =~ .*" --pack ".* ]] && $LXC_CMD image export -q ncp/"${version}" "$TAR"
[[ " $* " =~ .*" --pack ".* ]] && "${LXC_CMD[@]}" image export -q ncp/"${version}" "$TAR"

exit 0

Expand Down
3 changes: 2 additions & 1 deletion etc/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export NCDIR=/var/www/nextcloud
export ncc=/usr/local/bin/ncc
export NCPCFG=${NCPCFG:-etc/ncp.cfg}
export ARCH="$(dpkg --print-architecture)"
export DB_PREFIX="$(php -r 'include("/var/www/nextcloud/config/config.php"); echo $CONFIG['"'dbtableprefix'"'];' || echo 'oc_')"
[[ "${ARCH}" =~ ^(armhf|arm)$ ]] && ARCH="armv7"
[[ "${ARCH}" == "arm64" ]] && ARCH=aarch64
[[ "${ARCH}" == "amd64" ]] && ARCH=x86_64
Expand Down Expand Up @@ -568,7 +569,7 @@ function notify_admin()
{
local header="$1"
local msg="$2"
local admins=$(mysql -u root nextcloud -Nse "select uid from oc_group_user where gid='admin';")
local admins=$(mysql -u root nextcloud -Nse "select uid from ${DB_PREFIX}group_user where gid='admin';")
[[ "${admins}" == "" ]] && { echo "admin user not found" >&2; return 0; }
while read -r admin
do
Expand Down
18 changes: 12 additions & 6 deletions tests/system_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@
'/.ncp-image',
]

lxc_command = 'lxc'
if 'USE_INCUS' in os.environ and os.environ['USE_INCUS'] == 'yes':
lxc_command = 'incus'


class tc:
"terminal colors"
Expand Down Expand Up @@ -298,9 +294,19 @@ def set_cohorte_id(cohorte_id: int) -> CompletedProcess:
except:
dockers_running = ''

lxc_command = ['lxc'] if 'USE_INCUS' not in os.environ or os.environ['USE_INCUS'] != 'yes' else ['incus']

try:
lxc_test = run(lxc_command + ['info'], stdout=PIPE, check=True)
if lxc_test.returncode != 0:
raise Exception(f"failed to execute {lxc_command} info")
except:
lxc_test = run(['sudo'] + lxc_command + ['info'], stdout=PIPE, check='True')
lxc_command = ['sudo'] + lxc_command

# detect if we are running this in a LXC instance
try:
lxc_running = run([lxc_command, 'info', 'ncp'], stdout=PIPE, check = True)
lxc_running = run(lxc_command + ['info', 'ncp'], stdout=PIPE, check = True)
except:
lxc_running = False

Expand Down Expand Up @@ -328,7 +334,7 @@ def set_cohorte_id(cohorte_id: int) -> CompletedProcess:
# LXC method
elif lxc_running:
print( tc.brown + "* local LXC instance detected" + tc.normal)
pre_cmd = [lxc_command, 'exec', 'ncp', '--']
pre_cmd = lxc_command + ['exec', 'ncp', '--']

elif systemd_container_running:
pre_cmd = ['systemd-run', '--wait', '-P', '--machine=ncp']
Expand Down
10 changes: 10 additions & 0 deletions updates/1.54.2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

. /etc/os-release

if [[ "$VERSION_ID" -eq 12 ]]
then
rm -f /usr/local/etc/ncp-recommended.cfg
fi

DEBIAN_FRONTEND=noninteractive sudo apt-get install -y --no-install-recommends zstd

0 comments on commit 3f979ee

Please sign in to comment.