feat(wallpaper-changer.sh): change default image format to jpg
Add image-to-JPEG conversion change image format to jpg everywhere update getimageAR function to handle jpg
This commit is contained in:
1 parent
d244d00c92
commit
1100f058e6
1 file changed
+280
-250
+280
-250
@@ -63,6 +63,7 @@ usage(){
|
||||
-e\t\t\tEdit Config File
|
||||
-mon <n>\t\tchange monitor number\n"
|
||||
}
|
||||
|
||||
usageX(){
|
||||
printf "UsageX:
|
||||
-x\t\t\tSwitch Source Folder to X
|
||||
@@ -78,21 +79,44 @@ usageX(){
|
||||
-check_enc\tCheck for decrypted files
|
||||
-g <pattern>\tGrep NT for pattern <pattern>\n"
|
||||
}
|
||||
|
||||
convert_images_to_jpg(){
|
||||
local IMG JPG EXT
|
||||
while IFS= read -r -d '' IMG; do
|
||||
JPG="${IMG%.*}.jpg"
|
||||
EXT="${IMG##*.}"
|
||||
if [[ "${EXT,,}" == "jpg" ]]; then
|
||||
[[ "$IMG" == "$JPG" ]] && continue
|
||||
if [[ -e "$JPG" ]]; then
|
||||
echo "Cannot rename ${IMG}: ${JPG} already exists" >&2
|
||||
return 1
|
||||
fi
|
||||
mv -- "$IMG" "$JPG" || return 1
|
||||
continue
|
||||
fi
|
||||
if [[ -e "$JPG" && "$IMG" != "$JPG" ]]; then
|
||||
echo "Cannot convert ${IMG}: ${JPG} already exists" >&2
|
||||
return 1
|
||||
fi
|
||||
if convert "$IMG" "$JPG"; then
|
||||
rm -- "$IMG" || return 1
|
||||
else
|
||||
echo "Failed to convert image to JPG: ${IMG}" >&2
|
||||
return 1
|
||||
fi
|
||||
done < <(find "$1" -type f \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \) -print0)
|
||||
}
|
||||
|
||||
change_image(){
|
||||
IMGtype=("Wallpaper" "Screensaver" "Grub" "Login")
|
||||
EXCLUDE=${EXCLUDE_CONFIG}
|
||||
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ] && [ "${DAEMON}" == "false" ];then
|
||||
echo "Check Encryprion"
|
||||
check_encryption
|
||||
check_encryption || return 1
|
||||
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)
|
||||
echo "Convert Images to JPG"
|
||||
convert_images_to_jpg "${IMG_DIR}${IMG_FOLDER}" || return 1
|
||||
IMG_NUM_TOTAL=$(find ${IMG_DIR}${IMG_FOLDER} -name '*.jpg' | wc -l)
|
||||
if [ "${IMG_FOLDER}" == "${X_FOLDER}" ];then
|
||||
echo "Decode Naming Table"
|
||||
file_path="${IMG_DIR}${IMG_FOLDER}/"
|
||||
@@ -131,7 +155,7 @@ change_image(){
|
||||
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)
|
||||
IMG_count=$(find ${IMG_DIR}${IMG_FOLDER} -name '*.jpg' | 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}"
|
||||
@@ -153,7 +177,7 @@ change_image(){
|
||||
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"))
|
||||
IMG_ARR=($(find ${IMG_DIR}${IMG_FOLDER} -name '*.jpg' | grep -i "${SEARCH_STR}.*${SEARCH_NUM}" | grep -iv "${EXCLUDE}" | grep -v "_decrypted"))
|
||||
unset IFS; set +f
|
||||
fi
|
||||
IMG=${IMG_ARR[$NUM]}
|
||||
@@ -176,7 +200,7 @@ change_image(){
|
||||
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')"
|
||||
IMG_DEC="$(echo "${IMG_DEC}" | sed 's/.jpg/_DOUBLE_'"${RANDOM}"'\.jpg/g')"
|
||||
fi
|
||||
openssl enc -aes-256-cbc -pbkdf2 -d -in "${file_path}${IMG_ENC}" -out "${IMG_DEC}" -pass "${PrivKey}"
|
||||
if [ $? -eq 0 ]; then
|
||||
@@ -190,31 +214,32 @@ change_image(){
|
||||
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}"))
|
||||
IMG_ARR2=($(find ${IMG_DIR}${IMG_FOLDER} -name '*.jpg' | 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'_')
|
||||
convert -append $IMG $IMG2 "${LOG_DIR}NextCombined.jpg"
|
||||
NUM=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.jpg)' | cut -f1 -d'_')
|
||||
NUM2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.jpg)' | cut -f1 -d'_')
|
||||
LET=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.jpg)' | cut -f2 -d'_')
|
||||
LET2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.jpg)' | cut -f2 -d'_')
|
||||
NAME=$(echo $IMG | grep -o -P '(?<=Panorama_).*(?=.jpg)' | cut -f3 -d'_')
|
||||
NAME2=$(echo $IMG2 | grep -o -P '(?<=Panorama_).*(?=.jpg)' | 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"
|
||||
convert -font helvetica -fill white -pointsize ${POINTSIZE} -draw "text 20,'${y_1}' '${NAME}' text 20,'${y_2}' '${NAME2}'" "${LOG_DIR}NextCombined.jpg" "${LOG_DIR}NextCombined.jpg"
|
||||
fi
|
||||
IMG="${LOG_DIR}NextCombined.png"
|
||||
IMG="${LOG_DIR}NextCombined.jpg"
|
||||
NAME_BUF=${NAME2}
|
||||
done
|
||||
fi
|
||||
## Aspect Ratio Part
|
||||
echo Get Aspect Ratio
|
||||
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
|
||||
@@ -223,12 +248,12 @@ change_image(){
|
||||
fi
|
||||
BIGIMG=false
|
||||
AR_tolerance="0.26"
|
||||
Wallpaper_Name="${Wallpaper_Str}_${j}.png"
|
||||
Wallpaper_Name="${Wallpaper_Str}_${j}.jpg"
|
||||
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"
|
||||
echo "Copy $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]} Image - ${Wallpaper_Str}.jpg"
|
||||
cp "$IMG" "${Wallpaper_Str}.jpg"
|
||||
IMG_FIT=true
|
||||
BIGIMG=true
|
||||
((imageWidthFinal=${imageWidthFinal}+$(sum_ARR ${screen_width_X[@]})))
|
||||
@@ -240,8 +265,8 @@ change_image(){
|
||||
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"
|
||||
echo "Convert Image with smaller AR to $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]} - ${Wallpaper_Str}.jpg"
|
||||
convert "$IMG" -resize $((${screen_width_X[$j]}*${MONITOR_num}))x${screen_height_Y[$j]}\! "${Wallpaper_Str}.jpg"
|
||||
IMG_FIT=true
|
||||
BIGIMG=true
|
||||
((imageWidthFinal=${imageWidthFinal}+$(sum_ARR ${screen_width_X[@]})))
|
||||
@@ -261,7 +286,7 @@ change_image(){
|
||||
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
|
||||
#convert image.jpg -resize 100x100 -gravity center -background "rgb(255,0,255)" -extent 100x100 out.jpg
|
||||
IMG_FIT=true
|
||||
cp "$IMG" "${Wallpaper_Name}"
|
||||
ConvertSTR="${ConvertSTR} ${Wallpaper_Name}"
|
||||
@@ -282,7 +307,7 @@ change_image(){
|
||||
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
|
||||
#convert image.jpg -resize 100x100 -gravity center -background "rgb(255,0,255)" -extent 100x100 out.jpg
|
||||
IMG_FIT=true
|
||||
cp "$IMG" "${Wallpaper_Name}"
|
||||
((j++));
|
||||
@@ -314,8 +339,8 @@ change_image(){
|
||||
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"
|
||||
convert ${ConvertSTR} -gravity center -background black +append "${Wallpaper_Str}.jpg"
|
||||
chmod 777 "${Wallpaper_Str}.jpg"
|
||||
#echo "rm ${ConvertSTR}"
|
||||
|
||||
fi
|
||||
@@ -324,22 +349,22 @@ change_image(){
|
||||
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
|
||||
chown ${WC_USER}:${WC_GROUP} ${Wallpaper_Str}*jpg
|
||||
echo "file://${Wallpaper_Str}.jpg"
|
||||
if [ "$(su ${WC_USER} -c "gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark")" != "'file://${Wallpaper_Str}.jpg'" ]; 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"
|
||||
su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark file://${Wallpaper_Str}.jpg"
|
||||
su ${WC_USER} -c "gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri file://${Wallpaper_Str}.jpg"
|
||||
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
|
||||
if [ "$(gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark)" != "'file://${Wallpaper_Str}.jpg'" ]; 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
|
||||
gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri-dark file://${Wallpaper_Str}.jpg
|
||||
gsettings set org.gnome.desktop.${typeGnomeOpt[${i}]} picture-uri file://${Wallpaper_Str}.jpg
|
||||
fi
|
||||
if [ "$(gsettings get org.gnome.desktop.${typeGnomeOpt[${i}]} picture-options)" != "'spanned'" ]; then
|
||||
echo Set gsettings ${typeGnomeOpt[${i}]} picture-options
|
||||
@@ -372,7 +397,7 @@ change_image(){
|
||||
COPY_TR=$((${COPY_TR} && ${COPY_TR1}))
|
||||
done
|
||||
if [[ ${COPY_TR} -eq 1 ]] && [[ "${HOST}" != "quiethost" ]]; then
|
||||
cp "${Wallpaper_Str}.png" "${Wallpaper_TriLite_Str}.png"
|
||||
cp "${Wallpaper_Str}.jpg" "${Wallpaper_TriLite_Str}.jpg"
|
||||
echo "Copy Image to Trilite Folder"
|
||||
fi
|
||||
find ${IMG_DIR}TriLiteWallpaper/ -mmin +50 -type f -delete
|
||||
@@ -380,16 +405,18 @@ change_image(){
|
||||
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
|
||||
echo "Delete $(find /nextcloud/nextcloud-data/lucas/files_trashbin/files/ -type f -name Wallpaper_*jpg\.d*)"
|
||||
find /nextcloud/nextcloud-data/lucas/files_trashbin/files/ -type f -name Wallpaper_*jpg\.d* -delete
|
||||
find /nextcloud/nextcloud-data/lucas/files_trashbin/files/ -type f -name Sexy_*jpg\.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"'
|
||||
identify "$1" |perl -ne '/\b(\d+)x(\d+)\b/ and print $2/$1, "\n"'
|
||||
}
|
||||
|
||||
decode_all() {
|
||||
echo "Decode all Images"
|
||||
IMG_FOLDER_TMP="${X_FOLDER}"
|
||||
@@ -397,8 +424,8 @@ decode_all() {
|
||||
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
|
||||
for file in $(find ${IMG_DIR}${IMG_FOLDER_TMP} -name '*.jpg_enc' | sort); do
|
||||
if [ "$(identify ${file} 2>>/dev/null | grep "JPEG")" == "" ]; then
|
||||
DEC_NAME="$(cat "${file_path}${NAMING_TABLE}" | grep "$(echo ${file} | rev | cut -f1 -d'/' | rev)" | cut -f1 -d';')"
|
||||
|
||||
if [ "${DEC_NAME}" == "" ]; then
|
||||
@@ -407,7 +434,7 @@ decode_all() {
|
||||
echo "DEC_NAME empty"
|
||||
echo "File: ${file}"
|
||||
echo "DEC_NAME: ${DEC_NAME}"
|
||||
DEC_NAME="Sexy_MISSING_${RANDOM}.png"
|
||||
DEC_NAME="Sexy_MISSING_${RANDOM}.jpg"
|
||||
else
|
||||
echo "Found ${DEC_NAME} in NT Folder"
|
||||
fi
|
||||
@@ -415,7 +442,7 @@ decode_all() {
|
||||
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')"
|
||||
DEC_NAME="$(echo "${DEC_NAME}" | sed 's/.jpg/_DOUBLE_'"${RANDOM}"'\.jpg/g')"
|
||||
else
|
||||
echo "Decode ${file} to ${DEC_NAME}"
|
||||
fi
|
||||
@@ -432,24 +459,18 @@ decode_all() {
|
||||
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
|
||||
convert_images_to_jpg "${IMG_DIR}New" || return 1
|
||||
if [ $(ls ${IMG_DIR}New/*jpg 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}/
|
||||
ls ${IMG_DIR}New/*jpg
|
||||
mv ${IMG_DIR}New/*jpg ${IMG_DIR}/${IMG_FOLDER}/
|
||||
fi
|
||||
for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.png_enc'); do
|
||||
for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.jpg_enc'); do
|
||||
ENC_FILE_ARR[${ENC_FILE_COUNT}]=${file}
|
||||
((ENC_FILE_COUNT++))
|
||||
done
|
||||
@@ -461,8 +482,8 @@ check_encryption() {
|
||||
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
|
||||
for file in $(find ${IMG_DIR}${IMG_FOLDER} -name '*.jpg' | sort); do
|
||||
if [ "$(identify ${file} 2>>/dev/null | grep "JPEG")" != "" ]; then
|
||||
if [ ${#ENC_FILE_ARR[@]} -eq 0 ]; then
|
||||
ENC_FILE_COUNT=0
|
||||
ENC_NAME_CORE="0"
|
||||
@@ -471,11 +492,11 @@ check_encryption() {
|
||||
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_NAME="$(printf "%05d" ${ENC_NAME_CORE}).jpg_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"
|
||||
ENC_NAME="$(echo "${ENC_NAME_CORE}")_DOUBLE_${RANDOM}.jpg_enc"
|
||||
else
|
||||
echo "Encode ${file} to ${ENC_NAME}"
|
||||
fi
|
||||
@@ -483,7 +504,7 @@ check_encryption() {
|
||||
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')"
|
||||
file_identifier="$(echo "${file_identifier}" | sed 's/\.jpg/_enc_DOUBLE_'"${RANDOM}"'\.jpg/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
|
||||
@@ -502,6 +523,7 @@ check_encryption() {
|
||||
IMG_FOLDER="${X_FOLDER}"
|
||||
echo Check Encryption Done
|
||||
}
|
||||
|
||||
decode_images() {
|
||||
echo "Decode All *$1*"
|
||||
IMG_FOLDER_TMP="${X_FOLDER}"
|
||||
@@ -512,7 +534,7 @@ decode_images() {
|
||||
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
|
||||
if [ "$(identify ${file} 2>>/dev/null | grep "JPEG")" == "" ]; 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
|
||||
@@ -520,7 +542,7 @@ decode_images() {
|
||||
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')"
|
||||
DEC_NAME="$(echo "${DEC_NAME}" | sed 's/.jpg/_DOUBLE_'"${RANDOM}"'\.jpg/g')"
|
||||
else
|
||||
echo "Decode ${DEC_NAME}"
|
||||
fi
|
||||
@@ -536,6 +558,7 @@ decode_images() {
|
||||
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}/"
|
||||
@@ -547,6 +570,7 @@ printNamingTable() {
|
||||
echo "No Naming Table under ${file_path}${NAMING_TABLE_ENC}"
|
||||
fi
|
||||
}
|
||||
|
||||
encryptNT() {
|
||||
IMG_FOLDER_TMP="${X_FOLDER}/"
|
||||
file_path="${IMG_DIR}${IMG_FOLDER_TMP}"
|
||||
@@ -563,6 +587,7 @@ encryptNT() {
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
modifyNT() {
|
||||
IMG_FOLDER_TMP="${X_FOLDER}/"
|
||||
file_path="${IMG_DIR}${IMG_FOLDER_TMP}"
|
||||
@@ -584,6 +609,7 @@ modifyNT() {
|
||||
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
|
||||
@@ -596,6 +622,7 @@ logfile_cleanup(){
|
||||
exec 1>>${LOG_FILE} 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
sum_ARR(){
|
||||
arr=($@)
|
||||
if [ ${#arr[@]} -eq 0 ]; then return 0; fi
|
||||
@@ -604,6 +631,7 @@ sum_ARR(){
|
||||
unset IFS; set +f
|
||||
echo $sum
|
||||
}
|
||||
|
||||
get_screensize(){
|
||||
CONN_COUNT=0
|
||||
if [[ "${HOST}" == "vivohost" ]]; then
|
||||
@@ -746,11 +774,13 @@ get_screensize(){
|
||||
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
|
||||
@@ -760,191 +790,191 @@ sync_image() {
|
||||
/usr/bin/syncNC > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
get_config() {
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 && ${1:0:1} == "-" ]]; do
|
||||
echo "Param: $1"
|
||||
[[ $1 == -clear ]] && {
|
||||
CLEAR_ALL=true;
|
||||
shift 1;
|
||||
continue;
|
||||
}
|
||||
[[ $1 == -t ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
minutes=$2;
|
||||
DAEMON=true;
|
||||
MODE="daemon";
|
||||
LOG=true;
|
||||
shift 2;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -screen ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
SIZE=$2;
|
||||
shift 2;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -mon ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
MONITOR_num_ext=$2;
|
||||
shift 2;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -p ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
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;
|
||||
get_config() {
|
||||
while [[ $# -gt 0 && ${1:0:1} == "-" ]]; do
|
||||
echo "Param: $1"
|
||||
[[ $1 == -clear ]] && {
|
||||
CLEAR_ALL=true;
|
||||
shift 1;
|
||||
continue;
|
||||
}
|
||||
[[ $1 == -t ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
minutes=$2;
|
||||
DAEMON=true;
|
||||
MODE="daemon";
|
||||
LOG=true;
|
||||
shift 2;
|
||||
continue;
|
||||
};
|
||||
decode_images "${arg}"
|
||||
sync_image
|
||||
exit 0;
|
||||
};
|
||||
[[ $1 == -rm ]] && {
|
||||
[[ $1 == -screen ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
SIZE=$2;
|
||||
shift 2;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -mon ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
MONITOR_num_ext=$2;
|
||||
shift 2;
|
||||
continue;
|
||||
};
|
||||
[[ $1 == -p ]] && {
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
exit 1
|
||||
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 0
|
||||
};
|
||||
[[ $1 == -printNT ]] && {
|
||||
printNamingTable
|
||||
shift 1;
|
||||
exit 0;
|
||||
};
|
||||
[[ $1 == -g ]] && {
|
||||
printNamingTable "$2"
|
||||
shift 2;
|
||||
exit 0;
|
||||
};
|
||||
[[ $1 == -encryptNT ]] && {
|
||||
encryptNT
|
||||
shift 1;
|
||||
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 1
|
||||
shift 1;
|
||||
REMOVE=true
|
||||
};
|
||||
[[ $1 == -dec_all ]] && {
|
||||
decode_all
|
||||
exit 0
|
||||
};
|
||||
[[ $1 == -printNT ]] && {
|
||||
printNamingTable
|
||||
shift 1;
|
||||
exit 0;
|
||||
};
|
||||
[[ $1 == -g ]] && {
|
||||
printNamingTable "$2"
|
||||
shift 2;
|
||||
exit 0;
|
||||
};
|
||||
[[ $1 == -encryptNT ]] && {
|
||||
encryptNT
|
||||
shift 1;
|
||||
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 1
|
||||
shift 1;
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
echo Start $0 $@
|
||||
@@ -955,7 +985,7 @@ EXCLUDE_CONFIG="elements"
|
||||
get_config "$@"
|
||||
if $CLEAR_ALL; then
|
||||
clear_all
|
||||
find ${Wallpaper_Dir} -type f -name "*.png" -delete
|
||||
find ${Wallpaper_Dir} -type f -name "*.jpg" -delete
|
||||
if [ $(id -u) -eq 0 ]; then
|
||||
sudo -u lucas /usr/bin/syncNC > /dev/null 2>&1
|
||||
else
|
||||
|
||||
Reference in new issue
Block a user