2024-05-05 06:16:56 +07:00
#!/usr/bin/env ash
#
2024-06-29 22:02:16 +07:00
# Copyright (C) 2023 AuxXxilium <https://github.com/AuxXxilium>
2024-05-05 06:16:56 +07:00
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
if [ " ${ 1 } " = "early" ] ; then
echo " Installing addon misc - ${ 1 } "
# [CREATE][failed] Raidtool initsys
SO_FILE = "/usr/syno/bin/scemd"
2024-11-09 01:34:54 +07:00
[ ! -f " ${ SO_FILE } .bak " ] && cp -pf " ${ SO_FILE } " " ${ SO_FILE } .bak "
2024-05-05 06:16:56 +07:00
cp -f " ${ SO_FILE } " " ${ SO_FILE } .tmp "
xxd -c $( xxd -p " ${ SO_FILE } .tmp " 2>/dev/null | wc -c) -p " ${ SO_FILE } .tmp " 2>/dev/null |
sed "s/2d6520302e39/2d6520312e32/" |
xxd -r -p >" ${ SO_FILE } " 2>/dev/null
rm -f " ${ SO_FILE } .tmp "
elif [ " ${ 1 } " = "rcExit" ] ; then
echo " Installing addon misc - ${ 1 } "
mkdir -p /usr/syno/web/webman
2024-07-03 01:33:36 +07:00
# Create: Cleanup Disk
2024-05-05 06:16:56 +07:00
cat >/usr/syno/web/webman/clean_system_disk.cgi <<EOF
#!/bin/sh
echo -ne "Content-type: text/plain; charset=\"UTF-8\"\r\n\r\n"
if [ -b /dev/md0 ] ; then
mkdir -p /mnt/md0
mount /dev/md0 /mnt/md0/
rm -rf /mnt/md0/@autoupdate/*
rm -rf /mnt/md0/upd@te/*
rm -rf /mnt/md0/.log.junior/*
umount /mnt/md0/
rm -rf /mnt/md0/
echo '{"success": true}'
else
echo '{"success": false}'
fi
EOF
chmod +x /usr/syno/web/webman/clean_system_disk.cgi
2024-07-03 01:33:36 +07:00
# Create: Reboot to Loader
2024-05-05 06:16:56 +07:00
cat >/usr/syno/web/webman/reboot_to_loader.cgi <<EOF
#!/bin/sh
echo -ne "Content-type: text/plain; charset=\"UTF-8\"\r\n\r\n"
if [ -f /usr/bin/loader-reboot.sh ] ; then
/usr/bin/loader-reboot.sh config
echo '{"success": true}'
else
echo '{"success": false}'
fi
EOF
chmod +x /usr/syno/web/webman/reboot_to_loader.cgi
2024-07-03 01:33:36 +07:00
# Get Boot Logs
2024-05-05 06:16:56 +07:00
cat >/usr/syno/web/webman/get_logs.cgi <<EOF
#!/bin/sh
echo -ne "Content-type: text/plain; charset=\"UTF-8\"\r\n\r\n"
echo "==== proc cmdline ===="
cat /proc/cmdline
echo "==== SynoBoot log ===="
cat /var/log/linuxrc.syno.log
echo "==== Installerlog ===="
cat /tmp/installer_sh.log
echo "==== Messages log ===="
cat /var/log/messages
EOF
chmod +x /usr/syno/web/webman/get_logs.cgi
2024-07-03 01:33:36 +07:00
# Error message if bootloader disk is not mounted
2024-05-05 06:16:56 +07:00
if [ ! -b /dev/synoboot ] || [ ! -b /dev/synoboot1 ] || [ ! -b /dev/synoboot2 ] || [ ! -b /dev/synoboot3 ] ; then
2024-06-29 22:02:16 +07:00
sed -i 's/c("welcome","desc_install")/"Error: The bootloader disk is not successfully mounted, the installation will fail."/' /usr/syno/web/main.js
2024-05-05 06:16:56 +07:00
fi
2024-07-03 01:33:36 +07:00
# Create: Recovery Mode
2024-05-05 06:16:56 +07:00
cat >/usr/syno/web/webman/recovery.cgi <<EOF
#!/bin/sh
echo -ne "Content-type: text/plain; charset=\"UTF-8\"\r\n\r\n"
echo "Starting ttyd ..."
MSG = ""
MSG = "\${MSG}Arc Recovery Mode\n"
2024-06-30 15:55:03 +07:00
MSG = "\${MSG}\n"
MSG = "\${MSG}Using terminal commands to modify system configs, execute external binary\n"
MSG = "\${MSG}files, add files, or install unauthorized third-party apps may lead to system\n"
MSG = "\${MSG}damages or unexpected behavior, or cause data loss. Make sure you are aware of\n"
MSG = "\${MSG}the consequences of each command and proceed at your own risk.\n"
MSG = "\${MSG}\n"
MSG = "\${MSG}Warning: Data should only be stored in shared folders. Data stored elsewhere\n"
MSG = "\${MSG}may be deleted when the system is updated/restarted.\n"
MSG = "\${MSG}\n"
2024-11-08 01:15:46 +07:00
MSG = "\${MSG}'System partition(/dev/md0) mounted to': /tmpRoot\n"
2024-05-05 06:16:56 +07:00
MSG = "\${MSG}To 'Force re-install DSM': http://<ip>:5000/web_install.html\n"
MSG = "\${MSG}To 'Reboot to Config Mode': http://<ip>:5000/webman/reboot_to_loader.cgi\n"
MSG = "\${MSG}To 'Show Boot Log': http://<ip>:5000/webman/get_logs.cgi\n"
MSG = "\${MSG}To 'Reboot Loader' : exec reboot\n"
2024-06-30 15:55:03 +07:00
echo -e "\${MSG}" > /etc/motd
2024-05-05 06:16:56 +07:00
/usr/bin/killall ttyd 2>/dev/null || true
2024-06-30 15:55:03 +07:00
/usr/sbin/ttyd -W -t titleFixed = "Arc Recovery" login -f root >/dev/null 2>& 1 &
2024-05-05 06:16:56 +07:00
echo "Starting dufs ..."
/usr/bin/killall dufs 2>/dev/null || true
/usr/sbin/dufs -A -p 7304 / >/dev/null 2>& 1 &
cp -f /usr/syno/web/web_index.html /usr/syno/web/web_install.html
cp -f /addons/web_index.html /usr/syno/web/web_index.html
2024-11-08 01:15:46 +07:00
mkdir -p /tmpRoot
mount /dev/md0 /tmpRoot
2024-06-30 15:55:03 +07:00
echo "Arc Recovery mode is ready"
2024-05-05 06:16:56 +07:00
EOF
chmod +x /usr/syno/web/webman/recovery.cgi
2024-07-03 01:33:36 +07:00
# Start: Recovery Mode
2024-05-05 06:16:56 +07:00
if [ -n " $( grep force_junior /proc/cmdline 2>/dev/null) " ] && [ -n " $( grep recovery /proc/cmdline 2>/dev/null) " ] ; then
/usr/syno/web/webman/recovery.cgi
fi
2024-06-25 01:14:36 +07:00
elif [ " ${ 1 } " = "patches" ] ; then
2024-08-17 03:18:23 +07:00
# Start getty
for I in $( cat /proc/cmdline 2>/dev/null | grep -oE 'getty=[^ ]+' | sed 's/getty=//' ) ; do
TTYN = " $( echo " ${ I } " | cut -d',' -f1) "
BAUD = " $( echo " ${ I } " | cut -d',' -f2 | cut -d'n' -f1) "
echo "ttyS0 ttyS1 ttyS2" | grep -qw " ${ TTYN } " && continue
if [ -n " ${ TTYN } " ] && [ -e " /dev/ ${ TTYN } " ] ; then
echo " Starting getty on ${ TTYN } "
if [ -n " ${ BAUD } " ] ; then
/usr/sbin/getty -L " ${ TTYN } " " ${ BAUD } " linux &
else
/usr/sbin/getty -L " ${ TTYN } " linux &
fi
fi
done
2024-07-03 01:33:36 +07:00
# Set static IP from cmdline
2024-06-25 01:14:36 +07:00
if grep -q 'network.' /proc/cmdline; then
2024-07-18 23:41:57 +07:00
for I in $( grep -oE 'network.[0-9a-fA-F:]{12,17}=[^ ]*' /proc/cmdline) ; do
2024-09-15 05:07:50 +07:00
MACR = " $( echo " ${ I } " | cut -d. -f2 | cut -d= -f1 | sed 's/://g; s/.*/\L&/' | tr '[:lower:]' '[:upper:]' ) "
2024-06-25 01:14:36 +07:00
IPRS = " $( echo " ${ I } " | cut -d= -f2) "
for ETH in $( ls /sys/class/net/ 2>/dev/null | grep eth) ; do
2024-09-07 17:38:32 +07:00
MACX = $( cat /sys/class/net/${ ETH } /address 2>/dev/null | sed 's/://g; s/.*/\L&/' | tr '[:lower:]' '[:upper:]' )
2024-06-25 01:14:36 +07:00
if [ " ${ MACR } " = " ${ MACX } " ] ; then
echo " Setting IP for ${ ETH } to ${ IPRS } "
mkdir -p /etc/sysconfig/network-scripts
echo " DEVICE= ${ ETH } " >/etc/sysconfig/network-scripts/ifcfg-${ ETH }
echo "BOOTPROTO=static" >>/etc/sysconfig/network-scripts/ifcfg-${ ETH }
echo "ONBOOT=yes" >>/etc/sysconfig/network-scripts/ifcfg-${ ETH }
echo " IPADDR= $( echo " ${ IPRS } " | cut -d/ -f1) " >>/etc/sysconfig/network-scripts/ifcfg-${ ETH }
echo " NETMASK= $( echo " ${ IPRS } " | cut -d/ -f2) " >>/etc/sysconfig/network-scripts/ifcfg-${ ETH }
echo " GATEWAY= $( echo " ${ IPRS } " | cut -d/ -f3) " >>/etc/sysconfig/network-scripts/ifcfg-${ ETH }
2024-07-18 23:41:57 +07:00
echo " ${ ETH } " >>/etc/ifcfgs
2024-06-25 01:14:36 +07:00
fi
done
done
fi
2024-05-05 06:16:56 +07:00
elif [ " ${ 1 } " = "late" ] ; then
echo " Installing addon misc - ${ 1 } "
echo "Killing ttyd ..."
/usr/bin/killall ttyd 2>/dev/null || true
echo "Killing dufs ..."
/usr/bin/killall dufs 2>/dev/null || true
mount -t sysfs sysfs /sys
modprobe acpi-cpufreq
2024-07-03 01:33:36 +07:00
# CPU Scaling Driver
2024-05-05 06:16:56 +07:00
if [ -f /tmpRoot/usr/lib/modules-load.d/70-cpufreq-kernel.conf ] ; then
2024-06-29 00:27:37 +07:00
CPUFREQ = $( ls -ltr /sys/devices/system/cpu/cpufreq/* 2>/dev/null | wc -l)
if [ ${ CPUFREQ } -eq 0 ] ; then
echo "CPU does NOT support CPU Performance Scaling, disabling"
sed -i 's/^acpi-cpufreq/# acpi-cpufreq/g' /tmpRoot/usr/lib/modules-load.d/70-cpufreq-kernel.conf
else
2024-05-05 06:16:56 +07:00
echo "CPU supports CPU Performance Scaling, enabling"
sed -i 's/^# acpi-cpufreq/acpi-cpufreq/g' /tmpRoot/usr/lib/modules-load.d/70-cpufreq-kernel.conf
2024-11-09 01:34:54 +07:00
cp -pf /usr/lib/modules/cpufreq_* /tmpRoot/usr/lib/modules/
2024-05-05 06:16:56 +07:00
fi
fi
2024-08-02 23:59:16 +07:00
modprobe -r acpi-cpufreq
2024-05-05 06:16:56 +07:00
umount /sys
2024-07-03 01:33:36 +07:00
# CPU Crypto Support Check
2024-05-05 06:16:56 +07:00
if [ -f /tmpRoot/usr/lib/modules-load.d/70-crypto-kernel.conf ] ; then
CPUFLAGS = $( cat /proc/cpuinfo 2>/dev/null | grep flags | grep sse4_2 | wc -l)
if [ ${ CPUFLAGS } -gt 0 ] ; then
echo "CPU Supports SSE4.2, crc32c-intel should load"
else
echo "CPU does NOT support SSE4.2, crc32c-intel will not load, disabling"
sed -i 's/^crc32c-intel/# crc32c-intel/g' /tmpRoot/usr/lib/modules-load.d/70-crypto-kernel.conf
fi
CPUFLAGS = $( cat /proc/cpuinfo 2>/dev/null | grep flags | grep aes | wc -l)
if [ ${ CPUFLAGS } -gt 0 ] ; then
echo "CPU Supports AES, aesni-intel should load"
else
echo "CPU does NOT support AES, aesni-intel will not load, disabling"
2024-08-17 03:18:23 +07:00
sed -i 's/support_aesni_intel="yes"/support_aesni_intel="no"/' /tmpRoot/etc/synoinfo.conf /tmpRoot/etc.defaults/synoinfo.conf
2024-05-05 06:16:56 +07:00
sed -i 's/^aesni-intel/# aesni-intel/g' /tmpRoot/usr/lib/modules-load.d/70-crypto-kernel.conf
fi
fi
2024-07-03 01:33:36 +07:00
# Nvidia GPU Check
2024-05-05 06:16:56 +07:00
if [ -f /tmpRoot/usr/lib/modules-load.d/70-syno-nvidia-gpu.conf ] ; then
NVIDIADEV = $( cat /proc/bus/pci/devices 2>/dev/null | grep -i 10de | wc -l)
if [ ${ NVIDIADEV } -eq 0 ] ; then
echo "NVIDIA GPU is not detected, disabling "
sed -i 's/^nvidia/# nvidia/g' /tmpRoot/usr/lib/modules-load.d/70-syno-nvidia-gpu.conf
sed -i 's/^nvidia-uvm/# nvidia-uvm/g' /tmpRoot/usr/lib/modules-load.d/70-syno-nvidia-gpu.conf
else
echo "NVIDIA GPU is detected, nothing to do"
fi
fi
2024-07-18 23:41:57 +07:00
# service
SERVICE_PATH = "/tmpRoot/usr/lib/systemd/system"
2024-08-24 00:40:58 +07:00
sed -i 's|ExecStart=/|ExecStart=/|g' ${ SERVICE_PATH } /syno-oob-check-status.service ${ SERVICE_PATH } /SynoInitEth.service ${ SERVICE_PATH } /syno_update_disk_logs.service
2024-09-07 17:38:32 +07:00
2024-07-18 23:41:57 +07:00
# getty
for I in $( cat /proc/cmdline 2>/dev/null | grep -oE 'getty=[^ ]+' | sed 's/getty=//' ) ; do
TTYN = " $( echo " ${ I } " | cut -d',' -f1) "
BAUD = " $( echo " ${ I } " | cut -d',' -f2 | cut -d'n' -f1) "
echo "ttyS0 ttyS1 ttyS2" | grep -qw " ${ TTYN } " && continue
mkdir -vp /tmpRoot/usr/lib/systemd/system/getty.target.wants
if [ -n " ${ TTYN } " ] && [ -e " /dev/ ${ TTYN } " ] ; then
echo " Make getty\@ ${ TTYN } .service "
2024-08-11 04:51:53 +07:00
cp -fv /tmpRoot/usr/lib/systemd/system/serial-getty\@ .service /tmpRoot/usr/lib/systemd/system/getty\@ ${ TTYN } .service
2024-08-24 00:40:58 +07:00
sed -i " s|^ExecStart=.*|ExecStart=/sbin/agetty %I ${ BAUD :- 115200 } linux| " /tmpRoot/usr/lib/systemd/system/getty\@ ${ TTYN } .service
2024-08-11 04:51:53 +07:00
mkdir -vp /tmpRoot/usr/lib/systemd/system/getty.target.wants
ln -vsf /usr/lib/systemd/system/getty\@ ${ TTYN } .service /tmpRoot/usr/lib/systemd/system/getty.target.wants/getty\@ ${ TTYN } .service
2024-07-18 23:41:57 +07:00
fi
done
2024-07-03 01:33:36 +07:00
# Open-VM-Tools Fix
2024-05-05 06:16:56 +07:00
if [ -d /tmpRoot/var/packages/open-vm-tools ] ; then
sed -i 's/package/root/g' /tmpRoot/var/packages/open-vm-tools/conf/privilege
fi
2024-07-03 01:33:36 +07:00
# Qemu-Guest-Agent Fix
2024-05-05 06:16:56 +07:00
if [ -d /tmpRoot/var/packages/qemu-ga ] ; then
sed -i 's/package/root/g' /tmpRoot/var/packages/qemu-ga/conf/privilege
fi
2024-07-03 01:33:36 +07:00
# SD Card
2024-10-03 00:51:19 +07:00
[ ! -f /tmpRoot/usr/lib/udev/script/sdcard.sh.bak ] && cp -f /tmpRoot/usr/lib/udev/script/sdcard.sh /tmpRoot/usr/lib/udev/script/sdcard.sh.bak
2024-06-29 22:02:16 +07:00
echo -en '#!/bin/sh\nexit 0\n' >/tmpRoot/usr/lib/udev/script/sdcard.sh
2024-05-28 00:37:00 +07:00
2024-07-03 01:33:36 +07:00
# Network Init
2024-05-05 06:16:56 +07:00
rm -vf /tmpRoot/usr/lib/modules-load.d/70-network*.conf
2024-06-25 01:14:36 +07:00
mkdir -p /tmpRoot/etc/sysconfig/network-scripts
mkdir -p /tmpRoot/etc.defaults/sysconfig/network-scripts
for I in $( ls /etc/sysconfig/network-scripts/ifcfg-eth*) ; do
2024-11-09 01:34:54 +07:00
[ ! -f " /tmpRoot/ ${ I } " ] && cp -pf " ${ I } " " /tmpRoot/ ${ I } "
[ ! -f " /tmpRoot/ ${ I /etc/etc.defaults } " ] && cp -pf " ${ I } " " /tmpRoot/ ${ I /etc/etc.defaults } "
2024-05-05 06:16:56 +07:00
done
2024-06-25 01:14:36 +07:00
if grep -q 'network.' /proc/cmdline && [ -f "/etc/ifcfgs" ] ; then
for ETH in $( cat /etc/ifcfgs) ; do
echo " Copy ifcfg- ${ ETH } "
if [ -f " /etc/sysconfig/network-scripts/ifcfg- ${ ETH } " ] ; then
2024-09-07 17:38:32 +07:00
rm -vf /tmpRoot/etc/sysconfig/network-scripts/ifcfg-* /tmpRoot/etc.defaults/sysconfig/network-scripts/ifcfg-*
2024-11-09 01:34:54 +07:00
cp -pf /etc/sysconfig/network-scripts/ifcfg-${ ETH } /tmpRoot/etc/sysconfig/network-scripts/
cp -pf /etc/sysconfig/network-scripts/ifcfg-${ ETH } /tmpRoot/etc.defaults/sysconfig/network-scripts/
2024-06-25 01:14:36 +07:00
fi
done
fi
2024-05-05 06:16:56 +07:00
2024-07-12 23:41:37 +07:00
# syslog-ng
if [ -f /tmpRoot/etc.defaults/syslog-ng/patterndb.d/scemd.conf ] ; then
2024-11-09 01:34:54 +07:00
cp -pfp /tmpRoot/etc.defaults/syslog-ng/patterndb.d/scemd.conf /tmpRoot/etc.defaults/syslog-ng/patterndb.d/scemd.conf.bak
2024-07-12 23:41:37 +07:00
sed -i 's/destination(d_scemd)/flags(final)/g' /tmpRoot/etc.defaults/syslog-ng/patterndb.d/scemd.conf
else
echo "scemd.conf does not exist."
fi
if [ -f /tmpRoot/etc.defaults/syslog-ng/patterndb.d/synosystemd.conf ] ; then
2024-11-09 01:34:54 +07:00
cp -pfp /tmpRoot/etc.defaults/syslog-ng/patterndb.d/synosystemd.conf /tmpRoot/etc.defaults/syslog-ng/patterndb.d/synosystemd.conf.bak
2024-07-12 23:41:37 +07:00
sed -i 's/destination(d_synosystemd)/flags(final)/g; s/destination(d_systemd)/flags(final)/g' /tmpRoot/etc.defaults/syslog-ng/patterndb.d/synosystemd.conf
else
echo "synosystemd.conf does not exist."
fi
2024-07-03 01:33:36 +07:00
# Community Packages
2024-05-05 06:16:56 +07:00
if [ ! -f /tmpRoot/usr/syno/etc/packages/feeds ] ; then
mkdir -p /tmpRoot/usr/syno/etc/packages
2024-06-15 15:52:59 +07:00
echo '[{"feed":"https://spk7.imnks.com","name":"imnks"},{"feed":"https://packages.synocommunity.com","name":"synocommunity"}]' >/tmpRoot/usr/syno/etc/packages/feeds
2024-05-05 06:16:56 +07:00
fi
2024-07-03 01:33:36 +07:00
# Copy Loader Reboot
2024-11-09 01:34:54 +07:00
cp -pf /usr/bin/loader-reboot.sh /tmpRoot/usr/bin/loader-reboot.sh
cp -pf /usr/bin/grub-editenv /tmpRoot/usr/bin/grub-editenv
2024-06-29 22:02:16 +07:00
fi