1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
|
#!/bin/bash
# Copyright (C) 2007-2011 PlayOnLinux Team
# Copyright (C) 2007-2011 Pâris Quentin
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# scripts.lib
# -----------
#
# This lib contains useful tools for scriptors
POL_Shortcut_InsertBeforeWine ()
{
# Insert a command into a script just before running wine
# Usage: POL_Shortcut_InsertBeforeWine [Application] [Line to insert]
POL_Debug_Message "Inserting before POL_Wine : $2"
Application="$1"
CommandsToInsert="$2"
COMMANDS="${CommandsToInsert}" perl -ni -e '
if(!$done && /^POL_Wine /) {
print "$ENV{COMMANDS}\n";
$done=1;
}
print;' "$POL_USER_ROOT/shortcuts/${Application}"
}
POL_Open()
{
# Extended xdg-open function, works for mac
# Usage : POL_Open whatever you want
POL_Debug_Message "Opening: $@"
[ "$POL_OS" == "Mac" ] && open "$@"
[ "$POL_OS" == "Linux" ] && xdg-open "$@"
# FIXME Freebsd
}
POL_Browser ()
{
# Open default's user browser
# Usage : POL_Brower [URL]
POL_Open "$@"
}
POL_System_TmpCreate()
{
# Create a temporary directory for a script
# Usage: POL_System_TmpCreate [tmp_name]
[ "$1" = "" ] && POL_Debug_Fatal "TmpName not defined !"
mkdir -p "$POL_USER_ROOT/tmp/$1"
export POL_System_TmpDir="$POL_USER_ROOT/tmp/$1"
export POL_System_TmpName="$1"
}
POL_System_TmpDelete()
{
# Delete the temporary directory created before
# Usage: POL_System_TmpDelete
[ ! "$POL_System_TmpName" = "" ] && rm -rf "$POL_USER_ROOT/tmp/$POL_System_TmpName" || POL_Debug_Warning "POL_System_TmpName is not defined !"
}
POL_System_SetArch()
{
# Set the architecture to use for the current script
# Usage: POL_System_SetArch (auto|x86|amd64)
# If amd64 is specified and not supported, the script will end
# $1 = Auto, x86, amd64
# $2 = detected, if the result of an automatic selection
if [ ! "$1" == "x86" ] && [ ! "$1" == "amd64" ]
then
[ "$AMD64_COMPATIBLE" == "True" ] && export POL_ARCH="amd64" || export POL_ARCH="x86"
fi
if [ "$1" == "x86" ]
then
export POL_ARCH="x86"
fi
if [ "$1" == "amd64" ]
then
[ "$AMD64_COMPATIBLE" == "True" ] && export POL_ARCH="amd64" || POL_Debug_Fatal "amd64 is not supported by your system"
fi
[ "$2" = "detected" ] || POL_USER_ARCH="$POL_ARCH"
POL_Debug_Message "POL_ARCH set to $POL_ARCH"
}
POL_System_HomeSpaceLeft()
{
# Return the space left in the home partition
df -P -k "$HOME" | tail -n1 | awk '{print $4}'
}
POL_System_UserRootSpaceLeft()
{
# Return the space left in the PlayOnLinux state partition
df -P -k "$POL_USER_ROOT" | tail -n1 | awk '{print $4}'
}
POL_System_EnoughSpace()
{
# Set exitcode to 0 if we have enough space, 1 otherwise
# Usage POL_System_EnoughSpace [ Space required ]
[ "$1" -le "$(POL_System_UserRootSpaceLeft)" ]
}
POL_Shortcut_GetPrefix()
{
# Get a prefixname from a shortcut
# Usage: POL_Shortcut_GetPrefix [Shortcut]
[ "$1" = "" ] && POL_Debug_Error "No shortcut specified"
local file="$POL_USER_ROOT/shortcuts/$1"
[ -e "$file" ] || POL_Debug_Error "Shortcut does not exist"
local prefix="$(cat "$file" | grep '^export WINEPREFIX' | tail -n 1 | $SED s/'\/\//\/'/)"
prefix="${prefix/"$POL_USER_ROOT"/""}"
prefix="$(printf "$prefix" | cut -d "/" -f2)"
printf "$prefix" | tr -d \"
}
POL_GetLocalIcon()
{
# Get a local icon and add it into playonlinux
# Usage: POL_GetLocalIcon [PlayOnLinux's shortcut] [icon name]
convert "$HOME/.local/share/icons/$2" -geometry 32X32 "$POL_USER_ROOT/icones/32/$1"
convert "$HOME/.local/share/icons/$2" "$POL_USER_ROOT/icones/full_size/$1"
}
POL_ExtractIcon()
{
# Extract the icon of a .exe or .ico file
# Usage: POL_ExtractIcon [.exe file] [output image file]
mkdir -p "$POL_USER_ROOT/tmp/win32Icon"
wrestool -x -t14 "$1" > "$POL_USER_ROOT/tmp/win32Icon/icons-brut"
(cd "$POL_USER_ROOT/tmp/win32Icon"
icotool -x "icons-brut" -o "$POL_USER_ROOT/tmp/win32Icon/"
# Is there an existing 32x32 icon?
find . -name "*32x32x32.png" > icons-list
find . -name "*32x32x24.png" >> icons-list
find . -name "*32x32x16.png" >> icons-list
find . -name "*32x32x8.png" >> icons-list
find . -name "*32x32x4.png" >> icons-list
ICON_FILE=$(head -n 1 "icons-list")
if [ -n "$ICON_FILE" -a -s "$ICON_FILE" ]; then
shift
for target in "$@"; do
cp "$ICON_FILE" "$target" || POL_Debug_Warning "Icon was not extracted"
done
else
# Otherwise, find the smallest icon over 32x32 and downsize it
find . -name "*48x48x32.png" > icons-list
find . -name "*48x48x24.png" >> icons-list
find . -name "*48x48x16.png" >> icons-list
find . -name "*48x48x8.png" >> icons-list
find . -name "*48x48x4.png" >> icons-list
find . -name "*64x64x32.png" >> icons-list
find . -name "*64x64x24.png" >> icons-list
find . -name "*64x64x16.png" >> icons-list
find . -name "*64x64x8.png" >> icons-list
find . -name "*64x64x4.png" >> icons-list
find . -name "*96x96x32.png" >> icons-list
find . -name "*96x96x24.png" >> icons-list
find . -name "*96x96x16.png" >> icons-list
find . -name "*96x96x8.png" >> icons-list
find . -name "*96x96x4.png" >> icons-list
find . -name "*128x128x32.png" >> icons-list
find . -name "*128x128x24.png" >> icons-list
find . -name "*128x128x16.png" >> icons-list
find . -name "*128x128x8.png" >> icons-list
find . -name "*128x128x4.png" >> icons-list
find . -name "*256x256x32.png" >> icons-list
find . -name "*256x256x24.png" >> icons-list
find . -name "*256x256x16.png" >> icons-list
find . -name "*256x256x8.png" >> icons-list
find . -name "*256x256x4.png" >> icons-list
ICON_FILE=$(head -n 1 "icons-list")
if [ -n "$ICON_FILE" -a -s "$ICON_FILE" ]; then
convert "$ICON_FILE" -resize 32x32 "$POL_USER_ROOT/tmp/tmp_icon.png" || POL_Debug_Warning "Icon was not extracted"
shift
for target in "$@"; do
cp "$POL_USER_ROOT/tmp/tmp_icon.png" "$target" || POL_Debug_Warning "Icon was not extracted"
done
fi
fi
)
rm -r "$POL_USER_ROOT/tmp/win32Icon"
}
POL_ExtractBiggestIcon()
{
# Extract the biggest icon of a .exe or .ico file
# Usage: POL_ExtractCustomIcon [.exe file] [output image file] [size]
mkdir -p "$POL_USER_ROOT/tmp/win32Icon"
wrestool -x -t14 "$1" > "$POL_USER_ROOT/tmp/win32Icon/icons-brut"
(cd "$POL_USER_ROOT/tmp/win32Icon"
icotool -x "icons-brut" -o "$POL_USER_ROOT/tmp/win32Icon/"
find . -name "*256x256x32.png" > icons-list
find . -name "*256x256x24.png" >> icons-list
find . -name "*256x256x16.png" >> icons-list
find . -name "*256x256x8.png" >> icons-list
find . -name "*256x256x4.png" >> icons-list
find . -name "*128x128x32.png" >> icons-list
find . -name "*128x128x24.png" >> icons-list
find . -name "*128x128x16.png" >> icons-list
find . -name "*128x128x8.png" >> icons-list
find . -name "*128x128x4.png" >> icons-list
find . -name "*96x96x32.png" >> icons-list
find . -name "*96x96x24.png" >> icons-list
find . -name "*96x96x16.png" >> icons-list
find . -name "*96x96x8.png" >> icons-list
find . -name "*96x96x4.png" >> icons-list
find . -name "*64x64x32.png" >> icons-list
find . -name "*64x64x24.png" >> icons-list
find . -name "*64x64x16.png" >> icons-list
find . -name "*64x64x8.png" >> icons-list
find . -name "*64x64x4.png" >> icons-list
find . -name "*48x48x32.png" >> icons-list
find . -name "*48x48x24.png" >> icons-list
find . -name "*48x48x16.png" >> icons-list
find . -name "*48x48x8.png" >> icons-list
find . -name "*48x48x4.png" >> icons-list
find . -name "*36x36x32.png" >> icons-list
find . -name "*36x36x24.png" >> icons-list
find . -name "*36x36x16.png" >> icons-list
find . -name "*36x36x8.png" >> icons-list
find . -name "*36x36x4.png" >> icons-list
find . -name "*32x32x32.png" >> icons-list
find . -name "*32x32x24.png" >> icons-list
find . -name "*32x32x16.png" >> icons-list
find . -name "*32x32x8.png" >> icons-list
find . -name "*32x32x4.png" >> icons-list
ICON_FILE=$(head -n 1 "icons-list")
if [ -n "$ICON_FILE" -a -s "$ICON_FILE" ]; then
shift
for target in "$@"; do
cp "$ICON_FILE" "$target" || POL_Debug_Warning "Icon was not extracted"
done
fi
)
rm -r "$POL_USER_ROOT/tmp/win32Icon"
}
POL_System_find_file ()
{
# Usage: POL_System_find_file [(subdirectory/...)filename]
# Find a file in the current virtual drive that match the provided relative path suffix, case insensitively
# If found, returns its path relative to the drive_c subdirectory
local suffix="$1"
[ "$WINEPREFIX" ] || POL_Debug_Fatal "\$WINEPREFIX not set"
pushd "$WINEPREFIX" >/dev/null || POL_Debug_Fatal "Prefix $WINEPREFIX does not exist"
cd drive_c || POL_Debug_Fatal "drive_c folder does not exist"
local binary_path
if [ -e "./$suffix" ]; then
# Explicit relative path, note that the case has to be correct
binary_path="$suffix"
else
# Implicit path, search file outside of windows directory first
local paths="$(find . -path ./windows -prune -o -ipath "*/$suffix" -a -type f -print)"
[ -z "$paths" ] && paths="$(find ./windows -ipath "*/$suffix" -a -type f -print)"
if [ "$(wc -l <<<"$paths")" -gt 1 ]; then
POL_Debug_Warning "Multiple binaries found for suffix $suffix: $paths"
# Sorting both makes result deterministic, and picks a shallow file
binary_path="$(sort <<<"$paths"|head -n 1)"
else
binary_path="$paths"
fi
fi
popd > /dev/null
echo "$binary_path"
}
POL_Shortcut()
{
# Make a shortcut
# Usage: POL_Shortcut [binary] [shortcut name] [playonlinux website icon] [argument] [categories]
# If playonlinux website icon is not specified, playonlinux will try to extract it from the program
# Possibly to use a path instead of the executable.
BINARY="$1"
SpecialArg="$4"
Categories="$5"
BIN_PATH="$6"
if [ "$2" = "" ]
then
ICON_FILENAME="$1"
else
ICON_FILENAME="$2"
fi
mkdir -p "$POL_USER_ROOT/icones/32"
mkdir -p "$POL_USER_ROOT/icones/full_size"
ICON_WEB_NAME="$3"
ICON_OK=0
if [ -z "$BIN_PATH" ]; then
local binary_path="$(POL_System_find_file "$BINARY")"
local binary_dir="$WINEPREFIX/drive_c/$(dirname "$binary_path")"
else
local binary_path="$BIN_PATH/$BINARY"
local binary_dir="$(dirname "$binary_path")"
fi
local binary_name="$(basename "$binary_path")"
local target="$binary_dir/$binary_name"
[ "$binary_dir" = "$WINEPREFIX/drive_c/" ] && POL_Debug_Fatal "Can't find $BINARY"
POL_Debug_Message "Looking for <${BINARY}>, found <${binary_path}>"
[[ "$target" =~ \.lnk$ ]] && target="$(winepath -u "$(strings "$target"|tail -n 1)")"
if [ -n "$ICON_WEB_NAME" ]; then
if [ ! "$OFFLINE" = "1" ]; then # It can be downloaded...
$POL_WGET "$SITE/icones/$ICON_WEB_NAME" -O- > "$POL_USER_ROOT/icones/full_size/$ICON_FILENAME" || rm "$POL_USER_ROOT/icones/full_size/$ICON_FILENAME" # Take the full sized icon
fi
if [ -f "$POL_USER_ROOT/icones/full_size/$ICON_FILENAME" ]; then
convert -resize 32 "$POL_USER_ROOT/icones/full_size/$ICON_FILENAME" "$POL_USER_ROOT/icones/32/$ICON_FILENAME" # Scale it down to 32*32
ICON_OK=1
fi
elif [ "$ICON_OK" -ne 1 ]; then # No icon from the web, make one off the exe
POL_ExtractIcon "$target" "$POL_USER_ROOT/icones/32/$ICON_FILENAME"
POL_ExtractBiggestIcon "$target" "$POL_USER_ROOT/icones/full_size/$ICON_FILENAME"
fi
if [ -z "$binary_name" ]; then
POL_Debug_Error "$(eval_gettext 'Binary not found: $BINARY\nHave you installed the program to the default location?')"
else
## We generate shortcut
(echo "#!/usr/bin/env playonlinux-bash"
echo "[ \"\$PLAYONLINUX\" = \"\" ] && exit 0"
echo "source \"\$PLAYONLINUX/lib/sources\""
echo "export WINEPREFIX=\"$WINEPREFIX\""
echo "export WINEDEBUG=\"-all\""
[ -n "$LOGTITLE" ] && echo "#POL_Log=$LOGTITLE"
[ -n "$SCRIPTID" ] && echo "#ScriptID=$SCRIPTID"
if [[ "$binary_name" =~ \.(lnk|bat|cmd)$ ]]; then
echo "cd \"$binary_dir\""
echo "POL_Wine start.exe /wait /unix \"\$target\" $SpecialArg \"\$@\""
else
echo "cd \"$binary_dir\""
echo "POL_Wine \"$binary_name\" $SpecialArg \"\$@\""
fi) > "$POL_USER_ROOT/shortcuts/$ICON_FILENAME"
chmod +x "$POL_USER_ROOT/shortcuts/$ICON_FILENAME"
if [ -f "$POL_USER_ROOT/icones/full_size/$ICON_FILENAME" ]; then
iconPath="$POL_USER_ROOT/icones/full_size/$ICON_FILENAME"
else
# Default icon
iconPath="$PLAYONLINUX/etc/playonlinux.png"
fi
# Menus
if [ ! "$(POL_Config_Read NO_MENU_ICON)" = "TRUE" ]; then
# Do nothing on Mac OS
if [ -n "$Categories" -a "$POL_OS" = "Linux" ] || [ -n "$Categories" -a "$POL_OS" = "BSD" ]; then
LOCALAPPS="$HOME/.local/share/applications"
make_desktop_shortcut "$iconPath" "$ICON_FILENAME" "$LOCALAPPS" "$PLAYONLINUX/playonlinux --run \"$ICON_FILENAME\"" "$binary_name" "$Categories" "playonlinux-"
fi
fi
# Desktop
CleanLnkDesktop
if [ "$(POL_Config_Read NO_DESKTOP_ICON)" != "TRUE" ]; then
if [ "$POL_OS" = "Mac" ]; then
POL_SetupWindow_AutoApp "$ICON_FILENAME"
else
make_desktop_shortcut "$iconPath" "$ICON_FILENAME" "$DESKTOP" "$PLAYONLINUX/playonlinux --run \"$ICON_FILENAME\"" "$binary_name" "$Categories"
fi
fi
fi
POL_Debug_Message "Shortcut created: $binary_name $ICON_FILENAME"
}
POL_Shortcut_QuietDebug()
{
# Disable "crash" message on exitcode != 0 unless in debug mode
# Usage: POL_Shortcut_QuietDebug "shortcutname"
echo '[ "$WINEDEBUG" = "-all" ] && exit 0' >> "$POL_USER_ROOT/shortcuts/$1"
}
POL_Call()
{
# Call a "function" script from PlayOnLinux website
# Usage: POL_Call [function name]
POL_Debug_Message "Calling $1"
if [ ! "$1" = "" ]
then
# Caution, some scripts (POL_SP2_Extract at least) depend on this variable (!!)
OLD_PC_DIR="$PWD"
cd "$POL_USER_ROOT/tmp/"
# Local overriding mechanism
if [ "$(POL_Config_Read "ALLOW_FUNCTION_OVERRIDES")" = "TRUE" -a -e "$POL_USER_ROOT/configurations/function_overrides/$1" ]; then
cp "$POL_USER_ROOT/configurations/function_overrides/$1" .
if [ -z "$NOBUGREPORT" ]; then
NOBUGREPORT="TRUE"
POL_SetupWindow_message "$(eval_gettext 'Function override detected, disabling bug reporting')" "$TITLE"
fi
POL_Debug_Message "----- Starting function $1 (OVERRIDED) -----"
POL_Debug_LogToPrefix "----- Starting function $1 (OVERRIDED) -----"
source "$@"
exitcode="$?"
POL_Debug_Message "----- Ending function $1 (OVERRIDED) -----"
POL_Debug_LogToPrefix "----- Ending function $1 (OVERRIDED) -----"
else
# Download "function" script, check its signature, then execute it
$POL_WGET "$SITE/V4_data/repository/get_file.php?version=playonlinux-$VERSION&id=$1" -O- > "$1"
polMd5="$(POL_MD5_file "$1")"
if [ "$polMd5" = "68b329da9893e34099c7d8ad5cb9c940" -o "$polMd5" = "0f1b63a74ab217a19270be0df9e0590d" ] # Empty file
then
POL_Debug_Error "Function $1 does not exist!"
exitcode="1"
else
POL_Debug_Message "----- Starting function $1 -----"
POL_Debug_LogToPrefix "----- Starting function $1 -----"
POL_Source "$@"
exitcode="$?"
POL_Debug_Message "----- Ending function $1 -----"
POL_Debug_LogToPrefix "----- Ending function $1 -----"
fi
fi
cd "$OLD_PC_DIR"
return "$exitcode"
else
POL_Debug_Warning "no function name specified"
fi
}
POL_Call_list ()
{
# Make a list so that the user can choose functions to install
# Usage: POL_Call_List
[ "$WINEPREFIX" == "" ] && POL_Debug_Fatal "WINEPREFIX is not set"
POL_Wine_AutoSetVersionEnv
wineserver -k
ITEMS=$($POL_WGET $SITE/V4_data/repository/getf.php -O-)
POL_SetupWindow_checkbox_list "$(eval_gettext "Please make your choice")" "$APPLICATION_TITLE" "$ITEMS" "/"
local oldifs="$IFS"
IFS=/
set "$APP_ANSWER"
for i in $*
do
POL_Debug_Message "calling $i"
IFS="$old"
POL_Call "$i"
IFS=/
done
IFS="$oldifs"
}
POL_Tools_GenID()
{
# Generate a random string
# Usage: POL_Tools_GenID [length]
local LENGTH="$1"
local CHARACTERS='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
local i=0
while ((i < $LENGTH));
do
local CHAR_IDX=$(( $RANDOM % ${#CHARACTERS}));
printf ${CHARACTERS:$CHAR_IDX:1};
(( i=i+1 ))
done
}
POL_Download ()
{
# Download a file and place it in the current directory
# Usage: POL_Download [URL] [MD5]
POL_Debug_Message "Downloading $1"
local URL="$1"
local SERVER_MD5="$2"
local FILE="${URL##*/}"
local ATTEMPT
[ "$3" ] && ATTEMPT="$3" || ATTEMPT=1
if [ "$ATTEMPT" = "5" ]; then
POL_Debug_Fatal "Unable to download $1 after 5 attempts"
exit
fi
if [ "$URL" = "" ]
then
POL_Debug_Error "URL is missing !"
else
local neededSpace="$(POL_Download_GetSize "$URL")"
if [ "$neededSpace" ]; then
let neededSpace=neededSpace/1024
POL_System_EnoughSpace "$neededSpace" || POL_Debug_Error "$(eval_gettext 'No enough space to download:\n$URL ($neededSpace KB)')"
fi
POL_SetupWindow_download "$(eval_gettext 'Please wait while $APPLICATION_TITLE is downloading:')\n$FILE" "$TITLE" "$URL" "$PWD/$FILE"
if [ "$Result" = "Fail" ]; then
POL_SetupWindow_question "$URL\n\n$(eval_gettext 'An error happened during download.')\n\n$(eval_gettext 'Do you want to retry?')"
if [ "$APP_ANSWER" = "FALSE" ]; then
POL_Debug_Error "error during download! ($ATTEMPT attempt)"
else
POL_Download "$URL" "$SERVER_MD5" "$(( ATTEMPT + 1 ))"
fi
elif [ "$SERVER_MD5" = "" ]
then
POL_Debug_Warning "MD5 is missing!"
elif [ "$SERVER_MD5" = "NO_MD5" ]
then
POL_Debug_Message "Skipping MD5 checksum control"
else
local LOCAL_MD5="$(POL_MD5_file "$FILE")"
if [ "$LOCAL_MD5" = "$SERVER_MD5" ]
then
POL_Debug_Message "Download MD5 matches"
else
POL_SetupWindow_question "$URL\n\n$(eval_gettext 'Error ! Files mismatch\n\nLocal : $LOCAL_MD5\nServer : $SERVER_MD5')\n\n$(eval_gettext 'Do you want to retry?')"
if [ "$APP_ANSWER" = "TRUE" ]; then
POL_Download "$URL" "$SERVER_MD5" "$(( ATTEMPT + 1 ))"
else
POL_Debug_Error "MD5 sum mismatch ! ($ATTEMPT attempt)"
fi
fi
fi
fi
}
POL_Download_Resource ()
{
# Download a file and place it in the resource directory (if it does not exist)
# Usage: POL_Download_Resource [URL] [MD5] (Folder)
POL_Debug_Message "Downloading resource $1"
local URL="$1"
local SERVER_MD5="$2"
local SUBFOLDER="$3"
local ATTEMPT
[ "$4" ] && ATTEMPT="$4" || ATTEMPT=1
local FILE="${URL##*/}"
mkdir -p "$POL_USER_ROOT/ressources/$SUBFOLDER"
cd "$POL_USER_ROOT/ressources/$SUBFOLDER" || POL_Debug_Fatal "Resource subfolder $SUBFOLDER does not exist"
if [ -e "$FILE" ] && [ "$(POL_MD5_file "$FILE")" = "$SERVER_MD5" ]
then
POL_Debug_Message "Resource already present"
else
local WTCACHE=""
[ -d "$HOME/.cache/winetricks" ] && WTCACHE="$(find $HOME/.cache/winetricks -type f -a -iname "$FILE" | tail -n 1)"
if [ -n "$WTCACHE" ] && [ "$(POL_MD5_file "$WTCACHE")" = "$SERVER_MD5" ]
then
ln "$WTCACHE" "$FILE" || cp "$WTCACHE" "$FILE"
POL_Debug_Message "Resource found in winetricks cache"
elif [ "$URL" = "" ]
then
POL_Debug_Error "URL is missing !"
else
local neededSpace="$(POL_Download_GetSize "$URL")"
if [ "$neededSpace" ]; then
let neededSpace=neededSpace/1024
POL_System_EnoughSpace "$neededSpace" || POL_Debug_Error "$(eval_gettext 'No enough space to download:\n$URL ($neededSpace KB)')"
fi
[ -e "$FILE" ] && rm "$FILE"
POL_SetupWindow_download "$(eval_gettext "Please wait while $APPLICATION_TITLE is downloading:") $FILE" "$TITLE" "$URL"
if [ "$Result" = "Fail" ]; then
local APP_ANSWER
POL_SetupWindow_question "$URL\n\n$(eval_gettext 'An error happened during download.')\n\n$(eval_gettext 'Do you want to retry?')"
if [ "$APP_ANSWER" = "FALSE" ]; then
POL_Debug_Error "error during download! ($ATTEMPT attempt)"
else
POL_Download_Resource "$URL" "$SERVER_MD5" "$SUBFOLDER" "$(( ATTEMPT + 1))"
fi
elif [ "$SERVER_MD5" = "" ]
then
POL_Debug_Warning "MD5 is missing !"
else
local LOCAL_MD5="$(POL_MD5_file "$FILE")"
if [ "$LOCAL_MD5" = "$SERVER_MD5" ]
then
POL_Debug_Message "Download MD5 matches"
else
local APP_ANSWER
POL_SetupWindow_question "$URL\n\n$(eval_gettext 'Error ! Files mismatch\n\nLocal : $LOCAL_MD5\nServer : $SERVER_MD5')\n\n$(eval_gettext 'Do you want to retry?')"
if [ "$APP_ANSWER" = "FALSE" ]; then
POL_Debug_Error "MD5 sum mismatch ! ($ATTEMPT attempt)"
else
POL_Download_Resource "$URL" "$SERVER_MD5" "$SUBFOLDER" "$(( ATTEMPT + 1 ))"
fi
fi
fi
fi
fi
}
POL_Download_GetSize()
{
# Get the size of a distant file
# Usage: POL_Download_GetSize [URL]
wget "$1" --spider --server-response -O - 2>&1 | $SED -ne '/Content-Length/{s/.*: //;p}' | tail -n1
}
POL_MD5 ()
{
# Give the md5 sum of a string
# Usage: POL_MD5 <string>
if [ "$POL_OS" == "Mac" ] || [ "$POL_OS" == "FreeBSD" ]
then
printf "$1" | md5
fi
if [ "$POL_OS" == "Linux" ]
then
printf "$1" | md5sum | awk '{print $1}'
fi
}
POL_MD5_file ()
{
# Give the md5 sum of a file
# Usage: POL_MD5_file <file>
if [ "$POL_OS" == "Mac" ] || [ "$POL_OS" == "FreeBSD" ]
then
cat "$1" | md5
fi
if [ "$POL_OS" == "Linux" ]
then
cat "$1" | md5sum | awk '{print $1}'
fi
}
POL_base64()
{
[ "$POL_OS" = "Linux" ] && base64
[ "$POL_OS" = "Mac" ] || [ "$POL_OS" == "FreeBSD" ] && openssl base64
}
POL_unbase64()
{
[ "$POL_OS" = "Linux" ] && base64 -d
[ "$POL_OS" = "Mac" ] || [ "$POL_OS" == "FreeBSD" ] && openssl base64 -d
}
POL_System_unzip ()
{
POL_Debug_Message "Starting unzip $@"
POL_SetupWindow_wait "$(eval_gettext 'Please wait while $APPLICATION_TITLE is handling archive...')" "$TITLE"
unzip "$@" || POL_Debug_Fatal "POL_System_unzip failed with error $?!"
POL_Debug_Message "unzip ok"
POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE"
}
POL_System_7z ()
{
POL_Debug_Message "Starting 7z $@"
POL_SetupWindow_wait "$(eval_gettext 'Please wait while $APPLICATION_TITLE is handling archive...')" "$TITLE"
7z "$@" || POL_Debug_Fatal "POL_System_7z failed with error $?!"
POL_Debug_Message "7z ok"
POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE"
}
POL_System_tar ()
{
POL_Debug_Message "Starting tar $@"
POL_SetupWindow_wait "$(eval_gettext 'Please wait while $APPLICATION_TITLE is handling archive...')" "$TITLE"
tar "$@" || POL_Debug_Fatal "POL_System_tar failed with error $?!"
POL_Debug_Message "tar ok"
POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE"
}
POL_System_cabextract ()
{
POL_Debug_Message "Starting cabextract $@"
POL_SetupWindow_wait "$(eval_gettext 'Please wait while $APPLICATION_TITLE is handling archive...')" "$TITLE"
cabextract "$@" || POL_Debug_Fatal "POL_System_cabextract failed with error $?!"
POL_Debug_Message "cabextract ok"
POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE"
}
POL_System_unrar ()
{
POL_Debug_Message "Starting unrar $@"
POL_SetupWindow_wait "$(eval_gettext 'Please wait while $APPLICATION_TITLE is handling archive...')" "$TITLE"
unrar "$@" || POL_Debug_Fatal "POL_System_unrar failed with error $?!"
POL_Debug_Message "unrar ok"
POL_SetupWindow_wait "$(eval_gettext 'Please wait...')" "$TITLE"
}
POL_System_ExtractSingleFile ()
{
# This function has been written by hifi
# Extract a single file from an archive, with a progressbar
# Usage: POL_System_ExtractSingleFile <archive> <file> <destination>
local archive="$1"
local file="$2"
local dest="$3"
local archivename=`basename "$archive"`
local filename=`basename "$file"`
local szpid
local szip=`which 7z`
POL_Debug_Message "Extracting single file : \"$archive\", \"$file\", \"$dest\""
if [ "$szip" == "" ]; then
POL_Debug_Fatal "$(eval_gettext '7z not installed, please check that you have 7zip installed and try again')"
return 1
fi
local size=`"$szip" l -slt "$archive" "$file" | grep '^Size' | cut -d' ' -f3`
if [ "$size" == "" ]; then
POL_Debug_Error "$(eval_gettext 'Failed to locate ${dest} from ${archive}')"
return 1
fi
POL_SetupWindow_pulsebar "$(eval_gettext 'Extracting ${filename} from ${archivename}')" "$TITLE"
rm -f "$dest"
"$szip" e -so "$archive" "$file" 2>/dev/null 1>"$dest" & szpid=$!
while kill -0 $szpid 2>/dev/null; do
#POL_SetupWindow_pulse $(((`stat -c%s "$dest"` * 100) / "$size")) # Does not work for Mac OS
sleep 1
POL_SetupWindow_pulse $(( (`ls -l "$dest" | awk '{print $5}'` * 100) / $size ))
done
POL_SetupWindow_pulse 100
#if [ `stat -c%s "$dest"` != "$size" ]; then
if [ `ls -l "$dest" | awk '{print $5}'` != "$size" ]; then
POL_Debug_Error "$(eval_gettext 'Extracted file size does not match!')"
return 1
fi
return 0
}
POL_System_cpmv ()
{
# Extract a single file with a progressbar
# Usage: POL_System_cp <file> <destination>
local op="$1"
shift
local file="$1"
local dest="$2"
local filename=`basename "$file"`
case "$op" in
cp)
POL_Debug_Message "Copying single file : \"$file\", \"$dest\""
;;
mv)
POL_Debug_Message "Moving single file : \"$file\", \"$dest\""
;;
*)
POL_Debug_Fatal "POL_System_cpmv: bad operation `$op`"
esac
local size="$(ls -l $file | awk '{print $5}')"
POL_SetupWindow_pulsebar "$(eval_gettext 'Copying ${filename}')" "$TITLE"
rm -f "$dest"
"$op" "$file" "$dest" 2>/dev/null & szpid=$!
while kill -0 $szpid 2>/dev/null; do
sleep 0.3
POL_SetupWindow_pulse $(((`ls -l "$dest" | awk '{print $5}'` * 100) / $size))
done
POL_SetupWindow_pulse 100
if [ "`ls -l "$dest" | awk '{print $5}'`" != "$size" ]; then
POL_Debug_Error "$(eval_gettext 'File size does not match!')"
return 1
fi
return 0
}
POL_System_cp ()
{
POL_System_cpmv "cp" "$@"
}
POL_System_mv ()
{
POL_System_cpmv "mv" "$@"
}
POL_System_wget ()
{
# Wget with a progressbar
# Usage: Same than wget except that URL must be the first parameter, the title of the file is the second parameter
local URL="$1"
POL_Debug_Message "Downloading $1 with wget"
shift
local FILE="$1"
shift
POL_SetupWindow_pulsebar "$(eval_gettext 'Please wait while $APPLICATION_TITLE is downloading:')\n$FILE" "$TITLE"
local prev=0
local ellipsis=''
local wgetlog="$POL_USER_ROOT/tmp/wget$$.output"
local wgetline
set -o pipefail
${POL_WGET/-q} -v -c "$URL" "$@" 2>&1 | \
while read wgetline; do
if [[ "$wgetline" =~ .*\ ([0-9]+)%.* ]]; then
perc=${BASH_REMATCH[1]}
if [ "$perc" != "$prev" ]; then
POL_SetupWindow_pulse $perc
prev="$perc"
fi
ellipsis=1
else
[ "$ellipsis" ] && echo "..."
ellipsis=''
echo $wgetline
fi
done|tee "$wgetlog"
local code=$?
if [ $code -ne 0 ]; then
# man wget
local msg="error $code"
[ $code -eq 1 ] && msg="Generic error code"
[ $code -eq 2 ] && msg="Parse error"
[ $code -eq 3 ] && msg="File I/O error"
[ $code -eq 4 ] && msg="Network failure"
[ $code -eq 5 ] && msg="SSL verification failure"
[ $code -eq 6 ] && msg="Username/Password authentication failure"
[ $code -eq 7 ] && msg="Protocol errors"
[ $code -eq 8 ] && msg="Server issued an error response"
POL_Debug_Fatal "POL_System_wget failed: $msg\n$(cat "$wgetlog")"
fi
set +o pipefail
rm "$wgetlog"
POL_SetupWindow_pulse 100
return 0
}
POL_System_CopyDirectory()
{
# Usage POL_System_CopyDirectory [From] [To] [expected size]
local FROM="$1"
local TO="$2"
local EXPECTED_SIZE="$3"
if [ "$EXPECTED_SIZE" = "" ]; then
EXPECTED_SIZE="$(du "$FROM"| tail -n 1 | awk '{print $1}')"
fi
local statusfile="$POL_USER_ROOT/tmp/cpstatus.$$"
local pid
(cp -R "$FROM/." "$TO/"; echo $? > "$statusfile") & pid="$!"
POL_SetupWindow_DirectoryProgress "$FROM" "$EXPECTED_SIZE" "$pid"
local exitcode="$(cat "$statusfile")"
rm "$statusfile"
[ "$exitcode" = "0" ] || POL_Debug_Fatal "POL_System_CopyDirectory failed, error $exitcode !"
}
POL_Shortcut_Document()
{
# Add a manual to a shortcut
# Usage : POL_Shortcut_Document [Shortcut Name] [file path]
[ "$2" = "" ] && return
local SHORTCUT_NAME="$1"
local DOC_FILENAME="$2"
rm -f "$POL_USER_ROOT/configurations/manuals/$SHORTCUT_NAME"
local doc_path
# For historical reasons POL_Shortcut_Document also accepts absolute paths
if [[ "$DOC_FILENAME" =~ /* && -e "$DOC_FILENAME" ]]; then
doc_path="$DOC_FILENAME"
else
doc_path="$(POL_System_find_file "$DOC_FILENAME")"
[ "$doc_path" ] && doc_path="$WINEPREFIX/drive_c/$doc_path"
fi
if [ "doc_path" ]; then
ln -s "$doc_path" "$POL_USER_ROOT/configurations/manuals/$SHORTCUT_NAME"
else
POL_Debug_Warning "Document $DOC_FILENAME not found"
fi
}
POL_Shortcut_Configurator ()
{
# Add a configurator to a shortcut
# Usage:
# POL_Shortcut_Configurator [Shortcut name] [Program]
# or
# POL_Shortcut_Configurator [Shortcut name] <<_EOFCFG_
# <Configurator script>
# _EOFCFG_
local SHORTCUT_NAME="$1"
local PROGRAM="$2"
(cat <<_PRELUDE_
#!/usr/bin/env playonlinux-bash
[ -z "\$PLAYONLINUX" ] && exit 0
source "\$PLAYONLINUX/lib/sources"
export WINEPREFIX="\$POL_USER_ROOT/wineprefix/$PREFIX"
export WINEDEBUG="-all"
POL_LoadVar_PROGRAMFILES
TITLE="$TITLE"
_PRELUDE_
if [ -n "$PROGRAM" ]; then
local binary_path="$(POL_System_find_file "$PROGRAM")"
local binary_dir="$(dirname "$binary_path")"
local Binaire="$(basename "$binary_path")"
[ "$binary_dir" = "" ] && POL_Debug_Fatal "Can't find $PROGRAM"
echo "cd \"$WINEPREFIX/drive_c/$binary_dir\""
echo "POL_Wine \"$Binaire\" $SpecialArg \"\$@\""
else
cat
fi
) > "$POL_USER_ROOT/configurations/configurators/$SHORTCUT_NAME"
}
POL_RequiredVersion ()
{
# Stop the current script is the current version is lower the required one
# Usage : POL_RequiredVersion [VERSION]
NEEDED="$1"
if VersionLower "$VERSION" "$NEEDED"
then
POL_Debug_Warning "POL_RequiredVersion not satisfied! User version :$VERSION, expected $NEEDED"
POL_SetupWindow_message "$(eval_gettext 'Sorry, $APPLICATION_TITLE $VERSION is too old to continue.\n$APPLICATION_TITLE $NEEDED is required.')" "$TITLE"
POL_SetupWindow_Close
exit 0
fi
}
POL_AdvisedVersion ()
{
# Alert the user, but don't stop the current script is the current version is lower the required one
# Usage : POL_AdvisedVersion [VERSION]
NEEDED="$1"
if VersionLower "$VERSION" "$NEEDED"
then
POL_Debug_Warning "POL_AdvisedVersion not satisfied! User version :$VERSION, expected $NEEDED"
POL_SetupWindow_message "$(eval_gettext 'Warning: You are running $APPLICATION_TITLE $VERSION.\n$APPLICATION_TITLE $NEEDED is recommended to continue.')" "$TITLE"
fi
}
POL_Configurator_runparts ()
{
# Inside a configurator, in a place where SetupWindow and Debug are initialized, sources
# the the configurator parts named after main configurator script plus some extension
# (say the patch they're related to) in alphabetical order.
# Usage : POL_Configurator_runparts
shopt -s nullglob
for conf in "$0".*; do
source "$conf"
done
}
POL_Shortcut_AddLink()
{
# Add a link to a shortcut
# Usage : POL_Shortcut_AddLink [Shortcut] [Title] [URL]
echo "$2|$3" >> "$POL_USER_ROOT/configurations/links/$1"
}
POL_Shortcut_AddProfileLink()
{
# Add a scriptor profile link to a shortcut
# Usage : POL_Shortcut_AddProfileLink [Shortcut] [Username] [Userid]
# User can choose to disable it (POL_Config : PROFILE_LINK set to FALSE).
AUTHOR="$2"
if [ "$(POL_Config_Read "PROFILE_LINK")" != "FALSE" ]; then
POL_Shortcut_AddLink "$1" "PROFILEBUTTON/$(eval_gettext '$AUTHOR profile')" "http://www.$POL_DNS/en/profil-$(POL_Website_urlencode "$3").html?referer=$(POL_Website_urlencode "$1")"
fi
}
POL_LoadVar_Distro ()
{
if [ "$POL_OS" = "Linux" ] || [ "$POL_OS" == "FreeBSD" ]; then
export DISTRO="$(lsb_release -d | cut -d':' -f2 | tr -d \\t)"
else
main_kernel="$(uname -r | cut -d '.' -f 1)"
second_kernel="$(uname -r | cut -d '.' -f 2)"
[ "$main_kernel" = "8" ] && MacOS="Tiger"
[ "$main_kernel" = "9" ] && MacOS="Leopard"
[ "$main_kernel" = "10" ] && MacOS="Snow Leopard"
[ "$main_kernel" = "11" ] && MacOS="Lion"
[ "$main_kernel" = "12" ] && MacOS="Mountain Lion"
export DISTRO="$MacOS 10.$(( main_kernel - 4)).$second_kernel ($(uname -r))"
fi
}
POL_Shortcut_MakeDesktopShortcut()
{
PACKAGE="$1"
case "$POL_OS" in
Mac)
DIRAPP="$HOME/Desktop/$PACKAGE.app"
shortname="$(printf "$PACKAGE" | tr -c [[a-zA-Z0-9]] '_')"
make_skeleton "$PACKAGE"
make_icon "$PACKAGE"
make_pom_script "$PACKAGE"
make_plist "$PACKAGE" "$shortname"
;;
Linux|FreeBSD)
if [ -f "$POL_USER_ROOT/icones/full_size/$PACKAGE" ]; then
iconPath="$POL_USER_ROOT/icones/full_size/$PACKAGE"
else
# Default icon
iconPath="$PLAYONLINUX/etc/playonlinux.png"
fi
# http://stackoverflow.com/questions/8939580/bash-split-a-string-exactly-like-readline-would-split-it
eval set -- $(grep '^POL_Wine ' "$POL_USER_ROOT/shortcuts/$PACKAGE"|tail -n 1)
local binary="$2"
make_desktop_shortcut "$iconPath" "$PACKAGE" "$DESKTOP" "$PLAYONLINUX/playonlinux --run \"$PACKAGE\"" "$binary" ""
;;
*)
POL_Debug_Warning "POL_Shortcut_MakeDesktopShortcut: not supported OS: $POL_OS"
esac
}
POL_System_is32bit()
{
# Check if the file (1) is a 32bit executable
file "$1" | grep -q "PE32 executable"
}
POL_System_is64bit()
{
# Check if the file (1) is a 64bit executable
file "$1" | grep -q "PE32+ executable"
}
|