Skip to content

Commit

Permalink
Keep /etc/localtime and /etc/timezone synchronized with the host
Browse files Browse the repository at this point in the history
The permission of $XDG_RUNTIME_DIR/.flatpak-helper/monitor needs to be
relaxed [1] for this work in some corner cases. However, it already
works for the vast majority of cases when used as $USER or root inside
the toolbox container.

[1] flatpak/flatpak#2916

https://github.com/debarshiray/toolbox/issues/70
  • Loading branch information
debarshiray committed May 22, 2019
1 parent 34cc27a commit 8db414d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,17 @@ create()
max_minus_uid=$((max_uid_count - user_id_real))
uid_plus_one=$((user_id_real + 1))

echo "$base_toolbox_command: calling org.freedesktop.Flatpak.SessionHelper.RequestSession" >&3

if ! gdbus call \
--session \
--dest org.freedesktop.Flatpak \
--object-path /org/freedesktop/Flatpak/SessionHelper \
--method org.freedesktop.Flatpak.SessionHelper.RequestSession >/dev/null 2>&3; then
echo "$base_toolbox_command: failed to call org.freedesktop.Flatpak.SessionHelper.RequestSession" >&2
exit 1
fi

echo "$base_toolbox_command: trying to create container $toolbox_container" >&3

if spinner_directory=$(mktemp --directory --tmpdir $spinner_template 2>&3); then
Expand Down Expand Up @@ -763,6 +774,7 @@ create()
$toolbox_profile_bind \
--volume "$HOME":"$HOME":rslave \
--volume "$XDG_RUNTIME_DIR":"$XDG_RUNTIME_DIR" \
--volume "$XDG_RUNTIME_DIR"/.flatpak-helper/monitor:/run/host/monitor \
--volume "$dbus_system_bus_path":"$dbus_system_bus_path" \
--volume /etc:/run/host/etc \
--volume /dev/bus:/dev/bus \
Expand Down Expand Up @@ -832,6 +844,16 @@ init_container()
fi
fi

if ! localtime_target=$(readlink /etc/localtime >/dev/null 2>&3) \
|| [ "$localtime_target" != "/run/host/monitor/localtime" ] 2>&3; then
if ! (cd /etc 2>&3 \
&& unlink localtime 2>&3 \
&& ln --symbolic /run/host/monitor/localtime localtime 2>&3); then
echo "$base_toolbox_command: failed to redirect /etc/localtime to /run/host/monitor/localtime" >&2
return 1
fi
fi

if ! readlink /etc/resolv.conf >/dev/null 2>&3; then
if ! (cd /etc 2>&3 \
&& unlink resolv.conf 2>&3 \
Expand All @@ -841,6 +863,15 @@ init_container()
fi
fi

if ! readlink /etc/timezone >/dev/null 2>&3; then
if ! (cd /etc 2>&3 \
&& rm --force timezone 2>&3 \
&& ln --symbolic /run/host/monitor/timezone timezone 2>&3); then
echo "$base_toolbox_command: failed to redirect /etc/timezone to /run/host/monitor/timezone" >&2
return 1
fi
fi

if ! cd "$working_directory" 2>&3; then
echo "$base_toolbox_command: failed to restore working directory" >&2
fi
Expand Down Expand Up @@ -996,6 +1027,17 @@ run()
fi
fi

echo "$base_toolbox_command: calling org.freedesktop.Flatpak.SessionHelper.RequestSession" >&3

if ! gdbus call \
--session \
--dest org.freedesktop.Flatpak \
--object-path /org/freedesktop/Flatpak/SessionHelper \
--method org.freedesktop.Flatpak.SessionHelper.RequestSession >/dev/null 2>&3; then
echo "$base_toolbox_command: failed to call org.freedesktop.Flatpak.SessionHelper.RequestSession" >&2
exit 1
fi

echo "$base_toolbox_command: trying to start container $toolbox_container" >&3

if ! $prefix_sudo podman start "$toolbox_container" >/dev/null 2>&3; then
Expand Down

0 comments on commit 8db414d

Please sign in to comment.