Skip to content

Commit

Permalink
Merge pull request #592 from d-loose/no-refresh-on-loading
Browse files Browse the repository at this point in the history
feat(bootstrap): don't check for updates in `_initInstallerApp`
  • Loading branch information
d-loose authored and GitHub Actions committed Apr 5, 2024
2 parents bf41bd2 + 3f5a9d6 commit 8e11dce
Show file tree
Hide file tree
Showing 14 changed files with 593 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/ubuntu_bootstrap/lib/installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ Future<void> _initInstallerApp(Endpoint endpoint) async {
final services = [
getService<InstallerService>().init(),
tryGetService<DesktopService>()?.inhibit() ?? Future.value(),
getService<RefreshService>().check(),
getService<PageConfigService>().load(),
geo.init(),
telemetry.init({
Expand Down
11 changes: 1 addition & 10 deletions packages/ubuntu_bootstrap/lib/installer/installer_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,25 @@ final restartProvider = StateProvider((_) => 0);
final installerModelProvider = ChangeNotifierProvider.autoDispose(
(_) => InstallerModel(
getService<InstallerService>(),
getService<RefreshService>(),
),
);

class InstallerModel extends SafeChangeNotifier {
InstallerModel(this._installer, this._refresh);
InstallerModel(this._installer);

final InstallerService _installer;
final RefreshService _refresh;

ApplicationStatus? _status;
StreamSubscription<ApplicationStatus?>? _statusChange;
StreamSubscription<RefreshState>? _refreshChange;

ApplicationStatus? get status => _status;
bool get isInstalling => status?.isInstalling ?? false;
bool get isRefreshing => _refresh.state.busy;

Future<void> init() async {
_statusChange = _installer.monitorStatus().listen((status) {
_status = status;
notifyListeners();
});
_refreshChange = _refresh.stateChanged.listen((_) {
notifyListeners();
});
}

bool hasRoute(String route) => _installer.hasRoute(route);
Expand All @@ -44,8 +37,6 @@ class InstallerModel extends SafeChangeNotifier {
Future<void> dispose() async {
await _statusChange?.cancel();
_statusChange = null;
await _refreshChange?.cancel();
_refreshChange = null;
super.dispose();
}
}
13 changes: 2 additions & 11 deletions packages/ubuntu_bootstrap/test/installer_model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,31 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:subiquity_client/subiquity_client.dart';
import 'package:ubuntu_bootstrap/installer/installer_model.dart';
import 'package:ubuntu_bootstrap/services/refresh_service.dart';

import 'test_utils.dart';

void main() {
test('init', () async {
final statusController = StreamController<ApplicationStatus>();
final refreshController = StreamController<RefreshState>();

final installer = MockInstallerService();
when(installer.monitorStatus()).thenAnswer((_) => statusController.stream);

final refresh = MockRefreshService();
when(refresh.state).thenReturn(const RefreshState.checking());
when(refresh.stateChanged).thenAnswer((_) => refreshController.stream);

final model = InstallerModel(installer, refresh);
final model = InstallerModel(installer);
await model.init();
verify(installer.monitorStatus()).called(1);
expect(statusController.hasListener, isTrue);
verify(refresh.stateChanged).called(1);
expect(refreshController.hasListener, isTrue);

await model.dispose();
expect(statusController.hasListener, isFalse);
expect(refreshController.hasListener, isFalse);
});

test('has route', () async {
final installer = MockInstallerService();
when(installer.hasRoute('a')).thenReturn(true);
when(installer.hasRoute('b')).thenReturn(false);

final model = InstallerModel(installer, MockRefreshService());
final model = InstallerModel(installer);

expect(model.hasRoute('a'), isTrue);
expect(model.hasRoute('b'), isFalse);
Expand Down
50 changes: 50 additions & 0 deletions snap/local/launcher
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

source "$SNAP_USER_DATA/.last_revision" 2>/dev/null || true
if [ "$SNAP_DESKTOP_LAST_REVISION" = "$SNAP_REVISION" ]; then
needs_update=false
else
needs_update=true
fi

if [ "$SNAP_ARCH" = "amd64" ]; then
ARCH="x86_64-linux-gnu"
elif [ "$SNAP_ARCH" = "armhf" ]; then
ARCH="arm-linux-gnueabihf"
elif [ "$SNAP_ARCH" = "arm64" ]; then
ARCH="aarch64-linux-gnu"
elif [ "$SNAP_ARCH" = "ppc64el" ]; then
ARCH="powerpc64le-linux-gnu"
else
ARCH="$SNAP_ARCH-linux-gnu"
fi

# Set cache folder to local path
export XDG_CACHE_HOME="$SNAP_USER_COMMON/.cache"
[ -d "$XDG_CACHE_HOME" ] || mkdir -p "$XDG_CACHE_HOME"

# Workaround for flickering corners and other graphical glitches with GTK's
# OpenGL backend for X11. See:
# - https://github.com/canonical/ubuntu-desktop-installer/issues/1397
# - https://gitlab.gnome.org/GNOME/gtk/-/issues/5600
export GDK_RENDERING=image

export GDK_PIXBUF_MODULE_FILE="$XDG_CACHE_HOME/gdk-pixbuf-loaders.cache"
export GDK_PIXBUF_MODULEDIR="$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/2.10.0/loaders"
if [ "$needs_update" = true ] || [ ! -f "$GDK_PIXBUF_MODULE_FILE" ]; then
rm -f "$GDK_PIXBUF_MODULE_FILE"
if [ -f "$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders" ]; then
$SNAP/usr/lib/$ARCH/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders > "$GDK_PIXBUF_MODULE_FILE"
fi
fi

[ "$needs_update" = true ] && echo "SNAP_DESKTOP_LAST_REVISION=$SNAP_REVISION" > "$SNAP_USER_DATA/.last_revision"

# Disable storage automounting (/usr/lib/udisks2/udisks2-inhibit)
sudo mkdir -p /run/udev/rules.d
sudo sh -c 'echo "SUBSYSTEM==\"block\", ENV{UDISKS_IGNORE}=\"1\"" > /run/udev/rules.d/90-udisks-inhibit.rules'
trap "sudo rm -f /run/udev/rules.d/90-udisks-inhibit.rules; sudo udevadm control --reload; sudo udevadm trigger --subsystem-match=block" EXIT HUP INT QUIT ILL ABRT FPE KILL SEGV PIPE ALRM TERM BUS
sudo udevadm control --reload
sudo udevadm trigger --subsystem-match=block

"$@"
97 changes: 97 additions & 0 deletions snap/local/postinst.d/10_configure_auto_login
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
set -e

installer_conf=/tmp/ubuntu_desktop_installer.conf

if ! source $installer_conf 2>/dev/null || [ -z "$AutoLoginUser" ]; then
exit
fi

USER=$AutoLoginUser
ROOT=/target
chroot=chroot
BACKUP=

# Adapted from https://git.launchpad.net/ubiquity/tree/d-i/source/user-setup/user-setup-apply

if [ -d "$ROOT/etc/gdm3" ]; then
# Configure GDM autologin
GDMCustomFile=$ROOT/etc/gdm3/custom.conf
if [ -e "$GDMCustomFile" ] && [ "$BACKUP" ]; then
cp "$GDMCustomFile" "${GDMCustomFile}$BACKUP"
fi
AutologinParameters="AutomaticLoginEnable=true\n\
AutomaticLogin=$USER\n"

# Prevent from updating if parameters already present (persistent usb key)
if ! `grep -qs "AutomaticLogin=$USER" $GDMCustomFile` ; then
if [ -e "$GDMCustomFile" ]; then
sed -i '/\(Automatic\)Login/d' $GDMCustomFile
fi
if ! `grep -qs '\[daemon\]' $GDMCustomFile` ; then
echo '[daemon]' >> $GDMCustomFile
fi
sed -i "s/\[daemon\]/\[daemon\]\n$AutologinParameters/" $GDMCustomFile
fi
fi

if $chroot $ROOT [ -f /etc/kde4/kdm/kdmrc ]; then
# Configure KDM autologin
$chroot $ROOT sed -i$BACKUP -r \
-e "s/^#?AutoLoginEnable=.*\$/AutoLoginEnable=true/" \
-e "s/^#?AutoLoginUser=.*\$/AutoLoginUser=$USER/" \
-e "s/^#?AutoReLogin=.*\$/AutoReLogin=true/" \
/etc/kde4/kdm/kdmrc
fi

if $chroot $ROOT [ -f /etc/lxdm/lxdm.conf ]; then
# Configure LXDM autologin with LXDE session
$chroot $ROOT sed -i$BACKUP -r \
-e "s/^# autologin=dgod/autologin=$USER/" \
-e "s/^# session/session/" \
/etc/lxdm/lxdm.conf
fi

if $chroot $ROOT [ -f /etc/xdg/lubuntu/lxdm/lxdm.conf ]; then
# Configure LXDM autologin with Lubuntu session
$chroot $ROOT sed -i$BACKUP -r \
-e "s/^# autologin=dgod/autologin=$USER/" \
-e "s/^# session/session/" \
-e "s/startlxde/startlubuntu/" \
/etc/xdg/lubuntu/lxdm/lxdm.conf
fi

if $chroot $ROOT [ -f /usr/bin/sddm ]; then
# Configure SDDM autologin with an appropiate session
$chroot $ROOT /bin/sh -c "cat > /etc/sddm.conf" << EOF
[Autologin]
User=$USER
Session=PLACEHOLDER
EOF
if $chroot $ROOT [ -f /usr/share/xsessions/plasma.desktop ]; then
sed -i 's/PLACEHOLDER/plasma.desktop/' $ROOT/etc/sddm.conf
elif $chroot $ROOT [ -f /usr/share/xsessions/Lubuntu.desktop ]; then
sed -i 's/PLACEHOLDER/Lubuntu.desktop/' $ROOT/etc/sddm.conf
elif $chroot $ROOT [ -f /usr/share/xsessions/lxqt.desktop ]; then
sed -i 's/PLACEHOLDER/lxqt.desktop/' $ROOT/etc/sddm.conf
else #fallback if some other DE/WM is used
SDDMSESSION=$(ls /usr/share/xsessions | head -1)
sed -i "s/PLACEHOLDER/$SDDMSESSION/" $ROOT/etc/sddm.conf
fi
fi
if $chroot $ROOT [ -d /etc/lightdm ]; then
# Configure LightDM autologin
LightDMCustomFile=$ROOT/etc/lightdm/lightdm.conf
AutologinParameters="autologin-guest=false\n\
autologin-user=$USER\n\
autologin-user-timeout=0"
if ! grep -qs '^autologin-user' $LightDMCustomFile; then
if ! grep -qs '^\[Seat:\*\]' $LightDMCustomFile; then
echo '[Seat:*]' >> $LightDMCustomFile
fi
sed -i "s/\[Seat:\*\]/\[Seat:\*\]\n$AutologinParameters/" $LightDMCustomFile
#oem config scenario
else
sed -i "s/^\(\(str *\)\?autologin-user\)=.*$/\1=$USER/g;" $ROOT/etc/lightdm/lightdm.conf
fi
fi
11 changes: 11 additions & 0 deletions snap/local/postinst.d/10_copy_bluetooth_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e

target=/target
source_bluetooth=/var/lib/bluetooth
target_bluetooth=$target/$source_bluetooth

if [ -d $source_bluetooth ]; then
rm -rf $target_bluetooth
cp -a $source_bluetooth $target_bluetooth
fi
17 changes: 17 additions & 0 deletions snap/local/postinst.d/10_copy_network_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e

target=/target
source_nm=/etc/NetworkManager/system-connections
target_nm=$target/$source_nm

if [ -d $source_nm ] && [ -d $target_nm ]; then
cp -anr $source_nm/. $target_nm
fi

source_netplan=/etc/netplan
target_netplan=$target/$source_netplan

if [ -d $source_netplan ] && [ -d $target_netplan ]; then
cp -anr $source_netplan/90-NM-* $target_netplan
fi
11 changes: 11 additions & 0 deletions snap/local/postinst.d/10_flash_kernel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
set -e
# Currently curtin doesn't call flash-kernel after installing kernel
# and generating initrd, but we need it on arm64
# and we need to update-grub after flash-kernel installed dtb
if [ -e /target/usr/sbin/flash-kernel ]; then
FK_FORCE=yes $SNAP/bin/subiquity/bin/subiquity-cmd curtin in-target -t /target -- flash-kernel
fi
if [ -e /target/usr/sbin/update-grub ]; then
$SNAP/bin/subiquity/bin/subiquity-cmd curtin in-target -t /target -- update-grub
fi
28 changes: 28 additions & 0 deletions snap/local/postinst.d/10_override_desktop_settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
set -e

user=ubuntu
target=/target
source_schemas=/usr/share/glib-2.0/schemas
target_schemas=$target/$source_schemas

if [ ! -d $source_schemas ] || [ ! -d $target_schemas ] || ! id $user >/dev/null 2>&1; then
exit
fi

dconf_dump() {
target_schema=$target_schemas/20_ubuntu-desktop-installer-$1.gschema.override
sudo -u $user dconf dump /org/gnome/desktop/$1/ > $target_schema
# - [foo] -> [org.gnome.desktop.$1.foo:ubuntu]
sed -i -E "s/^\[([^/]*)\]/\[org.gnome.desktop.$1.\1:ubuntu\]/g" $target_schema
# - [/] -> [org.gnome.desktop.$1:ubuntu]
sed -i -E "s/^\[\/\]$/\[org.gnome.desktop.$1:ubuntu\]/g" $target_schema
[ -s $target_schema ] || rm $target_schema
}

dconf_dump a11y
dconf_dump interface
dconf_dump peripherals
dconf_dump wm

glib-compile-schemas $target_schemas
36 changes: 36 additions & 0 deletions snap/local/postinst.d/50_zfs_cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

# Provide a workaround so that ubuntu-desktop-installer does not
# recreate LP: #1993318

TARGET=/target

for pool in $(zpool list -H | cut -f1); do
zpool set cachefile= "${pool}"
if [ ! -d "/etc/zfs/zfs-list.cache" ] ; then
mkdir -p "/etc/zfs/zfs-list.cache"
fi
if [ ! -d "${TARGET}/etc/zfs/zfs-list.cache" ] ; then
mkdir -p "${TARGET}/etc/zfs/zfs-list.cache"
fi
# Force cache generation
: >"/etc/zfs/zfs-list.cache/${pool}"
# Execute zfs-list-cacher with a manual fake event
env -i \
ZEVENT_POOL=${pool} \
ZED_ZEDLET_DIR=/etc/zfs/zed.d \
ZEVENT_SUBCLASS=history_event \
ZFS=zfs \
ZEVENT_HISTORY_INTERNAL_NAME=create \
/etc/zfs/zed.d/history_event-zfs-list-cacher.sh
# ZFS list doesn't honor target prefix for chroots for
# the mountpoint property
# https://github.com/openzfs/zfs/issues/1078
# Drop leading /target from all mountpoint fields
sed -E "s|\t${TARGET}/?|\t/|g" "/etc/zfs/zfs-list.cache/${pool}" \
> "${TARGET}/etc/zfs/zfs-list.cache/${pool}"
# Ensure installer system doesn't generate mount units
rm -f "/etc/zfs/zfs-list.cache/${pool}"
done


23 changes: 23 additions & 0 deletions snap/local/postinst.d/99_telemetry_done
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

telemetry=/var/log/installer/telemetry

if [ ! -f $telemetry ]; then
exit
fi

current_time=$(date +%s)
created_at=$(stat --format %W $telemetry)
duration=$(($current_time - $created_at))

# {
# ...
# "Stages": {
# "0": "welcome",
# ...
# "1234": "done" // <==
# }
# }

jq ".Stages.\"$duration\"=\"done\"" $telemetry > $telemetry.tmp
mv $telemetry.tmp $telemetry

0 comments on commit 8e11dce

Please sign in to comment.