commit 9336502f682bf64fd83422ecf4a5c588df7f3ad8 Author: Bruno21 Date: Fri Jan 3 07:39:33 2025 +0100 1st commit diff --git a/certifs_info.sh b/certifs_info.sh new file mode 100755 index 0000000..e7744e1 --- /dev/null +++ b/certifs_info.sh @@ -0,0 +1,193 @@ +#!/usr/bin/env bash + +redbold="\033[1;31m" +red="\033[0;31m" +greenbold="\033[1;32m" +green="\033[0;32m" +yellowbold="\033[1;33m" +yellow="\033[0;33m" +bold="\033[1m" +#bold_under="\033[1;4m" +italic="\033[3m" +underline="\033[4m" +reset="\033[0m" + +# Requierements: +# - script must run with sudo +# - jq 1.7.1 mini (/bin/jq = 1.5 (dsm 7.2.2); /opt/bin/jq = 1.7.1 (opkg)) + +if [[ $EUID -ne 0 ]]; then + echo "$0 is not running as root. Try using sudo." + exit 2 +fi + +dsm=$(cat /etc.defaults/VERSION) +build=$(echo "$dsm" | grep buildnumber | awk -F"=" '{print $2}') +os=$(echo "$dsm" | grep os_name | awk -F"=" '{print $2}') +version=$(echo "$dsm" | grep productversion | awk -F"=" '{print $2}') +information="${os//\"/} ${version//\"/} build ${build//\"/}" +echo -e "$information" + # Supprimer les "" + #display_name="${display_name//\"/}" + + +vers_jq=$(jq -V | awk -F"-" '{print $2}') +echo -e "jq version ${vers_jq}\n" + +# GNU sort +version_greater_equal() { + printf '%s\n%s\n' "$2" "$1" | sort --check=quiet --version-sort +} + +version_greater_equal "${vers_jq}" 1.7.1 || { echo -e "Need ${italic}jq v1.7.1${reset} or above !"; echo -e "Maybe you should use ${italic}opkg install jq${reset}"; exit 1; } + + +certifs_archive=/usr/syno/etc/certificate/_archive +#certifs_archive=/Users/bruno/Downloads + +#services="$certifs_archive/SERVICES" +#[ -f "$services" ] && ser=$(cat "$services") || { echo -e "${red}No $services file found !${reset}"; exit 1; } + +info="$certifs_archive/INFO" +[ -f "$info" ] && inf=$(cat "$info") || { echo -e "${red}No $info file found !${reset}"; exit 1; } + +default="$certifs_archive/DEFAULT" +[ -f "$default" ] && def=$(cat "$default") || { echo -e "${red}No $default file found !${reset}"; exit 1; } + +rp=() +ap=() +ot=() + +echo -e "${greenbold}Reading $info${reset}\n" + + +echo -e "${yellow}Certificates's list...${reset}\n" + +liste_cert=$(echo "$inf" | jq -r 'keys[]') + +printf "| ${bold}%-7s${reset} | ${bold}%-53s${reset} | ${bold}%-25s${reset} \n" "Certif." "Description" "Date limite" + +while read certif; do + + filter=".$certif" + desc=$(echo "$inf" | jq -r $filter | jq -r '.desc') + + ssl=$(openssl x509 -enddate -subject -noout -in $certifs_archive/$certif/cert.pem) + notafter=$(echo "$ssl" | grep notAfter | awk -F"=" '{print $2}') + subject=$(echo "$ssl" | grep subject | awk -F"=" '{print $1}') + + timestamp_current=$(date +"%s") + timestamp_end=$(date --date="$notafter" +"%s") + left=$(($((timestamp_end - timestamp_current))/(60*60*24))) + end="$notafter ($left days left)" + + [ "$certif" == "$def" ] && printf "| ${green}%-7s${reset} | ${green}%-53s${reset} | ${green}%-25s${reset} \n" "$certif" "$desc" "$end (default)" || printf "| %-7s | %-53s | %-25s \n" "$certif" "$desc" "$end" + + + if [ "$certif" == "$def" ]; then + echo + ls -ld "$certifs_archive/$def"/* + # ls -ld * .* + echo + echo -e "${italic}cert.pem${reset} est le certificat de l'utilisateur final." + echo -e "${italic}chain.pem${reset} est le reste de la chaîne. Il s'agit uniquement du certificat racine de LetsEncrypt." + echo -e "${italic}fullchain.pem${reset} est cert.pem et chain.pem combinés." + echo -e "${italic}privkey.pem${reset} est une clé privée RSA générée avec le certificat." + fi + +done <<< "$liste_cert" + + +echo -e "\n\n${yellow}Certificates and Subscriber...${reset}\n" + +while read certif; do + + filter=".$certif" + desc=$(echo "$inf" | jq -r $filter | jq -r '.desc') + + printf "| ${yellowbold}%-7s${reset} | ${yellowbold}%-60s${reset} \n" "Certif." "Description" + printf "| ${yellowbold}%-7s${reset} | ${yellowbold}%-60s${reset} \n\n" "$certif" "$desc" # ok + + serv=$(echo "$inf" | jq -r $filter | jq -r '.services[]') + + + printf "|${bold} %-40s ${reset}|${bold} %-20s ${reset}|${bold} %-60s ${reset}\n" "Display_name" "Subscriber" "Service" + + while read line; do + + display_name=$(echo "$line" | jq -r '.display_name') + service=$(echo "$line" | jq -r '.service') + subscriber=$(echo "$line" | jq -r '.subscriber') + + #echo "$display_name" + #echo "$service" + #echo "$subscriber" + + printf "| %-40s | %-20s | %-60s \n" "$display_name" "$subscriber" "$service" + + + if [[ "$subscriber" == *ReverseProxy* ]]; then + rp+=("$display_name") + elif [[ "$subscriber" == *AppPortal* ]]; then + if [[ "$display_name" == *photos-nas.ovh* ]]; then + a=$(echo "$display_name" | awk -F" - " '{print $1}' | xargs) + b=$(echo "$display_name" | awk -F" - " '{print $2}' | xargs) + ap+=("$a") + rp+=("$b") + fi + else + if [[ "$display_name" == *photos-nas.ovh* ]]; then + if [[ "$display_name" =~ :[0-9]{1,5}$ ]]; then + c=$(echo "$display_name" | awk -F":" '{print $1}') + rp+=("$c") + else + rp+=("$display_name") + fi + else + ot+=("$display_name") + fi + fi + + + done < <(jq -c <<< "$serv") + + echo -e "\n\n" + +done <<< "$liste_cert" + + +echo -e "\n\n" + +IFS=$'\n' +reverseproxy=($(sort <<<"${rp[*]}")) +appportal=($(sort <<<"${ap[*]}")) +others=($(sort <<<"${ot[*]}")) +unset IFS + +printf "| %-3s | ${bold}%-60s${reset} \n" "" "Reverse Proxy" +i=1 +for val in ${!reverseproxy[@]} +do + printf "| %-3s | %-60s \n" "$i" "${reverseproxy[$val]}" + ((i++)) +done +echo -e "${italic}${#reverseproxy[@]} lines${reset}\n" + +printf "| %-3s | ${bold}%-60s${reset} \n" "" "AppPortal" +i=1 +for val in ${!appportal[@]} +do + printf "| %-3s | %-60s \n" "$i" "${appportal[$val]}" + ((i++)) +done +echo -e "${italic}${#appportal[@]} lines${reset}\n" + +printf "| %-3s | ${bold}%-60s${reset} \n" "" "Others" +i=1 +for val in ${!others[@]} +do + printf "| %-3s | %-60s \n" "$i" "${others[$val]}" + ((i++)) +done +echo -e "${italic}${#others[@]} lines${reset}\n" + diff --git a/certifs_services.sh b/certifs_services.sh new file mode 100755 index 0000000..21e38e6 --- /dev/null +++ b/certifs_services.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash + +red="\033[1;31m" +greenbold="\033[1;32m" +green="\033[0;32m" +yellow="\033[0;33m" +bold="\033[1m" +#bold_under="\033[1;4m" +italic="\033[3m" +underline="\033[4m" +reset="\033[0m" + + +services=/Users/bruno/Downloads/SERVICES +info=/Users/bruno/Downloads/INFO + +ser=$(cat "$services") +inf=$(cat "$info") + +rp=() +ap=() +ot=() + +echo -e "${greenbold}Reading $services${reset}\n" + +printf "|${bold} %-40s ${reset}|${bold} %-20s ${reset}|${bold} %-60s ${reset}\n" "Display_name" "Subscriber" "Service" + +while read line; do + display_name=$(echo "$line" | jq -r '.display_name') + subscriber=$(echo "$line" | jq -r '.subscriber') + service=$(echo "$line" | jq -r '.service') + + # Supprimer les "" + #display_name="${display_name//\"/}" + + printf "| %-40s | %-20s | %-60s \n" "$display_name" "$subscriber" "$service" + + if [[ "$subscriber" == *ReverseProxy* ]]; then + rp+=("$display_name") + elif [[ "$subscriber" == *AppPortal* ]]; then + if [[ "$display_name" == *photos-nas.ovh* ]]; then + a=$(echo "$display_name" | awk -F" - " '{print $1}' | xargs) + b=$(echo "$display_name" | awk -F" - " '{print $2}' | xargs) + ap+=("$a") + rp+=("$b") + fi + else + if [[ "$display_name" == *photos-nas.ovh* ]]; then + if [[ "$display_name" =~ :[0-9]{1,5}$ ]]; then + c=$(echo "$display_name" | awk -F":" '{print $1}') + rp+=("$c") + else + rp+=("$display_name") + fi + else + ot+=("$display_name") + fi + fi + +done < <(jq -c '.[]' <<< "$ser") + +echo -e "\n\n" + +IFS=$'\n' +reverseproxy=($(sort <<<"${rp[*]}")) +appportal=($(sort <<<"${ap[*]}")) +others=($(sort <<<"${ot[*]}")) +unset IFS + + +printf "| %-3s | ${bold}%-60s${reset} \n" "" "Reverse Proxy" +i=1 +for val in ${!reverseproxy[@]} +do + printf "| %-3s | %-60s \n" "$i" "${reverseproxy[$val]}" + ((i++)) +done +echo -e "${italic}${#reverseproxy[@]} lines${reset}\n" + +printf "| %-3s | ${bold}%-60s${reset} \n" "" "AppPortal" +i=1 +for val in ${!appportal[@]} +do + printf "| %-3s | %-60s \n" "$i" "${appportal[$val]}" + ((i++)) +done +echo -e "${italic}${#appportal[@]} lines${reset}\n" + +printf "| %-3s | ${bold}%-60s${reset} \n" "" "Others" +i=1 +for val in ${!others[@]} +do + printf "| %-3s | %-60s \n" "$i" "${others[$val]}" + ((i++)) +done +echo -e "${italic}${#others[@]} lines${reset}\n" + + diff --git a/dsm7-gitea-update.sh b/dsm7-gitea-update.sh new file mode 100644 index 0000000..b5e436b --- /dev/null +++ b/dsm7-gitea-update.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +GITEA_BIN=`which gitea` +if [ "$GITEA_BIN" == "*gitea*" ]; then + echo "Gitea is not installed..." + exit 0 +fi +GITEA_INSTALLED=`$GITEA_BIN --version | cut -d \ -f 3` + +LATEST_URL=`curl -Ls -o /dev/null -w %{url_effective} https://github.com/go-gitea/gitea/releases/latest` +#https://github.com/go-gitea/gitea/releases/tag/v1.11.3 + +#echo LATEST_URL = ${LATEST_URL} +GITEA_VERSION=${LATEST_URL##*/v} + +if [ "${GITEA_INSTALLED}" != "${GITEA_VERSION}" ]; then + echo "No update available..." + exit 0 + +else + echo "Installed: "${GITEA_INSTALLED} + echo "Latest: "${GITEA_VERSION} + + + a=$(echo -e "Do you wanna update Gitea to ${GITEA_VERSION} ? (y/n)") + read -p "$a" choice + + if [ "$choice" == "y" ] || [ "$choice" == "Y" ]; then + + rm -rf /tmp/gitea + mkdir /tmp/gitea + cd /tmp/gitea + + sudo systemctl stop gitea + + echo "Download latest Gitea..." + GITEA_ARCHIVE=gitea-${GITEA_VERSION}-linux-amd64.xz + #DOWNLOAD_URL=https://github.com/go-gitea/gitea/releases/download/v${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64.xz + DOWNLOAD_URL=https://github.com/go-gitea/gitea/releases/download/v${GITEA_VERSION}/${GITEA_ARCHIVE} + echo ${DOWNLOAD_URL} + + wget -P /tmp/gitea ${DOWNLOAD_URL} + # sudo opkg install xz + # sudo opkg install tar (sinon tar: unrecognized option '--exclude=INFO.in') + xz --decompress ${GITEA_ARCHIVE} + + echo "Installing Gitea ${GITEA_VERSION}..." + filename="${GITEA_ARCHIVE%.*}" + + if [[ "$filename" =~ gitea ]]; then + mv $filename gitea + sudo mv gitea `dirname "$GITEA_BIN"` + fi + sudo chmod +x ${GITEA_BIN} + sudo chown root:root ${GITEA_BIN} + + sudo systemctl start gitea + + sudo systemctl status gitea + + fi +fi + + +exit 1 diff --git a/ffmpeg-convertMP4.sh b/ffmpeg-convertMP4.sh new file mode 100644 index 0000000..c1542bf --- /dev/null +++ b/ffmpeg-convertMP4.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# run: sh ffmpeg-convertMP4v6.sh /volume1/video/TV_ts /volume1/video/TV +#v5: notifications, logs +#v6: modif date dans les logs +#v7 supprime ( GR1_B SMR6 Nat CNH Multi4 NTN MHD7 ) + +LOG=/volume1/homes/bruno/logs # dossier du fichier .log +ENREGISTREMENTS=/volume1/video/TV_2 +TABLEAU=( GR1_B SMR6 Nat CNH Multi4 NTN MHD7 ) +# http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/ +timestamp() +{ + date +"%d-%m-%Y %T" +} + +# création du fichier log +touch $LOG/ffmpeg.log +echo $(timestamp) "Demarrage du script" >> $LOG/ffmpeg.log + +# Variables Section +#============================================================== +# list process to monitor in the variable below. +PROGRAM1=ffmpeg +# APPCHK varible checks to see if $PROGRAM1 is running. +APPCHK=$(ps -ea | grep $PROGRAM1 | grep -v grep | wc -l) +#================================================================== +# The ‘if’ statement below checks to see if the process is running +# with the ‘ps’ command. If the value is returned as a ‘0’ then +# a message is prompted +if [ $APPCHK -eq 0 ]; +then + + cd "$1" + for FILE in *; + do + + #on supprime les espaces dans les noms de fichiers + # on supprime ( GR1_B SMR6 Nat CNH Multi4 NTN MHD7 ) + #RENAME=$(echo "$FILE" | sed -e 's/[[:blank:]]/_/g'); + RENAME=$(echo "$FILE" | sed -e '{s/[[:blank:]]/_/g;s/(\(GR1_B\|SMR6\|Nat\|CNH\|Multi4\|NTN\|MHD7\))//g}') + if [ -e "$RENAME" ];then + echo "">/dev/null; + else + mv "$FILE" "$RENAME"; + fi + + #on récupère le nom sans extension + NAME=$(echo "$RENAME" | sed 's/\.[^\.]*$//') + + #nom des fichiers + INPUT_FILE="$1/$RENAME" + OUTPUT_FILE=$(echo "$2/$NAME.mp4") + + #if [ "$NAME" != "@eaDir" -a ! -f "$OUTPUT_FILE" ]; + if [ "$NAME" != "@eaDir" ]; + then + + echo "Conversion du fichier: $OUTPUT_FILE" + + #echo "$JOUR Debut conversion du fichier $FILE" >> $LOG/ffmpeg.log + echo "$(timestamp) Debut conversion du fichier $FILE" >> $LOG/ffmpeg.log + + #/volume1/homes/bruno/scripts/ffmpeg -i "$INPUT_FILE" -map 0:0 -map 0:1 -c:a aac -strict -2 -async 1 -c:v libx264 -crf 20 -r 25 -s 1920x1080 -aspect 16:9 -qmin 3 -qmax 51 -qdiff 4 -y "$OUTPUT_FILE" + /volume1/homes/bruno/scripts/ffmpeg -i "$INPUT_FILE" -map 0:0 -map 0:1 -c:a aac -b:a 160k -async 1 -c:v libx264 -crf 20 -r 25 -s 1280x720 -aspect 16:9 -y "$OUTPUT_FILE" + #les originaux sont déplacés dans $ENREGISTREMENTS + mv "$INPUT_FILE" "$ENREGISTREMENTS/" + + #echo "$JOUR Conversion du fichier $NAME.mp4 terminee" >> $LOG/ffmpeg.log + echo "$(timestamp) Conversion du fichier $NAME.mp4 terminee" >> $LOG/ffmpeg.log + synodsmnotify @administrators "[ffmpeg-convertMP4.sh]" "Conversion du fichier $FILE terminee" + + fi + + done +else + #echo “$PROGRAM1 is running” + #echo "$JOUR $PROGRAM1 est deja actif" >> $LOG/ffmpeg.log + echo "$(timestamp) $PROGRAM1 est deja actif" >> $LOG/ffmpeg.log + synodsmnotify @administrators "[ffmpeg-convertMP4.sh]" "$PROGRAM1 est deja actif" + +fi +#echo $JOUR "Fin du script" >> $LOG/ffmpeg.log +echo "$(timestamp) Fin du script" >> $LOG/ffmpeg.log +exit \ No newline at end of file diff --git a/kymsu_dsm b/kymsu_dsm new file mode 160000 index 0000000..40040c2 --- /dev/null +++ b/kymsu_dsm @@ -0,0 +1 @@ +Subproject commit 40040c264b2b81bdb5efb96c799ded2def7ec1c7 diff --git a/opkg.sh b/opkg.sh new file mode 100644 index 0000000..eec869d --- /dev/null +++ b/opkg.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +#!/bin/su root + +# iPKG plugin for KYMSU +# https://github.com/welcoMattic/kymsu + +# No distract mode +no_distract=false + +if [[ $1 == "--nodistract" ]]; then + no_distract=true +fi + +#tester si lancer en root, sinon quit +if [ "$UID" -ne "0" ] +then + echo "" + echo "📦 _opkg doit être lancé en root !" + echo "Si vous lancez kymsu avec ssh, connectez-vous d'abord en ssh, puis lancez kymsu" + echo "" + exit 1 +fi + +echo "" +echo "📦 oPKG" +echo "" +/opt/bin/opkg update + +echo "" + +# ipkg list-installed + +opkg_outdated=$(/opt/bin/opkg list-upgradable) +upd3=$(echo "$opkg_outdated" | awk '{print $1}') + +if [ -n "$upd3" ]; then + + if [ "$no_distract" = false ]; then + + a=$(echo -e "Do you wanna run \033[1moPKG upgrade "$upd3"\033[0m? (y/n)") + read -p "$a" choice + case "$choice" in + y|Y ) echo "$opkg_outdated" | awk '{print $1}' | xargs -p -n 1 /opt/bin/opkg upgrade ;; + n|N ) echo "Ok, let's continue";; + * ) echo "invalid";; + esac + else + echo "$opkg_outdated" | awk '{print $1}' | xargs -n 1 /opt/bin/opkg upgrade + fi +else + echo -e "\033[4mNo availables updates.\033[0m" +fi + +echo "" +