aboutsummarylogtreecommitdiffstats
path: root/wechat-universal.sh
blob: 57d10f1b00e009d6f5f2c234895ab08aaccb6852 (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
#!/bin/bash

MOUNTS=(
	/etc/os-release=/usr/share/wechat-universal/etc/os-release
	/etc/lsb-release=/usr/share/wechat-universal/etc/lsb-release
	/usr/lib/license=/usr/share/wechat-universal/usr/lib/license
	/var=/usr/share/wechat-universal/var
)

coproc mounter {
	read -r session_pid || return $?
	exec 0<&-

	# mount as "root" via nsenter
	for mount in "${MOUNTS[@]}"; do # quit on error without writing to stdout
		nsenter -U -m --target $session_pid mount "${mount#*=}" "${mount%=*}" -o rbind || return $?
	done
	# signal that mounts are setup
	echo $?
}

exec {out}>>/dev/fd/${mounter[1]} {in}</dev/fd/${mounter[0]}

exec unshare --mount --user --map-user=$(id -u) --map-group=$(id -g) --map-users=auto --map-groups=auto --keep-caps --setgroups allow /bin/bash --noprofile --norc -c "echo \$\$ >&${out} && exec ${out}>&- || exit \$? ; read -u ${in} && exec ${in}<&- && \"\$@\" ; exit $?" unshare /opt/wechat-universal/wechat
exit $?