Created
September 15, 2020 08:13
-
-
Save pleasemarkdarkly/5cd29790645918b7ab0fec646a441741 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
### BEGIN INIT INFO | |
# Location: /usr/local/etc/rc.d | |
# Provides: Synology Custom Services | |
# Required-Start: hostname $local_fs | |
# Required-Stop: | |
# Should-Start: | |
# Default-Start: 1 2 3 4 5 | |
# Default-Stop: | |
# Short-Description: Additional services start upon Synology DSM reboot | |
# Description: Entware, Chroot, SSH, Cron | |
### END INIT INFO | |
PATH=/opt/bin:/sbin:/usr/sbin:/bin:/usr/bin:$PATH | |
SESSION=$(date +"%Y%m%d-%H%M") | |
HOSTNAME=`hostname` | |
SYSTEM_LOG="/root/synology-extra-config.${SESSION}.log" | |
CHROOT="/var/packages/debian-chroot/target/var/chroottarget" | |
[ ! -f "${SYSTEM_LOG}" ] && touch "${SYSTEM_LOG}" | |
function sendtext () { | |
curl -X POST https://textbelt.com/text --data-urlencode phone='7605077572' --data-urlencode message="$1" -d key=textbelt | |
} | |
function disable_remove_synology_packages () { | |
synoservicecfg --disable pkgctl-SynoFinder | |
synopkg uninstall SynoFinder | |
} | |
function additional_synology_config () { | |
synouser –setpw root [password] # Reenable logging in as root | |
} | |
function print_config_order () { | |
cat<<ENDOFTEXT | |
system scripts | |
/usr/local/etc/rc.d/extra_config.sh - first user script to be triggered | |
/usr/local/etc/rc.d/entware-startup.sh | |
/var/packages/debian-chroot/scripts/start-stop-status - chroot | |
session scripts | |
/etc/profile | |
/opt/etc/profile | |
$HOME/.profile | |
$HOME/.zshrc | |
ENDOFTEXT | |
} | |
function setup_simlinks () { | |
ln -s /volume1/systems/synology_918+/scripts/sshd_banner /etc/ssh/sshd_banner | |
ln -s /volume1/systems/synology_918+/scripts/startup-entware.sh /usr/local/etc/rc.d/startup-entware.sh | |
ln -s /volume1/systems/synology_918+/scripts/startup-mounts.sh /usr/local/etc/rc.d/startup-mounts.sh | |
ln -s /volume1/systems/synology_918+/scripts/startup-opt-file-perf.sh /usr/local/etc/rc.d/startup-opt-file-perf.sh | |
ln -s /volume1/systems/synology_918+/scripts/startup-synology-system.sh /usr/local/etc/rc.d/startup-synology-system.sh | |
} | |
function enable_chroot () { | |
[ -f /usr/local/etc/rc.d/chroot-start-stop-status ] && /usr/local/etc/rc.d/chroot-start-stop-status start | |
[ -f /usr/local/etc/rc.d/chroot-start-stop-status ] && /usr/local/etc/rc.d/chroot-start-stop-status status | |
chroot "${CHROOT}" "/bin/bash" -c "/etc/init.d/cron start" | |
chroot "${CHROOT}" "/bin/bash" -c "/etc/init.d/ssh start" | |
} | |
do_start () { | |
echo "Starting $0…" | |
# disable_remove_synology_packages | |
# reset_normal_raid_read_speeds | |
[ -f /opt/bin/mosh-server ] && /opt/bin/mosh-server # start synology mosh-server | |
# [ -f /usr/local/etc/rc.d/startup-entware.sh ] && /usr/local/etc/rc.d/startup-entware.sh start | |
# [ -f /usr/local/etc/rc.d/startup-mounts.sh ] && /usr/local/etc/rc.d/startup-mounts.sh start | |
[ -d /volume1/@appstore/debian-chroot/ ] && enable_chroot | |
# Setup Tun.sh for Docker Transmission | |
[ -f /volume1/systems/synology_918+/scripts/TUN.sh ] && /volume1/systems/synology_918+/scripts/TUN.sh | |
echo "Started $0…" | |
} | |
do_stop () { | |
echo "Stopping $0…" | |
echo "Backing up Synology configuration upon shutdown" | |
# /root/synology_config/scripts/backup_synology_config.sh | |
# cd /volume1/systems/synology_918+/synology-github/blackbox8000/config && synoconfbkp export | |
synoconfbkp export --filepath="/volume1/systems/synology_918+/synology-github/blackbox8000/config/blackbox8000_$(date +%Y%m%d-%H%M%S).dss" | |
/volume1/systems/synology_918+/scripts/backup.dd-wrt.routers.sh | |
[ -f /usr/local/etc/rc.d/startup-mounts.sh ] && /usr/local/etc/rc.d/startup-mounts.sh stop | |
[ -f /usr/local/etc/rc.d/chroot-start-stop-status ] && /usr/local/etc/rc.d/chroot-start-stop-status stop | |
# chroot /var/packages/debian-chroot/target/var/chroottarget/ "/bin/bash" -c "/etc/init.d/cron restart" | |
chroot "${CHROOT}" "/bin/bash" -c "/etc/init.d/cron start" | |
chroot "${CHROOT}" "/bin/bash" -c "/etc/init.d/ssh start" | |
echo "Stopped $0…" | |
} | |
do_status () { | |
[ -f /usr/local/etc/rc.d/startup-mounts.sh ] && /usr/local/etc/rc.d/startup-mounts.sh status | |
[ -f /usr/local/etc/rc.d/chroot-start-stop-status ] && /usr/local/etc/rc.d/chroot-start-stop-status status | |
chroot "${CHROOT}" "/bin/bash" -c "/etc/init.d/cron status" | |
chroot "${CHROOT}" "/bin/bash" -c "/etc/init.d/ssh status" | |
} | |
remove_logs() { | |
[ -f /root/synology-extra-config.*.log ] && rm -v "/root/synology-extra-config.*.log" | |
} | |
case "$1" in | |
start|"") | |
do_start | tee -a "${SYSTEM_LOG}" | |
;; | |
restart|reload|force-reload) | |
echo "Error: argument '$1' not supported" >&2 | |
exit 3 | |
;; | |
stop) | |
do_stop | tee -a "${SYSTEM_LOG}" | |
# remove_logs | |
;; | |
status) | |
do_status | tee -a "${SYSTEM_LOG}" | |
exit $? | |
;; | |
*) | |
echo "Usage: $0 [start|stop|status]" >&2 | |
exit 3 | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment