#!/bin/bash ## For laptop lid trigger: Write following in /etc/acpi/events/lm_lid # event=button/lid.* # action=/data/DatenLucas/Dokumente/Dokumente/Projekte/Server/scripts/quiethost/wallpaperChanger.sh -l -c HOST="$(hostname)" IMG_FOLDER="Desktop1920x1080/" if [ "${HOST}" == "serverhost" ]; then LOG_DIR="/torrent/WallpaperChanger/.LOG/" IMG_DIR="/torrent/WallpaperChanger/" Wallpaper_Dir="${IMG_DIR}Win10Wallpaper" PrivKey="file:/home/lucas/Documents/Dokumente/Projekte/Server/quiethost/IMG_privateKey.pem" elif [ "${HOST}" == "quiethost" ]; then LOG_DIR="/home/lucas/.LOG/" IMG_DIR="/data/Nextcloud/Stuff/Wallpaper/" Wallpaper_Dir="${LOG_DIR}Wallpaper" PrivKey="file:/data/Nextcloud/Documents/Dokumente/Projekte/Server/quiethost/IMG_privateKey.pem" elif [ "${HOST}" == "vivohost" ]; then LOG_DIR="/home/lucas/.LOG/" IMG_DIR="/home/lucas/Nextcloud/Wallpaper/" Wallpaper_Dir="${LOG_DIR}Wallpaper" IMG_FOLDER="Desktop1920x1080/" fi X_FOLDER="corrupt" DAEMON=false LOG=false DECODE_SINGLE=false REMOVE=false CUSTOM_DIR=false CONFIG=false CLEAR_ALL=false CONFIGFILE="wp.conf" NAMING_TABLE="naming_table.txt" NAMING_TABLE_ENC="naming_table_enc.txt" EXCLUDE_CONFIG_DEF="XXXDEFAULTXXX" REPLACE_ENC_IMG=false MONITOR_num_ext=0 DEVICE_CARD="card0" screen_height_Y=(1080) screen_width_X=(1920) X_IMAGE=false X_INSTA=false SET=false repeat_X=1 EDIT_CONFIG=false usage(){ printf "Usage: -t \t\tStart DAEMON and Change Image every min Interval -p \t\tPath of Image folder -s \t\tChose Search Parameters(everything until next -*) -ex \t\tExclude String from Search -c\t\t\tUse Config File -l\t\t\tUse Log File -elements\tInclude Spectral Lines of Elements Pictures -clear\t\tClear Config -h\t\t\tDisplay this -times \t\tchange image n times -e\t\t\tEdit Config File -mon \t\tchange monitor number\n" } usageX(){ printf "UsageX: -x\t\t\tSwitch Source Folder to X -X\t\t\tClear Config and change Wallpaper -dec_all\t\tDecode all Images -dec_leave\t\tLeave used Images decoded -dec_arg -rm(opt)\tDecode certain Images matching pattern ** and delete entries(opt) -printNT\t\tDecode NT to stdout -modifyNT\t\tDecode NT/Encode if decoded NT present -replace\t\tReplace Image in NT -insta\t\tInsta Mode -check_enc\tCheck for decrypted files -g \tGrep NT for pattern \n" } change_image(){ IMGtype=("Wallpaper" "Screensaver" "Grub" "Login") EXCLUDE=${EXCLUDE_CONFIG} if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && [ "${DAEMON}" == "false" ];then echo "Check Encryprion" check_encryption fi for IMG in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.jp*g' -or -name '*.JP*G'); do if [ "$(identify $IMG | grep -iP "jp[e]?g")" != "" ]; then convert "$IMG" "$(echo $IMG | sed 's/JP[E]\?G/png/g' | sed 's/jp[e]\?g/png/g')" rm "$IMG" IMG="$(echo $IMG | sed 's/JP[E]\?G/png/g' | sed 's/jp[e]\?g/png/g')" fi done IMG_NUM_TOTAL=$(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | wc -l) if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then echo "Decode Naming Table" file_path="${IMG_DIR}${IMG_FOLDER}/" if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}" fi fi ConvertSTR="" time_stamp=$(date +'%d%m%y_%H%M%S') if [[ "${HOST}" == "quiethost" ]] || [[ "${HOST}" == "vivohost" ]]; then Wallpaper_Str="${LOG_DIR}Wallpaper/Wallpaper_${time_stamp}" else Wallpaper_Str="${IMG_DIR}Win10Wallpaper/Wallpaper_${time_stamp}" fi Wallpaper_TriLite_Str="${IMG_DIR}TriLiteWallpaper/Wallpaper_${time_stamp}" imageWidthFinal=0 echo Mon: ${MONITOR_num} for (( j=0;j<${MONITOR_num};j++ )); do # j = Screen ind=$(($j)) img_fit_counter=0; IMG_FIT=false while ! $IMG_FIT; do if [ ${#SEARCH[@]} -eq 1 ]; then ind=0 fi SEARCH_PARAMETER=${SEARCH[${ind}]} SEARCH_NUM="$(echo ${SEARCH_PARAMETER} | grep -oE "[[:digit:]]{2}")" SEARCH_STR="$(echo ${SEARCH_PARAMETER} | grep -oE "[^[:digit:]]+")" echo "Search Parameter: ${SEARCH_STR} - ${SEARCH_NUM}, exclude ${EXCLUDE}" if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then IMG_count=$(cat "${file_path}${NAMING_TABLE}" | cut -f1 -d';' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted" | wc -l) else IMG_count=$(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted" | wc -l) fi if [ ${IMG_count} -eq 0 ];then echo "No image found for ${SEARCH_STR}" if [ "${SEARCH_STR}" == "" ];then exit 1 else SEARCH="" continue fi else echo "${IMG_count} Images found" fi NUM=$(($RANDOM % $IMG_count)) if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then IFS=$'\n'; set -f IMG_ARR=($(cat "${file_path}${NAMING_TABLE}" | cut -f1 -d';' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}")) IMG_ENC_ARR=($(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${IMG_ARR[@]} | sed 's/ /\\\|/g')" | cut -f2 -d';')) unset IFS; set +f else IFS=$'\n'; set -f IMG_ARR=($(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted")) unset IFS; set +f fi IMG=${IMG_ARR[$NUM]} for (( k=0;k<${#IMAGES[@]};k++ ));do if [[ ("${SEARCH[0]}" != "${SEARCH_PARAMETER}" && "${SEARCH_NUM}" != "" ) || ("${SEARCH[0]}" == "${SEARCH_PARAMETER}" && "${SEARCH_NUM}" == "") ]]; then counter=0; while [[ "${IMG}" == ${IMAGES[$k]} && ${counter} -lt ${IMG_count} ]]; do echo Disable Same Image NUM=$(($RANDOM % $IMG_count)) IMG=${IMG_ARR[$NUM]} ((counter++)) done fi done IMAGES[${j}]=$IMG #echo Ind $j Imgas ${IMAGES[${j}]} Img $IMG if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then echo "Decrypt Image" IMG_DEC=${file_path}${IMG} IMG_ENC=${IMG_ENC_ARR[$NUM]} if [ -f "${file_path}${IMG_DEC}" ]; then echo "File Name already present: ${IMG_DEC}" IMG_DEC="$(echo "${IMG_DEC}" | sed 's/.png/_DOUBLE_'"${RANDOM}"'\.png/g')" fi openssl enc -aes-256-cbc -pbkdf2 -d -in "${file_path}${IMG_ENC}" -out "${IMG_DEC}" -pass "${PrivKey}" if [ $? -eq 0 ]; then echo "Decryption Succesfull" else echo "Decryption failed" fi IMG=${IMG_DEC} fi if [[ "$(echo ${IMG} | grep "Elements/Elements_")" != "" ]]; then for ((k=0;k<3;k++)); do POINTSIZE=24 IFS=$'\n'; set -f IMG_ARR2=($(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | grep "Elements/Elements_" | grep -v "${IMG}")) unset IFS; set +f IMG_count2=${#IMG_ARR2[@]} NUM=$(($RANDOM % $IMG_count2)) IMG2=${IMG_ARR2[$NUM]} convert -append $IMG $IMG2 "${LOG_DIR}NextCombined.png" NUM=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f1 -d'_') NUM2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f1 -d'_') LET=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f2 -d'_') LET2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f2 -d'_') NAME=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f3 -d'_') NAME2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.png)' | cut -f3 -d'_') NAME="$(printf "%s %s %s" "$NUM" "$LET" "$NAME")" if [ "$( echo ${NAME} | grep -o "[A-Za-z]")" == "" ]; then NAME=${NAME_BUF}; fi NAME2="$(printf "%s %s %s" "$NUM2" "$LET2" "$NAME2")" if [ $(( ${k}%2 )) -eq 0 ]; then y_1=$(( 510 + k*540 )); y_2=$(( 580 + k*540 )); convert -font helvetica -fill white -pointsize ${POINTSIZE} -draw "text 20,'${y_1}' '${NAME}' text 20,'${y_2}' '${NAME2}'" "${LOG_DIR}NextCombined.png" "${LOG_DIR}NextCombined.png" fi IMG="${LOG_DIR}NextCombined.png" NAME_BUF=${NAME2} done fi ## Aspect Ratio Part imageAR=$(getAspectRatio ${IMG}) printf "Mon: %d: $(echo ${IMG} | rev | cut -f1 -d'/' | rev) ImAR: %s - MonAR: %s - ScrAR: %s\n" "${j}" "${imageAR}" "${screen_Aspect_Ratio[$j]}" "${screenAR}" if [[ "$IMG" == "" ]]; then exit; fi BIGIMG=false AR_tolerance="0.26" Wallpaper_Name="${Wallpaper_Str}_${j}.png" img_width_X="$(identify $IMG | cut -f3 -d' ' | cut -f1 -d'x')" if [ $(echo ${imageAR}'=='${screenAR} | bc -l) -eq 1 ]; then # if [ ${MONITOR_num} -eq 1 ]; then break; fi echo "Copy $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]} Image - ${Wallpaper_Str}.png" cp "$IMG" "${Wallpaper_Str}.png" IMG_FIT=true BIGIMG=true ((imageWidthFinal=${imageWidthFinal}+$(sum_ARR ${screen_width_X[@]}))) j=${MONITOR_num} if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && ! ${DECODE_SINGLE} ;then echo "Remove Decrypted Image" rm ${IMG} fi break elif [[ $(echo ${imageAR}'<'${screenAR}'*(1+'${AR_tolerance}')' | bc -l) -eq 1 && $(echo ${imageAR}'>'${screenAR}'*(1-'${AR_tolerance}')' | bc -l) -eq 1 ]] ;then # if [ ${MONITOR_num} -eq 1 ]; then break; fi echo "Convert Image with smaller AR to $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]} - ${Wallpaper_Str}.png" convert "$IMG" -resize $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]}\! "${Wallpaper_Str}.png" IMG_FIT=true BIGIMG=true ((imageWidthFinal=${imageWidthFinal}+$(sum_ARR ${screen_width_X[@]}))) j=${MONITOR_num} if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && ! ${DECODE_SINGLE} ;then echo "Remove Decrypted Image" rm "${IMG}" fi break elif [ $(echo ${imageAR}'=='${screen_Aspect_Ratio[$j]} | bc -l) -eq 1 ]; then img_height_Y="$(identify $IMG | cut -f3 -d' ' | cut -f2 -d'x')" #echo "${img_width_Y}x${img_height_X}:${screen_width_X[$j]}x${screen_height_Y[$j]}" if [[ "${img_width_X}" != "${screen_width_X[$j]}" || "${img_height_Y}" != "${screen_height_Y[$j]}" ]]; then echo "Convert Image with same AR to ${screen_width_X[$j]}x${screen_height_Y[$j]} - ${Wallpaper_Name}" IMG_FIT=true convert "$IMG" -resize ${screen_width_X[$j]}x${screen_height_Y[$j]}\! "${Wallpaper_Name}" ConvertSTR="${ConvertSTR} ${Wallpaper_Name}" else echo "Copy Image with same AR ${screen_width_X[$j]}x${screen_height_Y[$j]} Image - ${Wallpaper_Name}" #convert image.png -resize 100x100 -gravity center -background "rgb(255,0,255)" -extent 100x100 out.png IMG_FIT=true cp "$IMG" "${Wallpaper_Name}" ConvertSTR="${ConvertSTR} ${Wallpaper_Name}" fi ((imageWidthFinal=${imageWidthFinal}+${screen_width_X[$j]})) elif [ $(echo 2*${imageAR}'=='${screen_Aspect_Ratio[$j]} | bc -l) -eq 1 ]; then img_height_Y="$(identify $IMG | cut -f3 -d' ' | cut -f2 -d'x')" if [[ $(echo ${img_width_X}'=='2*${screen_width_X[$j]} | bc -l) -eq 1 && $(echo ${img_height_Y}'=='${screen_height_Y[$j]} | bc -l) -eq 1 ]]; then echo ${imageWidthFinal}+2*${screen_width_X[$j]}'<='$(sum_ARR ${screen_width_X[@]}) if [[ $(echo ${imageWidthFinal}+2*${screen_width_X[$j]}'>='$(sum_ARR ${screen_width_X[@]}) | bc -l) -eq 1 ]]; then echo Image size too big, reduce Size if [[ $(echo ${SEARCH[${ind}]} | grep Panorama) != "" ]];then SEARCH[${ind}]="" fi continue; fi echo "Copy Image with same AR 2 * ${screen_width_X[$j]}x${screen_height_Y[$j]} Image - ${Wallpaper_Name}" ((imageWidthFinal=${imageWidthFinal}+2*${screen_width_X[$j]})) #convert image.png -resize 100x100 -gravity center -background "rgb(255,0,255)" -extent 100x100 out.png IMG_FIT=true cp "$IMG" "${Wallpaper_Name}" ((j++)); ConvertSTR="${ConvertSTR} ${Wallpaper_Name}" fi elif [[ $(echo ${imageAR}'<'${screen_Aspect_Ratio[$j]}'*(1+'${AR_tolerance}')' | bc -l) -eq 1 && $(echo ${imageAR}'>'${screen_Aspect_Ratio[$j]}'*(1-'${AR_tolerance}')' | bc -l) -eq 1 ]]; then echo "Convert Image with smaller AR to ${screen_width_X[$j]}x${screen_height_Y[$j]} - ${Wallpaper_Name}" convert "$IMG" -resize ${screen_width_X[$j]}x${screen_height_Y[$j]}\! "${Wallpaper_Name}" cp "$IMG" "$( echo "${IMG}_bak" | sed 's/_decrypted//g')" IMG_FIT=true cp "${Wallpaper_Name}" "$IMG" ConvertSTR="${ConvertSTR} ${Wallpaper_Name}" ((imageWidthFinal=${imageWidthFinal}+${screen_width_X[$j]})) else echo "Image ${IMG} out of bounds" fi ((img_fit_counter++)) if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && ! ${DECODE_SINGLE} ;then echo "Remove Decrypted Image" rm "${IMG}" fi if [ $img_fit_counter -ge $IMG_NUM_TOTAL ]; then echo "No Images Found. Change Search Parameter" break fi done done echo Image Width: ${imageWidthFinal}px if ! $BIGIMG; then echo "Convert BigImg" echo "convert ${ConvertSTR} to "${Wallpaper_Name}"" convert ${ConvertSTR} -gravity center -background black +append "${Wallpaper_Str}.png" chmod 777 "${Wallpaper_Str}.png" #echo "rm ${ConvertSTR}" fi if [[ "${HOST}" == "quiethost" ]] || [[ "${HOST}" == "vivohost" ]]; then typeGnomeOpt=("background" "screensaver") i=0 WC_USER="lucas" if [[ "$(whoami)" == "root" ]]; then chown ${WC_USER}:${WC_GROUP} ${Wallpaper_Str}*png echo "file://${Wallpaper_Str}.png" if [ "$(su ${WC_USER} -c "gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark")" != "'file://${Wallpaper_Str}.png'" ]; then echo Set gsettings ${typeGnomeOpt[${i}]} picture-uri su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark file://${Wallpaper_Str}.png" su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri file://${Wallpaper_Str}.png" fi if [ "$(su ${WC_USER} -c "gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options")" != "'spanned'" ]; then echo Set gsettings ${typeGnomeOpt[${i}]} picture-options su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options spanned" fi else if [ "$(gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark)" != "'file://${Wallpaper_Str}.png'" ]; then echo Set gsettings picture-uri gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark file://${Wallpaper_Str}.png gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri file://${Wallpaper_Str}.png fi if [ "$(gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options)" != "'spanned'" ]; then echo Set gsettings ${typeGnomeOpt[${i}]} picture-options gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options spanned fi fi fi if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] ;then echo "Remove Naming Table" rm "${file_path}${NAMING_TABLE}" elif [[ "${HOST}" == "serverhost" ]]; then TRILITE_IMAGES=( "Berg" "Space" "Kamerun" "Stadt" "Foto" "Music") COPY_TR=1 #echo "${IMAGES[@]}" for ELEM in "${IMAGES[@]}"; do COPY_TR1=0 echo "ELEM: $ELEM" for KEYWORD in "${TRILITE_IMAGES[@]}"; do #echo "KEY: $KEYWORD" if [[ "$(echo ${ELEM} | grep ${KEYWORD})" != "" ]]; then printf "%s,%s\n" "${ELEM##*/}" "${KEYWORD}" COPY_TR1=1 #else # echo "Key ${KEYWORD} not found" fi done if [[ ${COPY_TR1} -eq 0 ]]; then printf "No keyword found in %s\n" "${ELEM##*/}" fi COPY_TR=$((${COPY_TR} && ${COPY_TR1})) done if [[ ${COPY_TR} -eq 1 ]] && [[ "${HOST}" != "quiethost" ]]; then cp "${Wallpaper_Str}.png" "${Wallpaper_TriLite_Str}.png" echo "Copy Image to Trilite Folder" fi find ${IMG_DIR}TriLiteWallpaper/ -mmin +50 -type f -delete fi find ${Wallpaper_Dir} -type f -name Wallpaper_${time_stamp}_* -delete find ${Wallpaper_Dir} -mmin +50 -type f -delete if [ $(id -u) -eq 0 ] && [ "${HOST}" == "serverhost" ]; then echo "Delete $(find /nextcloud/nextcloud-data/lucas/files_trashbin/files/ -type f -name Wallpaper_*png\.d*)" find /nextcloud/nextcloud-data/lucas/files_trashbin/files/ -type f -name Wallpaper_*png\.d* -delete find /nextcloud/nextcloud-data/lucas/files_trashbin/files/ -type f -name Sexy_*png\.d* -delete chown -R lucas:lucas ${IMG_DIR}Win10Wallpaper/* fi } getAspectRatio() { if [ "$1" == "" ]; then return "0"; fi identify "$1" | perl -ne '/(.+?)\s+[A-Z]{3}\s+(\d+)x(\d+)/; print $3/$2, "\n"' } decode_all() { echo "Decode all Images" IMG_FOLDER_TMP="${X_FOLDER}" file_path="${IMG_DIR}${IMG_FOLDER_TMP}/" if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}" fi for file in $(find ${IMG_DIR}${IMG_FOLDER_TMP} -name '*.png_enc' | sort); do if [ "$(identify ${file} 2>>/dev/null | grep "PNG")" == "" ]; then DEC_NAME="$(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${file} | rev | cut -f1 -d'/' | rev)" | cut -f1 -d';')" if [ "${DEC_NAME}" == "" ]; then DEC_NAME="$(cat ${file_path}NT/* | grep "$(echo ${file} | rev | cut -f1 -d'/' | rev)" | head -1 | cut -f1 -d';')" if [ "${DEC_NAME}" == "" ]; then echo "DEC_NAME empty" echo "File: ${file}" echo "DEC_NAME: ${DEC_NAME}" DEC_NAME="Sexy_MISSING_${RANDOM}.png" else echo "Found ${DEC_NAME} in NT Folder" fi fi DEC_NAME="${file_path}${DEC_NAME}" if [ -f "${file_path}${DEC_NAME}" ]; then echo "File Name already present: ${DEC_NAME}" DEC_NAME="$(echo "${DEC_NAME}" | sed 's/.png/_DOUBLE_'"${RANDOM}"'\.png/g')" else echo "Decode ${file} to ${DEC_NAME}" fi openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file}" -out "${DEC_NAME}" -pass "${PrivKey}" if [ $? -eq 0 ]; then rm ${file} else echo "Decryption failed, exit" echo "${file} to ${DEC_NAME}" exit fi fi done rm "${file_path}${NAMING_TABLE_ENC}" rm "${file_path}${NAMING_TABLE}" } check_encryption() { IMG_FOLDER="${X_FOLDER}" ENC_FILE_COUNT=0; file_path="${IMG_DIR}${IMG_FOLDER}/" for IMG in $(find ${IMG_DIR}New -name '*.jp*g' -or -name '*.JP*G'); do echo Found $IMG in New if [ "$(identify $IMG | grep -iP "jp[e]?g")" != "" ]; then convert "$IMG" "$(echo $IMG | sed 's/JP[E]\?G/png/g' | sed 's/jp[e]\?g/png/g')" rm "$IMG" IMG="$(echo $IMG | sed 's/JP[E]\?G/png/g' | sed 's/jp[e]\?g/png/g')" fi done if [ $(ls ${IMG_DIR}New/*png 2>>/dev/null | wc -l ) -gt 0 ]; then echo "Move to ${IMG_FOLDER}:" ls ${IMG_DIR}New/*png mv ${IMG_DIR}New/*png ${IMG_DIR}/${IMG_FOLDER}/ fi for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.png_enc'); do ENC_FILE_ARR[${ENC_FILE_COUNT}]=${file} ((ENC_FILE_COUNT++)) done ((ENC_FILE_COUNT--)) IFS=$'\n' ENC_FILE_ARR=($(sort <<<"${ENC_FILE_ARR[*]}")) unset IFS if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}" elif [ ! -f "${file_path}${NAMING_TABLE}" ]; then touch "${file_path}${NAMING_TABLE}" fi for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.png' | sort); do if [ "$(identify ${file} 2>>/dev/null | grep "PNG")" != "" ]; then if [ ${#ENC_FILE_ARR[@]} -eq 0 ]; then ENC_FILE_COUNT=0 ENC_NAME_CORE="0" cat "${file_path}${NAMING_TABLE}" else ENC_NAME_CORE=$(( $(echo "${ENC_FILE_ARR[${ENC_FILE_COUNT}]}" | cut -d'.' -f1 | rev | cut -f1 -d'/' | rev | bc) + 1)) ((ENC_FILE_COUNT++)) fi ENC_NAME="$(printf "%05d" ${ENC_NAME_CORE}).png_enc" ENC_FILE_ARR[${ENC_FILE_COUNT}]=${ENC_NAME} if [ -f "${file_path}${ENC_NAME}" ]; then echo "File Name already present: ${ENC_NAME}" ENC_NAME="$(echo "${ENC_NAME_CORE}")_DOUBLE_${RANDOM}.png_enc" else echo "Encode ${file} to ${ENC_NAME}" fi file_identifier="$( echo "${file}" | rev | cut -f1 -d'/' | rev)" if [ -f "${file_path}${NAMING_TABLE}" ];then if [ "$(cat "${file_path}${NAMING_TABLE}" | grep "${file_identifier}")" != "" ] && ! ${REPLACE_ENC_IMG} ; then echo "Identifier ${file_identifier} already present, changing to" file_identifier="$(echo "${file_identifier}" | sed 's/\.png/_enc_DOUBLE_'"${RANDOM}"'\.png/g')" echo "${file_identifier}" echo "${file_identifier};${ENC_NAME}" >> "${file_path}${NAMING_TABLE}" elif [ "$(cat "${file_path}${NAMING_TABLE}" | grep "${file_identifier}")" != "" ] && ${REPLACE_ENC_IMG} ; then ENC_NAME="$(cat "${file_path}${NAMING_TABLE}" | grep "${file_identifier}" | cut -d';' -f2)" echo "Identifier ${file_identifier} already present, replacing image ${ENC_NAME}" else echo "${file_identifier};${ENC_NAME}" >> "${file_path}${NAMING_TABLE}" fi fi openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file}" -out "${file_path}${ENC_NAME}" -pass "${PrivKey}" rm "${file}" fi done openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE}" -out "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}" rm "${file_path}${NAMING_TABLE}" IMG_FOLDER="${X_FOLDER}" echo Check Encryption Done } decode_images() { echo "Decode All *$1*" IMG_FOLDER_TMP="${X_FOLDER}" file_path="${IMG_DIR}${IMG_FOLDER_TMP}/" dec_file_path="${IMG_DIR}New/" if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}" fi files=($(cat "${file_path}${NAMING_TABLE}" | grep -e ".*$1.*" | cut -f2 -d';')) for file in ${files[@]}; do if [ "$(identify ${file} 2>>/dev/null | grep "PNG")" == "" ]; then naming_table_line=$(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${file} | rev | cut -f1 -d'/' | rev)") DEC_NAME="${dec_file_path}$(echo ${naming_table_line} | cut -f1 -d';')" if [ "$(echo ${naming_table_line} | grep -e ".*$1.*")" == "" ]; then continue fi if [ -f "${DEC_NAME}" ]; then echo "File Name already present: ${DEC_NAME}" DEC_NAME="$(echo "${DEC_NAME}" | sed 's/.png/_DOUBLE_'"${RANDOM}"'\.png/g')" else echo "Decode ${DEC_NAME}" fi openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${file}" -out "${DEC_NAME}" -pass "${PrivKey}" if [[ "${REMOVE}" == "true" ]]; then echo "Remove line ${naming_table_line} from Naming Table" sed -i '/'"${naming_table_line}"'/d' ${file_path}${NAMING_TABLE} echo "Remove ${file_path}${file}" rm "${file_path}${file}" fi fi done openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE}" -out "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}" rm "${file_path}${NAMING_TABLE}" } printNamingTable() { IMG_FOLDER_TMP="${X_FOLDER}/" file_path="${IMG_DIR}${IMG_FOLDER_TMP}/" if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}" | grep -i "$1" | sort else echo "No Naming Table under ${file_path}${NAMING_TABLE_ENC}" fi } modifyNT() { IMG_FOLDER_TMP="${X_FOLDER}/" file_path="${IMG_DIR}${IMG_FOLDER_TMP}" NAMING_TABLE="naming_table_mod.txt" if [ -f "${file_path}${NAMING_TABLE_ENC}" ];then if [ ! -f "${file_path}${NAMING_TABLE}" ];then openssl enc -d -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE_ENC}" -out "${file_path}${NAMING_TABLE}" -pass "${PrivKey}" echo "Decrypting to ${file_path}${NAMING_TABLE}" if [ $# -eq 0 ]; then vim ${file_path}${NAMING_TABLE} modifyNT fi else openssl enc -aes-256-cbc -pbkdf2 -salt -in "${file_path}${NAMING_TABLE}" -out "${file_path}${NAMING_TABLE_ENC}" -pass "${PrivKey}" rm "${file_path}${NAMING_TABLE}" echo "Encrypting to ${file_path}${NAMING_TABLE_ENC}" fi else echo "No Naming Table under ${file_path}${NAMING_TABLE_ENC}" fi } logfile_cleanup(){ size=$(ls -l $LOG_FILE | cut -f5 -d' ') echo Logfile Size: $size if [ $size -gt 100000 ]; then lines=$(wc -l $LOG_FILE | cut -f1 -d' ') lines_new=$(($lines / 2)) echo Lines: $lines echo Lines_new: $lines_new sed -i "1,${lines_new}d" $LOG_FILE exec 1>>${LOG_FILE} 2>&1 fi } sum_ARR(){ arr=($@) if [ ${#arr[@]} -eq 0 ]; then return 0; fi IFS='+'; set -f sum=$(echo "scale=1;${arr[*]}"|bc) unset IFS; set +f echo $sum } get_screensize(){ CONN_COUNT=0 if [[ "${HOST}" == "vivohost" ]]; then cards=($(ls /sys/class/drm/ | grep card[0-9] | grep -v -)) for ((i=0;i<${#cards[@]};i++)); do DEVICE_CARD=${cards[$i]} devices=($(ls /sys/class/drm/${DEVICE_CARD}/ | grep "${DEVICE_CARD}-" | cut -f2- -d'-')) echo ${devices[@]} for ((j=0;j<${#devices[@]};j++)); do status=$(cat /sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-"${devices[${j}]}"/status) enabled=$(cat /sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-"${devices[${j}]}"/enabled) echo ${status} ${enabled} if [ "${status}" == "connected" ] && [ "${enabled}" == "enabled" ]; then ((CONN_COUNT++)) mon_dev[$i]=/sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-${devices[${j}]} echo "mon_dev: $mon_dev" fi done done elif [[ "${HOST}" == "quiethost" ]]; then if [ "$(ls /sys/class/drm/${DEVICE_CARD}/ | grep "${DEVICE_CARD}-")" == "" ]; then printf "Wrong Device Card: %s -> " "${DEVICE_CARD}" DEVICE_CARD="card1" printf "New: %s\n" "${DEVICE_CARD}" fi IFS=$'\n'; set -f devices=($(ls /sys/class/drm/${DEVICE_CARD}/ | grep "${DEVICE_CARD}-" | cut -f2- -d'-')) unset IFS; set +f CONN_COUNT=0 for ((i=0;i<${#devices[@]};i++)); do echo "Device: ${devices[${i}]}" devices_name[${i}]=$(echo ${devices[${i}]}| grep -o "[[:alpha:]]*" | grep -m1 "[[:alpha:]]*") devices_num[${i}]=$(echo ${devices[${i}]}|rev| grep -o "[[:digit:]]" | grep -m1 "[[:digit:]]") status[${i}]=$(cat /sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-"${devices[${i}]}"/status) enabled[${i}]=$(cat /sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-"${devices[${i}]}"/enabled) if [ $(echo ${devices[${i}]} | grep "eDP" | wc -l) -ge 1 ]; then if [ $(grep "wallpaperChanger.sh" /etc/acpi/events/lm_lid 2>/dev/null | wc -l) -eq 0 ]; then echo "ERROR: No laptop lid trigger file: /etc/acpi/events/lm_lid" fi if [ $(grep "open" /proc/acpi/button/lid/LID0/state | wc -l) -eq 0 ]; then status[${i}]="disconnected" echo "Laptop Lid closed" else echo "Laptop Lid open" fi fi if [ "${status[${i}]}" == "connected" ] && [ "${enabled[${i}]}" == "enabled" ]; then ((CONN_COUNT++)) mon_dev[$i]=/sys/class/drm/${DEVICE_CARD}/${DEVICE_CARD}-${devices[${j}]} echo "mon_dev: $mon_dev" fi echo "${devices[${i}]}: ${status[${i}]}, ${enabled[${i}]}" done fi if [[ "${HOST}" == "quiethost" ]] || [[ "${HOST}" == "vivohost" ]];then MONITOR_FILE="/home/lucas/.config/monitors.xml" echo "Open Monitor File" CONFIG_ARR=($(cat ${MONITOR_FILE} | tr '\n' ';' | sed 's/ \+//g' | sed 's/<\/configuration>/<\/configuration>\n/g' | grep "")) for ((j=0;j<${#CONFIG_ARR[@]};j++)); do CONFIG_ARR[$j]="$(echo "${CONFIG_ARR[$j]}" | tr ';' '\n')" MONITOR_COUNT=$(echo "${CONFIG_ARR[$j]}" | grep -c "") CONFIG_SUCCESS=true echo "Connected Monitors: $CONN_COUNT" echo "Configured Monitors: $MONITOR_COUNT" if [ $CONN_COUNT -ne $MONITOR_COUNT ]; then continue else echo Continue with correct monitors fi for ((i=0;i<${#mon_dev[@]};i++)); do CONFIG_TEST=${CONFIG_ARR[$j]} if [ "${status[${i}]}" == "connected" ]; then echo "${mon_dev[${i}]}/device/device/graphics/fb0/virtual_size" SIZE_X="$(cat "${mon_dev[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f1 -d',')" SIZE_Y="$(cat "${mon_dev[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f2 -d',')" CONFIG_TEST="$(echo "${CONFIG_TEST}" | tr '\n' ';' | sed 's/<\/logicalmonitor>;/<\/logicalmonitor>\n/g' | grep "${devices_name[${i}]}" | grep "${devices_num[${i}]}" | grep ";${SIZE_X};${SIZE_Y};")" CONFIG_TEST=="Hack" fi if [ "${CONFIG_TEST}" == "" ]; then CONFIG_SUCCESS=false echo "Wrong Monitor" fi done if ${CONFIG_SUCCESS}; then echo "Correct Config found" CONFIG_NEW="${CONFIG_ARR[$j]}" else echo "Wrong Monitor" fi # CONFIG_ARR_NEW[$j]="$(echo "${CONFIG_ARR[$j]}" | grep "${devices[${i}]}")" done if [ $CONN_COUNT -eq 1 ]; then for ((i=0;i<${#devices[@]};i++)); do if [ "${status[${i}]}" == "connected" ]; then echo "i:$i, ${mon_dev[${i}]}/device/device/graphics/fb0/virtual_size" SIZE_X="$(cat "${mon_dev[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f1 -d',')" SIZE_Y="$(cat "${mon_dev[${i}]}/device/device/graphics/fb0/virtual_size" | cut -f2 -d',')" POS="0" CONFIG_NEW="$SIZE_X\n$SIZE_Y\n$POS\n" else echo Status of ${devices[$i]} not connected fi done fi if [ "$CONFIG_NEW" == "" ]; then echo "Abort: Monitor Information not consistent" exit fi IFS=$'\n'; set -f screen_width_X=($(echo -e "$CONFIG_NEW" | grep "width" | grep -o "[[:digit:]]*")) screen_height_Y=($(echo -e "$CONFIG_NEW" | grep "height" | grep -o "[[:digit:]]*")) screen_pos_X=($(echo -e "$CONFIG_NEW" | grep "" | grep -o "[[:digit:]]*")) unset IFS; set +f for ((i=0; i<${#screen_width_X[@]} ; i++ )); do screen_Aspect_Ratio[${i}]=$(perl -E "say ${screen_height_Y[${i}]}/${screen_width_X[${i}]}") done screenAR=$(perl -E "say ${screen_height_Y[0]}/$(sum_ARR ${screen_width_X[@]})") MONITOR_num=$((${#screen_width_X[@]})) elif [ "${HOST}" == "serverhost" ]; then MONITOR_FILE="monitors.cfg" if [ ${MONITOR_num_ext} -gt 0 ]; then MONITOR_FILE="monitors${MONITOR_num_ext}.cfg" echo "Change monitor file to ${MONITOR_FILE}" fi MONITOR_num=$(cat ${IMG_DIR}.LOG/${MONITOR_FILE} | grep Mon | cut -f2 -d':') IFS=':'; set -f; read -r -a screen_width_X <<< $(cat ${IMG_DIR}.LOG/${MONITOR_FILE} | grep X | tr -d 'X') IFS=':'; set -f; read -r -a screen_height_Y <<< $(cat ${IMG_DIR}.LOG/${MONITOR_FILE} | grep Y | tr -d 'Y') unset IFS; set +f for ((i=0; i<${#screen_width_X[@]} ; i++ )); do screen_Aspect_Ratio[${i}]=$(perl -E "say ${screen_height_Y[${i}]}/${screen_width_X[${i}]}") done screenAR=$(perl -E "say ${screen_height_Y[0]}/$(sum_ARR ${screen_width_X[@]})") fi } clear_all() { > ${LOG_DIR}${CONFIGFILE} CONFIG=true; IMG_FOLDER="Desktop1920x1080/" } sync_image() { echo "Sync Nextcloud" if [ "${HOST}" == "serverhost" ]; then if [ $(id -u) -eq 0 ]; then sudo -u lucas /usr/bin/syncNC > /dev/null 2>&1 else /usr/bin/syncNC > /dev/null 2>&1 fi fi } get_config() { while [[ ${1:0:1} == - ]]; do echo "Param: $1" [[ $1 == -clear ]] && { CLEAR_ALL=true; shift 1; continue; } [[ $1 == -t ]] && { if [ $# -lt 2 ]; then usage exit fi minutes=$2; DAEMON=true; MODE="daemon"; LOG=true; shift 2; continue; }; [[ $1 == -screen ]] && { if [ $# -lt 2 ]; then usage exit fi SIZE=$2; shift 2; continue; }; [[ $1 == -mon ]] && { if [ $# -lt 2 ]; then usage exit fi MONITOR_num_ext=$2; shift 2; continue; }; [[ $1 == -p ]] && { if [ $# -lt 2 ]; then usage exit fi CUSTOM_DIR=true; IMG_DIR=$2; shift 2; continue; }; [[ $1 == -s ]] && { if [ $# -lt 2 ]; then SEARCH="" else counter=0 while (true); do if [[ "$2" == "-"* || "$2" == "" ]]; then shift 1; break; fi SEARCH[$counter]=$2 ((counter++)) shift 1 done fi continue; }; [[ $1 == -c ]] && { CONFIG=true; shift 1; continue; }; [[ $1 == -set ]] && { if [ $# -lt 2 ]; then usageX exit fi SET=true shift 1; SET_TO="$*" continue; exit }; [[ $1 == -l ]] && { LOG=true; shift 1; continue; }; [[ $1 == -x ]] && { X_IMAGE=true; X_FOLDER="corrupt" IMG_FOLDER="${X_FOLDER}" shift 1; continue; }; [[ $1 == -h ]] && { usage exit 0; }; [[ $1 == -hX ]] && { usageX exit 0; }; [[ $1 == -check_enc ]] && { sync_image check_encryption sync_image exit 0; }; [[ $1 == -ex ]] && { EXCLUDE_CONFIG="$2" shift 2; }; [[ $1 == -dec_leave ]] && { DECODE_SINGLE=true shift 1; continue; }; [[ $1 == -e ]] && { EDIT_CONFIG=true; shift 1; continue; }; [[ $1 == -insta ]] && { X_INSTA=true X_FOLDER="insta" IMG_FOLDER="${X_FOLDER}" shift 1; continue; }; [[ $1 == -dec_arg ]] && { arg=$2; shift 2; [[ $1 == -rm ]] && { REMOVE=true shift 1; }; decode_images "${arg}" sync_image exit 0; }; [[ $1 == -rm ]] && { shift 1; REMOVE=true }; [[ $1 == -dec_all ]] && { decode_all exit }; [[ $1 == -printNT ]] && { printNamingTable shift 1; exit 0; }; [[ $1 == -g ]] && { printNamingTable "$2" shift 2; exit 0; }; [[ $1 == -modifyNT ]] && { modifyNT shift 1; exit 0; } [[ $1 == -decNT ]] && { modifyNT -leave shift 2; exit 0; } [[ $1 == -replace ]] && { REPLACE_ENC_IMG=true shift 1; continue; } [[ $1 == -times ]] && { repeat_X=$2; shift 2; continue; } echo "Parameter $1 discarded" exit shift 1; done } echo Start $0 $@ SEARCH="" MODE="user"; #EXCLUDE_CONFIG=${EXCLUDE_CONFIG_DEF} EXCLUDE_CONFIG="elements" get_config "$@" if $CLEAR_ALL; then clear_all find ${Wallpaper_Dir} -type f -name "*.png" -delete if [ $(id -u) -eq 0 ]; then sudo -u lucas /usr/bin/syncNC > /dev/null 2>&1 else /usr/bin/syncNC > /dev/null 2>&1 fi fi if $SET; then echo "$SET_TO" > ${LOG_DIR}${CONFIGFILE} fi if $EDIT_CONFIG; then vim "${LOG_DIR}${CONFIGFILE}" fi if $CONFIG; then IFS=$' '; set -f get_config $(cat "${LOG_DIR}${CONFIGFILE}") unset IFS; set +f fi if $X_IMAGE; then X_FOLDER="corrupt" IMG_FOLDER="${X_FOLDER}" fi if $X_INSTA; then X_FOLDER="insta" IMG_FOLDER="${X_FOLDER}" fi if $LOG; then LOG_FILE="${LOG_DIR}wallpaperchanger_${MODE}.log" ls $LOG_DIR >> /dev/null 2>&1 if [[ $? -ne 0 ]]; then echo "Directory $LOG_DIR not present" exit 1 fi exec 1>>${LOG_FILE} 2>&1 date fi if $CUSTOM_DIR; then if [ "$(echo "${IMG_DIR: -1}")" == "/" ]; then IMG_FOLDER="$(echo ${IMG_DIR} | rev | cut -f2 -d'/' | rev)/" IMG_DIR="$(echo ${IMG_DIR} | rev | cut -f3- -d'/' | rev)/" else IMG_FOLDER="$(echo ${IMG_DIR} | rev | cut -f1 -d'/' | rev)/" IMG_DIR="$(echo ${IMG_DIR} | rev | cut -f2- -d'/' | rev)/" fi echo ${IMG_FOLDER} echo ${IMG_DIR} fi ls ${IMG_DIR}${IMG_FOLDER} >> /dev/null 2>&1 if [[ $? -ne 0 ]]; then echo "Directory ${IMG_DIR}${IMG_FOLDER} not present" exit 1 fi get_screensize if [ "${screenAR}" == "0.5625" ]; then EXCLUDE_CONFIG="Panorama" fi echo "Monitor Number: ${MONITOR_num}" echo "Screen Width: ${screen_width_X[@]}" echo "Screen Height: ${screen_height_Y[@]}" echo "Screen Pos: ${screen_pos_X[@]}" echo "Monitor Aspect Ratio: ${screen_Aspect_Ratio[@]} - Screen: ${screenAR}" echo "Dir: ${IMG_DIR}${IMG_FOLDER}" echo "User: $(whoami)" if ${DAEMON}; then if [ "`echo $minutes | egrep ^[[:digit:]]+$`" = "" ];then echo "$minutes is not an Integer" exit else echo "Interval: $minutes min" fi echo "Start DAEMON" sleep_time=$(( $minutes * 60 )) while [[ 1 -eq 1 ]]; do if $CONFIG; then IMG_FOLDER="Desktop1920x1080/" IFS=$' '; set -f get_config $(cat "${LOG_DIR}${CONFIGFILE}") unset IFS; set +f fi get_screensize change_image sync_image date logfile_cleanup echo "DAEMON Mode" sleep $sleep_time done else if [ $repeat_X -gt 1 ]; then echo "Change Image ${repeat_X} times" fi for (( i=0; i<$repeat_X ; i++ )); do change_image sleep 1 done sync_image fi exit 0