chore: rename create_conf script then lefthook analyse it when commit

This commit is contained in:
Yorick Barbanneau 2024-10-13 11:41:53 +02:00
parent f113664131
commit 5ff1e36a53
2 changed files with 31 additions and 37 deletions

View file

@ -14,6 +14,6 @@ in
frei0r
inkscape
];
home.file.".local/bin/create_conf".source = ./files/create_conf;
home.file.".local/bin/create_conf".source = ./files/create_conf.sh;
};
}

View file

@ -3,8 +3,7 @@
error() {
printf -v message "\e[31mERROR:\e[0m %s\n" "$1"
message="${message} \e[1mStack trace\e[0m:\n"
for (( i=1; i<${#FUNCNAME[@]}; i++ ))
do
for ((i = 1; i < ${#FUNCNAME[@]}; i++)); do
if [[ $i = $((${#FUNCNAME[@]} - 1)) ]]; then
message="${message}"
else
@ -12,7 +11,7 @@ error() {
fi
message="${message}─ source:\e[3;34m${BASH_SOURCE[$i]}\e[0m"
message="${message} function:\e[3;34m${FUNCNAME[$i]}\e[0m"
message="${message} line:\e[3;34m${BASH_LINENO[$i-1]}\e[0m\n"
message="${message} line:\e[3;34m${BASH_LINENO[$i - 1]}\e[0m\n"
done
>&2 printf "%b\n" "${message}"
}
@ -25,17 +24,18 @@ die() {
process_args() {
while :; do
case $1 in
-l|--label)
key_label="$2"
shift
;;
-r|--recorder)
recorder_label="$2"
shift
;;
*)
conf="$*"
break
-l | --label)
key_label="$2"
shift
;;
-r | --recorder)
recorder_label="$2"
shift
;;
*)
conf="$*"
break
;;
esac
shift
done
@ -58,7 +58,7 @@ mount_device() {
device="/dev/$(lsblk -o KNAME,LABEL | grep "${label}" | awk '{print $1}')"
# check is we found a device with this name
if [[ $device = "/dev/" ]]; then
if [[ $device = "/dev/" ]]; then
error "Can't get device named $label is device plugged?"
return 1
fi
@ -87,19 +87,15 @@ get_file_hash() {
file=$1
file_size=${2:-1}
if (( file_size != -1 ))
then
if [ -f "$file" ]
then
if (( file_size > 0 ))
then
if (( file_size > 2000000 ))
then
if ((file_size != -1)); then
if [[ -f "$file" ]]; then
if ((file_size > 0)); then
if ((file_size > 2000000)); then
#calculate
local tmp_file
tmp_file=mktemp
head -c 1MB "$file" > "$tmp_file"
tail -c 1MB "$file" >> "$tmp_file"
head -c 1MB "$file" >"$tmp_file"
tail -c 1MB "$file" >>"$tmp_file"
printf "%s" "$(md5sum "$tmp_file" | cut -d" " -f 1)"
rm "$tmp_file"
else
@ -112,7 +108,7 @@ get_file_hash() {
printf "%s" -1
}
move_file(){
move_file() {
if [[ ! $# -eq 2 ]]; then
error "move_file need 2 arguments, $# provided : '$*'"
return 1
@ -140,10 +136,9 @@ get_file_size() {
fi
local file
file=$1
if [ -f "$file" ]
then
wc -c < "$file"
return
if [[ -f "$file" ]]; then
wc -c <"$file"
return
fi
printf "%s" -1
}
@ -167,10 +162,10 @@ insert_media() {
filesize=$(get_file_size "$filename")
filehash=$(get_file_hash "$filename" "$filesize")
if ! sed -i \
-e "s#\[\[${tag}\]\]#${filename}#g" \
-e "s#\[\[${tag}_filesize\]\]#${filesize}#g" \
-e "s#\[\[${tag}_filehash\]\]#${filehash}#g" \
"${folder}/montage.kdenlive"; then
-e "s#\[\[${tag}\]\]#${filename}#g" \
-e "s#\[\[${tag}_filesize\]\]#${filesize}#g" \
-e "s#\[\[${tag}_filehash\]\]#${filehash}#g" \
"${folder}/montage.kdenlive"; then
error "sed command error on insert media!"
return 1
fi
@ -196,7 +191,6 @@ function main() {
# create it
mkdir "${folder}/"{rushes,audio,titles} -p || die "folder creation failed"
cp "${base_dir}/logo_amis.svg" "${folder}/titles" || die "SVG copy failed!"
cp "${base_dir}/template.kdenlive" "${folder}/montage.kdenlive" || die "Template copy failed!"
@ -209,7 +203,7 @@ function main() {
sed -i "s/\[\[date\]\]/${inkscape_date}/g" "${folder}/titles/logo_amis.svg" || die "Change date failed!"
printf "Export SVG title \n"
inkscape --export-type="png" "${folder}/titles/logo_amis.svg" || die "Export failed"
inkscape --export-type="png" "${folder}/titles/logo_amis.svg" || die "SVG export failed"
printf "Importing PNG File in %s/montage.kdenlive \n" "$folder"
insert_media "$folder/titles/logo_amis.png" "logo"