#!/bin/bash
# Copyright (c) 2000-2015 Synology Inc. All rights reserved.

mkdir -p ${TmpInstDir}/usr/sbin ${TmpInstDir}/etc ${TmpInstDir}/usr/share/ntp ${TmpInstDir}/var/lib/ntp/ ${TmpInstDir}/usr/syno/etc/services.d ${TmpInstDir}/usr/lib/systemd/system
mkdir -m 700 -p ${TmpInstDir}/usr/syno/etc/logcollector/whitelist/
mkdir -m 700 -p ${TmpInstDir}/usr/syno/bin/logcollector/
	install -m 755 -o ntp -g ntp ntpdate/ntpdate ${TmpInstDir}/usr/sbin
	install -m 755 -o ntp -g ntp ntpd/ntpd ${TmpInstDir}/usr/sbin
	install -m 755 -o ntp -g ntp ntpdc/ntpdc ${TmpInstDir}/usr/sbin
	install -m 755 -o ntp -g ntp ntpq/ntpq ${TmpInstDir}/usr/sbin
	install -m 644 synology/ntp.conf ${TmpInstDir}/etc
	install -m 644 synology/ntp.conf.user ${TmpInstDir}/etc
	install -m 644 synology/ntp-common.conf ${TmpInstDir}/usr/share/ntp/ntp-common.conf
	install -m 644 synology/ntp-restrict-serveroff.conf ${TmpInstDir}/usr/share/ntp/ntp-restrict-serveroff.conf
	install -m 644 synology/ntp-restrict-serveron.conf ${TmpInstDir}/usr/share/ntp/ntp-restrict-serveron.conf
	install -m 644 synology/time.google.com.conf ${TmpInstDir}/usr/share/ntp/time.google.com.conf
	install -m 644 synology/pool.ntp.org.conf ${TmpInstDir}/usr/share/ntp/pool.ntp.org.conf
	install -m 644 synology/syno_ntp.sc ${TmpInstDir}/usr/syno/etc/services.d/syno_ntp.sc
	install -m 644 synology/whitelist ${TmpInstDir}/usr/syno/etc/logcollector/whitelist/ntp-4.2.8
	install -m 700 synology/collector_ntpq_status.sh ${TmpInstDir}/usr/syno/bin/logcollector/collector_ntpq_status.sh
	install -m 644 synology/ntpd.service ${TmpInstDir}/usr/lib/systemd/system/

# docker dsm do not support ntpd-client
if checkPlatformFunction SYNO_FEA_NON_SUPPORT_NTPD_CLIENT; then
	install -m 644 synology/ntp.conf.ddsm ${TmpInstDir}/etc/ntp.conf
	rm ${TmpInstDir}/usr/share/ntp/pool.ntp.org.conf
	rm ${TmpInstDir}/usr/share/ntp/time.google.com.conf
fi

if [ "x$NOSTRIP" != "xNOSTRIP" ]; then
	${STRIP} ${TmpInstDir}/usr/sbin/ntpdate
	${STRIP} ${TmpInstDir}/usr/sbin/ntpd
	${STRIP} ${TmpInstDir}/usr/sbin/ntpdc
	${STRIP} ${TmpInstDir}/usr/sbin/ntpq
fi
