aboutsummaryrefslogtreecommitdiff
blob: a1ae82354cfe41f65c981374ec87d22e42d5d0a7 (plain)
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
# -*-eselect-*-  vim: ft=eselect
# Copyright 2005-2017 Gentoo Foundation
# Distributed under the terms of the GNU GPL version 2 or later

inherit config multilib tests

DESCRIPTION="Manage active wine version"
MAINTAINER="NP-Hardass@gentoo.org"

CONFIG_DIR="/etc/eselect/wine"

VARIANTS=(
	vanilla
	staging
	d3d9
	any
)

################################################################################
#                               Eselect Wine                                   #
################################################################################

# Verify that files exist for specified target
# Input: ${P}
is_valid_target(){
	if [[ $# -ne 1 ]]; then
		die "Invalid number of parameters"
	fi
	
	local tgt="$1"

	set_dir_env	

	if [[ ! -d "${wine_bin}" ]] || \
		[[ ! "$(ls -A ${wine_bin})" ]] || \
		[[ ! -e "${wine_bin}/wine" ]]; then
		return 1
	elif [[ ! -e "${EPREFIX}/usr/bin/${tgt}" ]]; then
		return 1
	else
		return 0
	fi

	unset_dir_env
}

# Verify that symlinks are valid
are_symlinks_valid() {
	if [[ $# -gt 1 ]]; then
		die "Invalid number of parameters"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die "Invalid variant"
			fi
		else
			die "Invalid parameter"
		fi
		shift
	done

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	local active=$(get_active ${v_arg})
	local tgt="${active}"
	if [[ "${active}" == "(unset)" ]]; then
		write_error_message "Invalid active config"
		return 1
	fi

	set_dir_env

	local possible_vars=( bin man include )
	local symlink_vars=$(load_config "${CONFIG_DIR}/links/${v}" symlink_dirs)
	if [[ -z "${symlink_vars}" ]]; then
		write_error_msg "Missing any configured symlink_dirs"
		return 1
	fi
	local var

	for var in ${possible_vars[@]}; do
		if has ${var} ${symlink_vars[@]}; then
			symlink_vars=$(list_rm_item "${var}" "${symlink_vars}")
		else
			write_warning_message "Missing '${var}' in ${v} config"
			write_warning_message "Might want to re-run set or update"
		fi
	done
	if [[ ! -z ${symlink_vars} ]]; then
		write_error_msg "Config contains unknown symlink_dirs ${symlink_vars}"
		return 1
	fi

	symlink_vars=$(load_config "${CONFIG_DIR}/links/${v}" symlink_dirs)
	for var in ${symlink_vars[@]}; do
		local symlinks=$(load_config "${CONFIG_DIR}/links/${v}" ${var})
		local symlink

		if [[ -z "${symlinks}" ]]; then
			die -q "Missing listing of ${var} symlinks"
		fi
		for symlink in ${symlinks[@]}; do
			if [[ ! -L ${symlink} ]]; then
				write_error_msg "${symlink} is not a symlink"
				return 1
			else
				local file=$(canonicalise ${symlink})
				if [[ ! -e "${file}" ]]; then
					write_error_msg "${symlink} points to nonexistant ${file}"
					return 1
				# Handle bin separately because symlinks don't go to wine_${var}
				elif [[ "${var}" == "bin" ]]; then
					local path="${symlink%${v_arg#-}}${tgt#wine}"
					if [[ "${file}" != "${path}" ]]; then
						write_error_msg "${symlink} points to ${file}"
						write_error_msg "which doesn't appear to be the proper link"
						return 1
					fi
				else
					local path=wine_${var}
					path=${!path}
					path=$(canonicalise "${path}")
					if [[ "${file}" != "${path%/}"/* ]]; then
						write_error_msg "${symlink} points to ${file}"
						write_error_msg "which doesn't appear to be part of wine"
						return 1
					fi
				fi
			fi
		done
	done

	unset_dir_env
}


# print currently selected wine
get_active() {
	if [[ $# -gt 1 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid variant"
			fi
		else
			[[ -z $1 ]] || die -q "Invalid parameter"
		fi
		shift
	done

	local active=$(load_config "${CONFIG_DIR}/active" ${v})

	if [[ -z "${active}" ]]; then
		echo "(unset)"
	else
		echo "${active}"
	fi
}

get_installed(){
	if [[ $# -gt 1 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid variant"
			fi
		else
			die -q "Invalid parameter"
		fi
		shift
	done

	local installed=$(load_config "${CONFIG_DIR}/installed" ${v})

	echo $(sort_list ${installed[@]})
}

### Registration action ##
describe_register(){
	echo "Register a new package with the eselect module (Internal use only)"
}

describe_register_parameters() {
	echo "<target>"
}

describe_register_options() {
	for v in ${VARIANTS[@]}; do
		echo "--${v} : Register a new package with ${v}"
	done
	echo "target : A fully qualified variant e.g."
	echo " :	wine-1.9.23, wine-vanilla-2.0, or wine-staging-2.1.1" 
}

do_register(){
	if [[ $# -lt 1 ]] || [[ $# -gt 3 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid flag or variant"
			fi
		else
			local tgt="$1"
		fi
		shift
	done

	if [[ -z "${tgt}" ]]; then
		die -q "Target not specified"
	fi

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	if is_number "${tgt}"; then
		local tgts=($(get_installed ${v_arg}))
		tgt=${tgts[${tgt}-1]}
	fi

	if ! is_valid_target "${tgt}"; then
		die -q "Target does not exist"
	fi

	local list=$(get_installed ${v_arg})

	if ! has ${tgt} ${list}; then
		list=($(sort_list "${list} ${tgt}"))
		store_config "${CONFIG_DIR}/installed" ${v} "${list[@]}"
	fi
}

describe_deregister(){
	echo "Deregister a package with the eselect module (Internal use only)"
}

describe_deregister_parameters() {
	echo "<target>"
}

describe_deregister_options() {
	for v in ${VARIANTS[@]}; do
		echo "--${v} : Deregister a package with ${v}"
	done
	echo "--force : Forcibly remove a package"
	echo "target : A fully qualified variant e.g."
	echo " :	wine-1.9.23, wine-vanilla-2.0, or wine-staging-2.1.1" 
}

do_deregister(){
	if [[ $# -lt 1 ]] || [[ $# -gt 3 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"
	local force=false

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			elif [[ "${flag}" == "force" ]]; then
				force=true
			else
				die -q "Invalid variant"
			fi
		else
			local tgt="$1"
		fi
		shift
	done

	if [[ -z "${tgt}" ]]; then
		die -q "Target not specified"
	fi

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	if is_number "${tgt}"; then
		local tgts=($(get_installed ${v_arg}))
		tgt=${tgts[${tgt}-1]}
	fi

	if ! is_valid_target "${tgt}" && [[ ${force} == "false" ]]; then
		die -q "Target does not exist"
	fi

	local list=$(get_installed ${v_arg})

	if ! has ${tgt} ${list}; then
		die -q "${tgt} is not registered for ${v}"
	fi

	if [[ "${tgt}" == "$(get_active ${v_arg})" ]]; then
		do_unset ${v_arg}
	fi

	list=$(list_rm_item ${tgt} "${list}")
	store_config "${CONFIG_DIR}/installed" ${v} "${list}"
}

### list action ###

describe_list() {
	echo "List available wine versions"
}

describe_list_options() {
	for v in ${VARIANTS[@]}; do
		echo "--${v} : List the available 'wine-${v}'"
	done
}

do_list() {
	if [[ $# -gt 1 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid variant"
			fi
		else
			die -q "Invalid parameter"
		fi
		shift
	done

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	write_list_start "Available wine${v_arg#-} versions:"
	local installed=($(get_installed ${v_arg}))
	local active=$(get_active ${v_arg})

	if [[ ${#installed} -eq 0 ]]; then
		unset installed
	else
		for (( i = 0; i < ${#installed[@]}; i++ )); do
			if [[ ${installed[i]} = ${active} ]]; then
				installed[i]=$(highlight_marker "${installed[i]}")
			fi
		done
	fi

	write_numbered_list -m "(none found)" "${installed[@]}"
}

### show action ###

describe_show() {
	echo "Show the active wine version"
}

describe_show_options() {
	for v in ${VARIANTS[@]}; do
		echo "--$v : Show the active 'wine-$v'"
	done
}

do_show() {
	if [[ $# -gt 1 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid variant"
			fi
		else
			die -q "Invalid parameter"
		fi
		shift
	done

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	write_list_start "Active wine${v_arg#-} version:"
	local active=$(get_active ${v_arg})

	write_kv_list_entry "${active}" ""
	if [[ "${active}" != "(unset)" ]]; then
		are_symlinks_valid ${v_arg}
	fi
}

### unset action ###

describe_unset() {
	echo "Remove wine symlinks"
}

describe_unset_options() {
	for v in ${VARIANTS[@]}; do
		echo "--$v : Remove the 'wine-$v' symlinks"
	done
	echo "--all : Unset active wine and all variants"
}

do_unset() {
	if [[ $# -gt 1 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"
	local all=false

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			elif [[ "${flag}" == "all" ]]; then
				all=true
			else
				die -q "Invalid variant"
			fi
		else
			die -q "Invalid parameter"
		fi
		shift
	done

	# Run do_unset for all variants
	if ${all}; then
		do_unset
		for v in ${VARIANTS[@]}; do
			do_unset "--${v}"
		done

		return 0
	fi

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	remove_symlinks ${v_arg} || die -q "Couldn't remove wine${v_arg#-} symlinks"

	store_config "${CONFIG_DIR}/active" "${v}" ""
}

### set action ###

describe_set() {
	echo "Set a new wine version"
}

describe_set_parameters() {
	echo "<target>"
}

describe_set_options() {
	for v in ${VARIANTS[@]}; do
		echo "--$v : Set only the 'wine-$v' symlinks"
	done
	echo "target : Target name or number (from 'list' action)"
}

do_set() {
	if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid flag or variant"
			fi
		else
			local tgt="$1"
		fi
		shift
	done

	if [[ -z "${tgt}" ]]; then
		die -q "Target not specified"
	fi

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	if is_number "${tgt}"; then
		local tgts=($(get_installed ${v_arg}))
		tgt=${tgts[${tgt}-1]}
	fi

	if ! is_valid_target "${tgt}"; then
		die -q "Target does not exist"
	fi

	do_unset ${v_arg} || die -q "Failed to unset active target"
	set_symlinks ${v_arg} "${tgt}" || die -q "Couldn't set wine-${v_arg#-} symlinks"

	store_config "${CONFIG_DIR}/active" "${v}" "${tgt}"
}

### update action ###

describe_update() {
	echo "Set highest version installed active"
}

describe_update_options() {
	for v in ${VARIANTS[@]}; do
		echo "--$v : Update the 'wine-$v' symlinks"
	done
	echo "--all : Update main active wine and all variants"
	echo "--if-unset : Reuse currently selected version if it appears valid"
}

do_update() {
	if [[ $# -gt 3 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"
	local if_unset=false
	local all=false

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			elif [[ "${flag}" == "if-unset" ]]; then
				if_unset=true
			elif [[ "${flag}" == "all" ]]; then
				all=true
			else
				die -q "Invalid flag or variant"
			fi
		else
			die -q "Invalid parameter"
		fi
		shift
	done

	if [[ "${v}" != "wine" ]] && ${all}; then
		die -q "Either specify a specific variant, or all, but not both"
	fi

	# Run do_update for all variants
	if ${all}; then
		local unset_arg
		if ${if_unset}; then
			unset_arg="--if-unset"
		fi

		do_update ${unset_arg}
		for v in ${VARIANTS[@]}; do
			do_update "--${v}" ${unset_arg}
		done

		return 0
	fi

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	# Determine if set and valid
	# If so, return
	if ${if_unset}; then
		local active=$(get_active ${v_arg})
		if is_valid_target "${active}" && are_symlinks_valid ${v_arg}; then
			return 0
		fi
	fi

	local installed=($(get_installed ${v_arg}))
	if [[ ${#installed[@]} -eq 0 ]]; then
		write_warning_msg "Skipping wine${v_arg#-}. No registered targets found."
		return 0
	fi
	local tgt=${installed[-1]}

	do_set ${v_arg} "${tgt}" || die -q "Couldn't set new wine${v_arg#-} symlinks"
}


# lifted from fdo-mime.eclass
desktop_database_update() {
	if [[ -x "${EPREFIX}/usr/bin/update-desktop-database" ]]; then
#		echo "Updating desktop mime database ..."
		"${EPREFIX}/usr/bin/update-desktop-database" -q "${EPREFIX}/usr/share/applications" || die
	fi
}

# sort function for versions, to be used in a pipe
sort_versions() {
	local vsort="sort --version-sort"
	# Test if our sort supports the --version-sort option (posix does)
	${vsort} </dev/null &>/dev/null || vsort=sort

	# We sort versions as follows:
	# 1. Run sed to prepend the version string by the numeric version
	#      1.7.21 wine-1.7.21
	#      1.7.14 wine-compholio-1.7.14
	# 2. sort --version-sort
	# 3. Run sed again to remove the prepended keys from step 1.
	sed -e 's/^\(.\+-\)\([[:digit:].]*\)$/\2 &/' \
		| LC_ALL=C ${vsort} | sed 's/.* //'
}

# Takes a list of items and returns a sorted version
sort_list() {
	list=($@)
	if [[ ! -z "${list}" ]]; then
		for i in ${list[@]}; do
			echo "${i}"
		done | sort_versions
	fi
}

# Returns a list excluding the specified item
# list_rm_item [rm_this] [list]
list_rm_item() {
	if [[ $# -lt 2 ]]; then
		die "Not enough arguments"
	fi

	rm_this=$1
	shift
	list=($@)

	local i
	for i in ${!list[@]};do
	    if [ "${list[$i]}" == "${rm_this}" ]; then
	        unset list[$i]
	    fi 
	done

	echo ${list[@]}
}

remove_symlinks() {
	if [[ $# -gt 1 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid flag or variant"
			fi
		else
			die -q "Invalid parameter"
		fi
		shift
	done

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	local symlink_vars=$(load_config "${CONFIG_DIR}/links/${v}" symlink_dirs)
	if [[ -z "${symlink_vars}" ]]; then
		return 0
	fi
	local var
	for var in ${symlink_vars[@]}; do
		local symlinks=$(load_config "${CONFIG_DIR}/links/${v}" ${var})
		local symlink
		if [[ -z "${symlinks}" ]]; then
			die -q "Missing listing of ${var} symlinks"
		fi
		for symlink in ${symlinks[@]}; do
			if [[ -e "${symlink}"  ]]; then
				if [[ ! -L "${symlink}" ]]; then
					die -q "${symlink} is not a symlink."
				fi
				rm "${symlink}" || die "Failed to rm ${symlink}"
			else
				write_warning_msg "${symlink} symlink was missing."
			fi
			
			# remove entry from config file
			symlinks=$(list_rm_item "${symlink}" "${symlinks}")
		done
		store_config "${CONFIG_DIR}/links/${v}" ${var} "${symlinks}"

		# remove set from config file
		symlink_vars=$(list_rm_item "${var}" "${symlink_vars}")

		store_config "${CONFIG_DIR}/links/${v}" symlink_dirs "${symlink_vars}"
	done

	# Remove active if it exists
	store_config "${CONFIG_DIR}/active" "${v}" ""

	local desktop="${EPREFIX}/usr/share/applications/wine${v_arg#-}.desktop"
	if [[ -e "${desktop}" ]]; then
		rm "${desktop}" || die "Failed ro remove desktop file"
	fi
	desktop_database_update || die "Failed to update xorg desktop database"
}

set_symlinks() {
	if [[ $# -lt 1 ]] || [[ $# -gt 2 ]]; then
		die -q "Invalid number of parameters specified"
	fi

	local v="wine"

	while [[ $# -gt 0 ]]; do
		if [[ $1 == --* ]]; then
			local flag="${1#--}"
			if has "${flag}" ${VARIANTS[@]}; then
				v=${flag}
			else
				die -q "Invalid flag or variant"
			fi
		else
			local tgt="$1"
		fi
		shift
	done

	if [[ -z "${tgt}" ]]; then
		die -q "Target not specified"
	fi

	local v_arg
	if [[ ${v} != "wine" ]]; then
		v_arg="--${v}"
	fi

	if is_number "${tgt}"; then
		local tgts=($(get_installed ${v_arg}))
		tgt=${tgts[${tgt}-1]}
	fi

	if ! is_valid_target "${tgt}"; then
		die -q "Target does not exist"
	fi

	set_dir_env

	local link
	local links
	(
	shopt -s failglob

	store_config "${CONFIG_DIR}/links/${v}" symlink_dirs "bin"
	store_config "${CONFIG_DIR}/links/${v}" "bin" ""
	for b in "${wine_bin}"/*; do
		link="${EPREFIX}/usr/bin/${b##*/}${v_arg#-}"
		local linktgt="${EPREFIX}/usr/bin/${b##*/}${tgt##wine}"
		if [[ -L "${link}" ]]; then
			write_warning_msg "${link} already exists, overwriting"
			rm "${link}" || die -q "Failed to rm old link: ${link}"
		fi
		ln -s "${linktgt}" "${link}"
		if [[ $? -ne 0 ]]; then
			write_warning_msg "Failed to set symlink from ${linktgt} to ${link}"
			write_warning_msg "Cleaning up"
			remove_symlinks ${v_arg}
		fi
		links="${links} ${link}"
	done
	store_config "${CONFIG_DIR}/links/${v}" "bin" "${links}"

	shopt -s globstar
	links=""
	append_config "${CONFIG_DIR}/links/${v}" symlink_dirs "man"
	store_config "${CONFIG_DIR}/links/${v}" "man" ""
	pushd "${wine_man}" > /dev/null
	for m in **/*.1; do
		link="${EPREFIX}/usr/share/man/${m}${v_arg#-}"
		if [[ -L "${link}" ]]; then
			write_warning_msg "${link} already exists, overwriting"
			rm "${link}" || die -q "Failed to rm old link: ${link}"
		fi
		mkdir -p "${link%/*}" || die -q "Failed to mkdir: ${link%/*}"
		ln -s "${wine_man}/${m}" "${link}"
		if [[ $? -ne 0 ]]; then
			write_warning_msg "Failed to set symlink from ${wine_man}/${m} to ${link}"
			write_warning_msg "Cleaning up"
			remove_symlinks ${v_arg}
		fi
		links="${links} ${link}"
	done
	append_config "${CONFIG_DIR}/links/${v}" "man" "${links}"
	popd > /dev/null

	append_config "${CONFIG_DIR}/links/${v}" symlink_dirs "include"
	store_config "${CONFIG_DIR}/links/${v}" "include" ""
	link="${EPREFIX}/usr/include/wine${v_arg#-}"
	local linktgt="${wine_include}"
	if [[ -L "${link}" ]]; then
		write_warning_msg "${link} already exists, overwriting"
		rm "${link}" || die -q "Failed to rm old link: ${link}"
	fi
	ln -s "${linktgt}" "${link}"
	if [[ $? -ne 0 ]]; then
		write_warning_msg "Failed to set symlink from ${linktgt} to ${link}"
		write_warning_msg "Cleaning up"
		remove_symlinks ${v_arg}
	fi
	store_config "${CONFIG_DIR}/links/${v}" "include" "${link}"


	local desktop="${EPREFIX}/usr/share/applications/wine${v_arg#-}.desktop"
	cp "${wine_app}/wine.desktop" "${desktop}" || die "Failed to copy desktop file"
	sed -i "s:Exec=.*:Exec=wine${v_arg#-} start /unix %f:" ${desktop} || die "Failed to edit desktop file"
	desktop_database_update || die "Failed to update xorg desktop database"

	)
	unset_dir_env
}

# set env vars for us to work with
set_dir_env() {
	wine_bin="${EPREFIX}/usr/lib/${tgt}/bin"
	wine_include="${EPREFIX}/usr/include/${tgt}/wine"
	wine_share="${EPREFIX}/usr/share/${tgt}"
	wine_app="${wine_share}/applications"
	wine_man="${wine_share}/man"
}

# unset our env vars
unset_dir_env() {
	unset wine_{bin,include,share,app,man}
}