fix something

This commit is contained in:
Ing 2024-03-08 00:50:05 +08:00
parent 6b65130c3f
commit fce0e76221
17 changed files with 2349 additions and 2113 deletions

View File

@ -171,35 +171,34 @@ echo -e "$(TEXT "Cmdline:\n")\033[1;36m${CMDLINE_LINE}\033[0m"
DIRECT="$(readConfigKey "directboot" "${USER_CONFIG_FILE}")"
if [ "${DIRECT}" = "true" ]; then
CMDLINE_DIRECT=$(echo ${CMDLINE_LINE} | sed 's/>/\\\\>/g') # Escape special chars
grub-editenv ${GRUB_PATH}/grubenv set dsm_cmdline="${CMDLINE_DIRECT}"
grub-editenv ${USER_GRUBENVFILE} set dsm_cmdline="${CMDLINE_DIRECT}"
echo -e "\033[1;33m$(TEXT "Reboot to boot directly in DSM")\033[0m"
grub-editenv ${GRUB_PATH}/grubenv set next_entry="direct"
grub-editenv ${USER_GRUBENVFILE} set next_entry="direct"
reboot
exit 0
else
ETHX=$(ls /sys/class/net/ 2>/dev/null | grep -v lo) || true
echo "$(printf "$(TEXT "Detected %s network cards.")" "$(echo ${ETHX} | wc -w)")"
echo "$(TEXT "Checking Connect.")"
echo -en "$(TEXT "Checking Connect.")"
COUNT=0
BOOTIPWAIT="$(readConfigKey "bootipwait" "${USER_CONFIG_FILE}")"
[ -z "${BOOTIPWAIT}" ] && BOOTIPWAIT=10
while [ ${COUNT} -lt $((${BOOTIPWAIT} + 32)) ]; do
hasConnect="false"
MSG=""
for N in ${ETHX}; do
if ethtool ${N} 2>/dev/null | grep 'Link detected' | grep -q 'yes'; then
echo -en "${N} "
hasConnect="true"
MSG+="${N} "
fi
done
if [ ${hasConnect} = "true" ]; then
echo -en "connected.\n"
if [ -n "${MSG}" ]; then
echo -en "\r${MSG}$(TEXT "connected.")\n"
break
fi
COUNT=$((${COUNT} + 1))
echo -n "."
sleep 1
done
echo "$(TEXT "Waiting IP.(For reference only)")"
echo "$(TEXT "Waiting IP.")"
for N in ${ETHX}; do
COUNT=0
DRIVER=$(ls -ld /sys/class/net/${N}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')

View File

@ -13,8 +13,10 @@ UNTAR_PAT_PATH="${TMP_PATH}/pat"
RAMDISK_PATH="${TMP_PATH}/ramdisk"
LOG_FILE="${TMP_PATH}/log.txt"
USER_GRUB_CONFIG="${PART1_PATH}/boot/grub/grub.cfg"
USER_GRUBENVFILE="${PART1_PATH}/boot/grub/grubenv"
USER_CONFIG_FILE="${PART1_PATH}/user-config.yml"
GRUB_PATH="${PART1_PATH}/boot/grub"
USER_LOCALE_FILE="${PART1_PATH}/.locale"
ORI_ZIMAGE_FILE="${PART2_PATH}/zImage"
ORI_RDGZ_FILE="${PART2_PATH}/rd.gz"

View File

@ -201,10 +201,13 @@ function _get_fastest() {
local speedlist=""
for I in $@; do
speed=$(ping -c 1 -W 5 ${I} 2>/dev/null | awk '/time=/ {print $7}' | cut -d '=' -f 2)
speedlist+="${I} ${speed:-999}\n"
speedlist+="${I} ${speed:-999}\n" # Assign default value 999 if speed is empty
done
fastest="$(echo -e "${speedlist}" | tr -s '\n' | sort -k2n | head -1 | awk '{print $1}')"
echo "${fastest}"
fastest="$(echo -e "${speedlist}" | tr -s '\n' | sort -k2n | head -1)"
URL="$(echo "${fastest}" | awk '{print $1}')"
SPD="$(echo "${fastest}" | awk '{print $2}')"
echo "${URL}"
[ ${SPD:-999} -ge 999 ] && return 1 || return 0
}
###############################################################################
@ -295,10 +298,10 @@ function getIP() {
IP=""
if [ -n "${1}" -a -d "/sys/class/net/${1}" ]; then
IP=$(ip route show dev ${1} 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p')
[ -z "${IP}" ] && IP=$(ip addr show ${1} 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -f1 -d'/' | head -1)
[ -z "${IP}" ] && IP=$(ip addr show ${1} scope global 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -f1 -d'/' | head -1)
else
IP=$(ip route show 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p' | head -1)
[ -z "${IP}" ] && IP=$(ip addr show 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -f1 -d'/' | head -1)
[ -z "${IP}" ] && IP=$(ip addr show scope global 2>/dev/null | grep -E "inet .* eth" | awk '{print $2}' | cut -f1 -d'/' | head -1)
fi
echo "${IP}"
}
@ -310,12 +313,17 @@ function getLogo() {
MODEL="${1}"
rm -f "${PART3_PATH}/logo.png"
fastest=$(_get_fastest "www.synology.com" "www.synology.cn")
STATUS=$(curl -skL --connect-timeout 10 -w "%{http_code}" "https://${fastest}/api/products/getPhoto?product=${MODEL/+/%2B}&type=img_s&sort=0" -o "${PART3_PATH}/logo.png")
if [ $? -ne 0 -o ${STATUS:-0} -ne 200 -o -f "${PART3_PATH}/logo.png" ]; then
convert -rotate 180 "${PART3_PATH}/logo.png" "${PART3_PATH}/logo.png" 2>/dev/null
magick montage "${PART3_PATH}/logo.png" -background 'none' -tile '3x3' -geometry '350x210' "${PART3_PATH}/logo.png" 2>/dev/null
convert -rotate 180 "${PART3_PATH}/logo.png" "${PART3_PATH}/logo.png" 2>/dev/null
if [ $? -ne 0 ]; then
return 1
fi
STATUS=$(curl -skL --connect-timeout 10 -w "%{http_code}" "https://${fastest}/api/products/getPhoto?product=${MODEL/+/%2B}&type=img_s&sort=0" -o "${PART3_PATH}/logo.png")
if [ $? -ne 0 -o ${STATUS:-0} -ne 200 -o ! -f "${PART3_PATH}/logo.png" ]; then
return 1
fi
convert -rotate 180 "${PART3_PATH}/logo.png" "${PART3_PATH}/logo.png" 2>/dev/null
magick montage "${PART3_PATH}/logo.png" -background 'none' -tile '3x3' -geometry '350x210' "${PART3_PATH}/logo.png" 2>/dev/null
convert -rotate 180 "${PART3_PATH}/logo.png" "${PART3_PATH}/logo.png" 2>/dev/null
return 0
}
###############################################################################

View File

@ -77,11 +77,13 @@ done
# Get the VID/PID if we are in USB
VID="0x46f4"
PID="0x0001"
TYPE="DoM"
BUS=$(getBus "${LOADER_DISK}")
if [ "${BUS}" = "usb" ]; then
VID="0x$(udevadm info --query property --name ${LOADER_DISK} 2>/dev/null | grep ID_VENDOR_ID | cut -d= -f2)"
PID="0x$(udevadm info --query property --name ${LOADER_DISK} 2>/dev/null | grep ID_MODEL_ID | cut -d= -f2)"
TYPE="flashdisk"
elif [ "${BUS}" != "sata" -a "${BUS}" != "scsi" -a "${BUS}" != "nvme" -a "${BUS}" != "mmc" ]; then
die "$(TEXT "Loader disk neither USB or SATA/SCSI/NVME/MMC DoM")"
fi
@ -91,7 +93,7 @@ writeConfigKey "vid" ${VID} "${USER_CONFIG_FILE}"
writeConfigKey "pid" ${PID} "${USER_CONFIG_FILE}"
# Inform user
echo -e "$(TEXT "Loader disk:") \033[1;32m${LOADER_DISK}\033[0m (\033[1;32m${BUS^^} flashdisk\033[0m)"
echo -e "$(TEXT "Loader disk:") \033[1;32m${LOADER_DISK}\033[0m (\033[1;32m${BUS^^} ${TYPE}\033[0m)"
# Load keymap name
LAYOUT="$(readConfigKey "layout" "${USER_CONFIG_FILE}")"
@ -120,18 +122,17 @@ fi
# Wait for an IP
echo "$(printf "$(TEXT "Detected %s network cards.")" "$(echo ${ETHX} | wc -w)")"
echo "$(TEXT "Checking Connect.")"
echo -en "$(TEXT "Checking Connect.")"
COUNT=0
while [ ${COUNT} -lt 30 ]; do
hasConnect="false"
MSG=""
for N in ${ETHX}; do
if ethtool ${N} 2>/dev/null | grep 'Link detected' | grep -q 'yes'; then
echo -en "${N} "
hasConnect="true"
MSG+="${N} "
fi
done
if [ "${hasConnect}" = "true" ]; then
echo -en "connected.\n"
if [ -n "${MSG}" ]; then
echo -en "\r${MSG}$(TEXT "connected.")\n"
break
fi
COUNT=$((${COUNT} + 1))
@ -176,7 +177,7 @@ echo -e "$(TEXT "TTYD: \033[1;34mhttp://rr:7681/\033[0m")"
echo -e "$(TEXT "DUFS: \033[1;34mhttp://rr:7304/\033[0m")"
echo -e "$(TEXT "TTYD&DUFS: \033[1;34mhttp://rr:80/\033[0m")"
echo
echo -e "$(TEXT "Default SSH Root password is") \033[1;31mrr\033[0m"
echo -e "$(TEXT "Default SSH \033[1;31mroot\033[0m password is") \033[1;31mrr\033[0m"
echo
DSMLOGO="$(readConfigKey "dsmlogo" "${USER_CONFIG_FILE}")"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -258,8 +258,13 @@ function productversMenu() {
DIALOG --title "$(TEXT "Product Version")" \
--infobox "$(TEXT "Get pat data ...")" 0 0
idx=0
NETERR=0
while [ ${idx} -le 3 ]; do # Loop 3 times, if successful, break
fastest=$(_get_fastest "www.synology.com" "www.synology.cn")
if [ $? -ne 0 ]; then
NETERR=1
continue
fi
[ "${fastest}" = "www.synology.cn" ] &&
fastest="https://www.synology.cn/api/support/findDownloadInfo?lang=zh-cn" ||
fastest="https://www.synology.com/api/support/findDownloadInfo?lang=en-us"
@ -275,11 +280,17 @@ function productversMenu() {
idx=$((${idx} + 1))
done
if [ -z "${paturl}" -o -z "${patsum}" ]; then
MSG="$(TEXT "Failed to get pat data,\nPlease manually fill in the URL and md5sum of the corresponding version of pat.")"
if [ ${NETERR} -ne 0 ]; then
MSG=""
MSG+="$(TEXT "Network error, please check the network connection and try again.")"
MSG+="\n$(TEXT "Or use 'Parse pat' function for installation.")"
else
MSG="$(TEXT "Failed to get pat data,\nPlease manually fill in the URL and md5sum of the corresponding version of pat.\nOr click 'Retry'.")"
fi
paturl=""
patsum=""
else
MSG="$(TEXT "Successfully to get pat data,\nPlease confirm or modify as needed.")"
MSG="$(TEXT "Successfully to get pat data, Please confirm.\nOr modify the URL and md5sum to you need.")"
fi
DIALOG --title "$(TEXT "Product Version")" \
--extra-button --extra-label "$(TEXT "Retry")" \
@ -342,11 +353,11 @@ function ParsePat() {
[ $? -ne 0 ] && return
fi
PAT_PATH=""
ITEMS="$(ls ${USER_UP_PATH}/*.pat 2>/dev/null)"
ITEMS="$(ls ${TMP_PATH}/pats/*.pat 2>/dev/null)"
if [ -z "${ITEMS}" ]; then
MSG=""
MSG+="$(TEXT "No pat file found in users folder!\n")"
MSG+="$(TEXT "Please upload the pat file to /mnt/p3/users/ folder via DUFS and re-enter this option.\n")"
MSG+="$(TEXT "No pat file found in /tmp/pats/ folder!\n")"
MSG+="$(TEXT "Please upload the pat file to /tmp/pats/ folder via DUFS and re-enter this option.\n")"
DIALOG --title "$(TEXT "Update")" \
--msgbox "${MSG}" 0 0
return
@ -1018,6 +1029,11 @@ function getSynoExtractor() {
MKERR_FILE="${TMP_PATH}/makeerror.log"
mirrors=("global.synologydownload.com" "global.download.synology.com" "cndl.synology.cn")
fastest=$(_get_fastest ${mirrors[@]})
if [ $? -ne 0 ]; then
MSG="$(TEXT "Network error, please check the network connection and try again.")"
echo -e "${MSG}" >"${MKERR_FILE}"
return 1
fi
OLDPAT_URL="https://${fastest}/download/DSM/release/7.0.1/42218/DSM_DS3622xs%2B_42218.pat"
OLDPAT_PATH="${TMP_PATH}/DS3622xs+-42218.pat"
EXTRACTOR_PATH="${PART3_PATH}/extractor"
@ -1149,6 +1165,11 @@ function extractDsmFiles() {
mkdir -p "${PART3_PATH}/dl"
mirrors=("global.synologydownload.com" "global.download.synology.com" "cndl.synology.cn")
fastest=$(_get_fastest ${mirrors[@]})
if [ $? -ne 0 ]; then
MSG="$(TEXT "Network error, please check the network connection and try again.")"
echo -e "${MSG}" >"${MKERR_FILE}"
return 1
fi
mirror="$(echo ${PATURL} | sed 's|^http[s]*://\([^/]*\).*|\1|')"
if echo "${mirrors[@]}" | grep -wq "${mirror}" && [ "${mirror}" != "${fastest}" ]; then
echo "$(printf "$(TEXT "Based on the current network situation, switch to %s mirror to downloading.")" "${fastest}")"
@ -2162,10 +2183,10 @@ function editUserConfig() {
function editGrubCfg() {
while true; do
DIALOG --title "$(TEXT "Edit with caution")" \
--editbox "${GRUB_PATH}/grub.cfg" 0 0 2>"${TMP_PATH}/usergrub.cfg"
--editbox "${USER_GRUB_CONFIG}" 0 0 2>"${TMP_PATH}/usergrub.cfg"
[ $? -ne 0 ] && return
mv -f "${TMP_PATH}/usergrub.cfg" "${GRUB_PATH}/grub.cfg"
dos2unix "${GRUB_PATH}/grub.cfg"
mv -f "${TMP_PATH}/usergrub.cfg" "${USER_GRUB_CONFIG}"
dos2unix "${USER_GRUB_CONFIG}"
break
done
}

View File

@ -198,6 +198,26 @@ else
cp -f "${WORK_PATH}/patch/modulelist" "${RAMDISK_PATH}/addons/modulelist"
fi
# backup current loader configs
BACKUP_PATH="${RAMDISK_PATH}/usr/rr/backup"
rm -rf "${BACKUP_PATH}"
for F in "${USER_GRUB_CONFIG}" "${USER_CONFIG_FILE}" "${USER_LOCALE_FILE}" "${USER_UP_PATH}" "${SCRIPTS_PATH}"; do
if [ -f "${F}" ]; then
FD="$(dirname "${F}")"
mkdir -p "${FD/\/mnt/${BACKUP_PATH}}"
cp -f "${F}" "${FD/\/mnt/${BACKUP_PATH}}"
elif [ -d "${F}" ]; then
SIZE="$(du -sm "${F}" 2>/dev/null | awk '{print $1}')"
if [ ${SIZE:-0} -gt 4 ]; then
echo "Backup of ${F} skipped, size is ${SIZE}MB" >>"${LOG_FILE}" 2>&1
continue
fi
FD="$(dirname "${F}")"
mkdir -p "${FD/\/mnt/${BACKUP_PATH}}"
cp -rf "${F}" "${FD/\/mnt/${BACKUP_PATH}}"
fi
done
# Network card configuration file
for N in $(seq 0 7); do
echo -e "DEVICE=eth${N}\nBOOTPROTO=dhcp\nONBOOT=yes\nIPV6INIT=dhcp\nIPV6_ACCEPT_RA=1" >"${RAMDISK_PATH}/etc/sysconfig/network-scripts/ifcfg-eth${N}"