You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
7.7 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

#!/bin/bash
path=~/.i4lock/config.yml
ImageType=""
BlurType=""
FilePath=""
isConfigExist() {
cat $path 2>/dev/null
echo $?
}
#############################
#
# Fonction to write config
#
setConfig() {
echo "Image: $1" > $path
echo "Blur: $2" >> $path
echo "Sound: $3" >> $path
echo "PowerBtn: $4" >> $path
}
#############################
#
# Fonction to config Image
#
selectImage() {
title="Type Image"
prompt="Selectionner ci-dessous:"
options=("ScreenShot" "Fichier Existant" "Couleur")
PS3="$prompt "
while opt=$(zenity --title="$title" --text="$prompt" --list \
--width=480 --height=480 --column="Options" "${options[@]}" 2>/dev/null)
do
case "$opt" in
"${options[0]}") echo $opt; break;;
"${options[1]}") echo $opt; break;;
"${options[2]}") echo $opt; break;;
*) zenity --error --text="Option Invalide. Veuillez réessayer." 2>/dev/null;;
esac
done
}
#############################
#
# Fonction to config RGB Image
#
selectRGB() {
title="Couleur"
ask="Inserer votre couleur:  [Hex dans #]"
echo `zenity --entry --title $title --text $ask "ff0000" "00ff00" "0000ff" 2>/dev/null`
}
#############################
#
# Fonction to config blur
#
selectBlurType() {
title="Pourcentage de blur"
prompt="Selectionner ci-dessous:"
options=("0x0" "0x2" "0x4" "0x8" "0x16" "0x32" "0x64")
PS3="$prompt "
while opt=$(zenity --title="$title" --text="$prompt" --list \
--width=480 --height=480 --column="Options" "${options[@]}" 2>/dev/null)
do
case "$opt" in
"${options[0]}") echo $opt; break;;
"${options[1]}") echo $opt; break;;
"${options[2]}") echo $opt; break;;
"${options[3]}") echo $opt; break;;
"${options[4]}") echo $opt; break;;
"${options[5]}") echo $opt; break;;
"${options[6]}") echo $opt; break;;
*) zenity --error --text="Option Invalide. Veuillez réessayer." 2>/dev/null;;
esac
done
}
#############################
#
# Fonctions to config Sound
#
selectSoundBoolean() {
title="Son à l'activage"
prompt="Selectionner ci-dessous:"
options=("Oui" "Non")
PS3="$prompt "
while opt=$(zenity --title="$title" --text="$prompt" --list \
--width=480 --height=480 --column="Options" "${options[@]}" 2>/dev/null)
do
case "$opt" in
"${options[0]}") echo $opt; break;;
"${options[1]}") echo $opt; break;;
*) zenity --error --text="Option Invalide. Veuillez réessayer." 2>/dev/null;;
esac
done
}
selectSoundType() {
echo `zenity --file-selection 2>/dev/null`
}
#############################
#
# Fonction to config power button
#
selectPowerBoolean() {
title="Désactivage du Power Button"
prompt="Selectionner ci-dessous:"
options=("Oui" "Non")
PS3="$prompt "
while opt=$(zenity --title="$title" --text="$prompt" --list \
--width=480 --height=480 --column="Options" "${options[@]}" 2>/dev/null)
do
case "$opt" in
"${options[0]}") echo $opt; break;;
"${options[1]}") echo $opt; break;;
*) zenity --error --text="Option Invalide. Veuillez réessayer." 2>/dev/null;;
esac
done
}
#############################
#
# Fonction to select a file
#
selectFile() {
echo `zenity --file-selection 2>/dev/null`
}
#############################
#
# Fonction to setup config
# of i4lock.
#
setupNewUser() {
echo "Bienvenue sur i4lock,"
echo "Veuillez suivre les instructions afin de setup votre environnement."
TypeLock=""
ImageType=""
BlurType=""
SoundType=""
SoundBoolean=""
PowerButton=""
echo "Etape 1/5"
echo "| Selection Type"
ImageType="$(selectImage)"
if [[ $ImageType == "" ]]; then
exit 1
fi
if [[ $ImageType == "Fichier Existant" ]]; then
ImageType="$(selectFile)"
TypeLock="File"
if [[ $ImageType == "" ]]; then
exit 1
fi
elif [[ $ImageType == "Couleur" ]]; then
ImageType="$(selectRGB)"
TypeLock="RGB"
fi
echo "Etape 2/5"
echo "| Selection Blur"
if [[ $TypeLock != "RGB" ]]; then
BlurType="$(selectBlurType)"
else
BlurType="0x0"
fi
if [[ $BlurType == "" ]]; then
exit 1
fi
#echo $BlurType
echo "Etape 2/5"
echo "| Selection Sound"
SoundBoolean="$(selectSoundBoolean)"
SoundType="null"
if [[ $SoundBoolean == "Oui" ]]; then
echo "Etape 3/5"
echo "| Selection Sound 2"
SoundType="$(selectSoundType)"
fi
echo "Etape 4/5"
echo "| Selection Power Button"
PowerButton="$(selectPowerBoolean)"
echo "Etape 5/5"
echo "| Save Config"
mkdir ~/.i4lock 2>/dev/null
echo 'alias i4lock="~/../machirat1/public/i4lock.sh"' >> ~/.bashrc
setConfig $ImageType $BlurType $SoundType $PowerButton
}
rmtempfile() {
rm /tmp/lock2.png 2>/dev/null
rm /tmp/lock.png 2>/dev/null
}
##############
# #
# Global #
# #
##############
if [[ "$#" != "0" ]]; then
######################
#
# Code of args
#
######################
if [[ "$1" == "--help" ]]; then
echo "Utilisation : i4lock [OPTION]"
echo "Un i3lock custom à votre goût."
echo " "
echo "Options:"
echo "-c --config Permet de reconfigurer votre i4lock."
echo "-v --version Permet d'avoir la version de i4lock."
echo "-cl --clear Permet de clear sa config."
echo " "
echo "Dependencies:"
echo "- i3lock"
echo "- mpg123"
echo "- composite"
echo "- convert"
echo "- xinput"
elif [[ "$1" == "-c" || "$1" == "--config" ]]; then
setupNewUser
elif [[ "$1" == "-v" || "$1" == "--version" ]]; then
echo "i4lock version 1.0"
elif [[ "$1" == "-cl" || "$1" == "--clear" ]]; then
read -p "Press any key to clear data or cancel with Ctrl+c"
rm $path
else
echo "i4lock: option invalide -- '$1'"
echo "Saisissez « i4lock --help » pour plus d'informations."
fi
else
######################
#
# Main of i4lock
#
######################
configexist="$(isConfigExist)"
if [[ $configexist == "1" ]]; then
setupNewUser
else
rmtempfile
Image=`cat $path | grep Image | cut -f 2 -d ' '`
ClrImg=`echo $Image | grep /home | wc -l`
Blur=`cat $path | grep Blur | cut -f 2 -d ' '`
Sound=`cat $path | grep Sound | cut -f 2 -d ' '`
PowerBtn=`cat $path | grep PowerBtn | cut -f 2 -d ' '`
getpower=`xinput --list | grep Power | cut -f 35 -d ' ' | sed 's/[^0-9]*//g'`
if [[ $Sound != "null" ]]; then
mpg123 $Sound
fi
if [[ $PowerBtn == "Oui" ]]; then
for i in $getpower; do
xinput disable $i;
done
fi
scrot /tmp/lock.png
if [[ "$Image" == "ScreenShot" ]]; then
if [[ $Blur != "0px" ]]; then
convert -blur $Blur /tmp/lock.png /tmp/lock.png
fi
i3lock -i /tmp/lock.png
elif [[ "$ClrImg" == "0" ]]; then
i3lock -c $Image
else
cp $Image /tmp/lock2.png
convert /tmp/lock2.png -resize 1920x1080 /tmp/lock2.png
composite -gravity center /tmp/lock2.png /tmp/lock.png /tmp/lock.png
if [[ "$Blur" != "0px" ]]; then
convert -blur $Blur /tmp/lock.png /tmp/lock.png
fi
i3lock -i /tmp/lock.png
fi
for i in $getpower; do
xinput enable $i;
done
rmtempfile
fi
fi