btrbk: add mainProgram (#356350)
[NixPkgs.git] / pkgs / by-name / ke / keepass / extractWinRscIconsToStdFreeDesktopDir.sh
blobdec7367379e4e2d697b2c42c37b6a8bf06a7df8a
1 #!/bin/sh
3 # The file from which to extract *.ico files.
4 #rscFile="./KeePass.exe"
5 rscFile=$1
7 # A regexp that can extract the image size from the file name.
8 # sizeRegex='[^\.]+\.exe_[0-9]+_[0-9]+_[0-9]+_[0-9]+_([0-9]+x[0-9]+)x[0-9]+\.png'
9 sizeRegex=$2
11 # sizeReplaceExp='\1'
12 sizeReplaceExp=$3
14 # A regexp that can extract the name of the target image from the file name.
15 # nameRegex='([^\.]+)\.exe.+'
16 nameRegex=$4
18 # nameReplaceExp='\1'
19 nameReplaceExp=$5
21 # out=./myOut
22 out=$6
24 # An optional temp dir. TODO: Generate it randomly by default instead.
25 tmp=./tmp
26 if [ "" != "$4" ]; then
27 tmp=$7
32 rm -rf $tmp/png $tmp/ico
33 mkdir -p $tmp/png $tmp/ico
35 # Extract the ressource file's extension.
36 rscFileExt=`echo "$rscFile" | sed -re 's/.+\.(.+)$/\1/'`
38 # Debug ressource file extension.
39 echo "rscFileExt=$rscFileExt"
41 if [ "ico" = "$rscFileExt" ]; then
42 cp -p $rscFile $tmp/ico
43 else
44 wrestool -x --output=$tmp/ico -t14 $rscFile
47 icotool --icon -x --palette-size=0 -o $tmp/png $tmp/ico/*.ico
49 mkdir -p $out
51 for i in $tmp/png/*.png; do
52 fn=`basename "$i"`
53 size=$(echo $fn | sed -re 's/'${sizeRegex}'/'${sizeReplaceExp}'/')
54 name=$(echo $fn | sed -re 's/'${nameRegex}'/'${nameReplaceExp}'/')
55 targetDir=$out/share/icons/hicolor/$size/apps
56 targetFile=$targetDir/$name.png
57 mkdir -p $targetDir
58 mv $i $targetFile
59 done
61 rm -rf $tmp/png $tmp/ico