-
Notifications
You must be signed in to change notification settings - Fork 1
/
winestarter_extract
executable file
·138 lines (134 loc) · 5.31 KB
/
winestarter_extract
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
#! /bin/bash
## License:
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
## You can redistribute it as you wish : GPL v3
## author : wildtruc@noneltd.net
temp_list=$(mktemp --tmpdir ex_list.XXX)
## comment the line below if using script as wine package extrator only and uncomment the second one.
[[ -d $HOME'/.winebin' ]]|| exit 0
if [[ $wine_bin == '' ]]; then wine_bin=$(find /usr/{bin,local/bin} -name wine); fi
export wine_version=$($wine_bin --version| \
sed -En "s/^(.*)( [\(]?(\w*)[\)]?)$/\1-\l\3/g;p"| sed -En "s/^.*-([0-9].*)$/\1/p")
if ! [[ $wine_version =~ staging ]]; then wine_version=$wine_version'-stable'; fi
[[ $wine_version ]]|| ( echo -e "# Wine is not installed. Abort."; exit 0; )
bin_dir=$HOME'/.winebin'
def_dir=$(pwd)
def_elf=$(uname -p)
if [[ $def_elf =~ 64 ]]; then _elf='64'; def_sys='amd64'; else _elf=''; def_sys='x86'; fi
we_bin=( msidb msiexec notepad regedit regsvr32 widl wine wine$_elf wine-preloader \
wine$_elf-preloader wineboot winebuild winecfg wineconsole winedbg winedump winefile winecpp \
wineg++ winegcc winemaker winemine winepath wineserver wineserver$_elf wmc wrc )
## define and find all files.
alt_bin='bin,local/bin'
alt_dir=$(find /usr/{lib,lib64,share} -maxdepth 2 -name "wine*" -type d)
alt_lib=$(find -P /usr/{lib,lib64} -maxdepth 2 -name "libwine*" -type f)
alt_share=$(find -P /usr/share -maxdepth 2 -name "wine*" -type f)
echo -e "$alt_dir\n$alt_lib\n$alt_share" >> $temp_list
## extract 'bin' dir content.
unset pack_bin
for wordkey in "${we_bin[@]}"; do
[ -d $bin_dir/$def_sys/$wine_version/bin/ ]|| mkdir -p $bin_dir/$def_sys/$wine_version/bin/
pack_bin=( $(bash -c "find /usr/{$alt_bin} -name $wordkey") )
for line in "${pack_bin[@]}"; do
if [[ -e $line && ! -d $line ]]; then
_bin_key=$(echo -e "$line"| sed -n "s/^.*\///g;p")
if [[ -x $line ]]; then
if [[ ! -h $line ]]; then
_elf_key=$(file $line | cut -d',' -f1| sed -En "s/^.*([0-9]{2}).*$/\1/g;p")
if [[ $_elf_key =~ [0-9]{2}|script ]]; then
if [[ $_elf_key != 32 ]]; then
if [[ $(echo "$_bin_key"| grep -c "wine$\|wine-preloader$") -gt 0 \
&& $(echo -e "$_bin_key"| grep -c "64") -eq 0 ]]; then
_suff='64'
else
_suff=''
fi
if [ $(echo "$_bin_key"| grep -c "wine-preloader$") -gt 0 ]; then
_bin="wine$_suff-preloader"
else
_bin=$_bin_key$_suff
fi
else
_bin=$_bin_key
fi
if [[ $prev_key != '' ]] \
&& [ $(echo "$_bin_key"| grep -oc "$prev_key") -gt 0 ] \
&& [ $(diff -q $prev_path $line| grep -c .) -eq 0 ]; then
cd $bin_dir/$def_sys/$wine_version/bin/
ln -sf $prev_key $_bin
cd $def_dir
else
cp -f $line $bin_dir/$def_sys/$wine_version/bin/$_bin
fi
prev_path=$bin_dir/$def_sys/$wine_version/bin/$_bin
fi
else
if [ $(file $line | grep -c "link") -gt 0 ]; then
link_id=$(file $line | sed -En "s/^.* (.*)$/\1/g;p")
if [[ $link_id =~ ^\.\.\/ ]]; then link_id=$(echo "$link_id"| sed -En "s/^\.\./\/usr/p"); fi
if [[ $(diff -q $prev_path $link_id | grep -c .) -gt 0 ]]; then
if [[ $prev_key != '' \
&& $(echo "$_bin_key"| grep -oc "$prev_key") -gt 0 \
&& $(diff -q $prev_path $line| grep -c .) -eq 0 ]]; then
cd $bin_dir/$def_sys/$wine_version/bin/
ln -sf $prev_key $_bin_key
cd $def_dir
else
if ! [[ -x $bin_dir/$def_sys/$wine_version/bin/$_bin_key ]]; then
cp -f $line $bin_dir/$def_sys/$wine_version/bin/
fi
fi
else
cp -f $line $bin_dir/$def_sys/$wine_version/bin/
fi
prev_path=$bin_dir/$def_sys/$wine_version/bin/$_bin_key
fi
fi
fi
prev_key=$_bin_key
fi
done
done
## extract 'lib' & 'share' dir content.
unset pack_libs
pack_libs=( $(echo -e "$alt_dir\n$alt_lib\n$alt_share"| tr '\n' '#'| sed -En "s/#/ /g;p" ) )
for line in "${pack_libs[@]}"; do
dir_to=lib
if [[ $line =~ lib.*64 ]]; then dir_to=lib64 ; fi
if [[ $line =~ share ]]; then
dir_to=share
if [[ $line =~ share\/doc ]]; then dir_to=share/doc ; fi
if [[ $line =~ share\/appli* ]]; then dir_to=share/applications ; fi
if [[ $line =~ share\/wine\/ ]]; then dir_to=share/wine ; fi
fi
if ! [ -d $bin_dir/$def_sys/$wine_version/$dir_to/ ]; then mkdir -p $bin_dir/$def_sys/$wine_version/$dir_to/; fi
cp -Rf $line $bin_dir/$def_sys/$wine_version/$dir_to/
if [[ $line =~ libwine.so.1.0 ]]; then
cd $bin_dir/$def_sys/$wine_version/$dir_to/
ln -sf libwine.so.1.0 libwine.so.1
ln -sf libwine.so.1 libwine.so.0
cd $def_dir
fi
done
## create symlink for 32 bits dirs if any.
if [[ $def_sys == amd64 ]]; then
[ -d $bin_dir/x86/ ]|| mkdir -p $bin_dir/x86/
cd $bin_dir/x86/
ln -sf ../$def_sys/$wine_version $wine_version
fi
## get out.
exit 0