This file is indexed.

/usr/share/session-migration/scripts/unity-gnome-shell-migration.17.10.py is in ubuntu-session 3.28.1-0ubuntu2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
#!/usr/bin/python3

from gi.repository import Gio
import os
import sys


UNITY_LAUNCHER_SETTINGS = "com.canonical.Unity.Launcher"
UNITY_LAUNCHER_FAVORITE_KEY = "favorites"
UNITY_APP_PREFIX = "application://"

GNOME_DASH_SETTINGS = "org.gnome.shell"
GNOME_DASH_FAVORITE_KEY = "favorite-apps"

UNITY_COMPIZ_LAUNCHER_SETTINGS = "org.compiz.unityshell"
UNITY_COMPIZ_LAUNCHER_SETTINGS_PATH = "/org/compiz/profiles/unity/plugins/unityshell/"

DOCK_SETTINGS = "org.gnome.shell.extensions.dash-to-dock"

def get_default_gnome_shell_favorites():
    settings = Gio.Settings.new(GNOME_DASH_SETTINGS)
    settings.delay()
    settings.reset(GNOME_DASH_FAVORITE_KEY)
    return settings.get_strv(GNOME_DASH_FAVORITE_KEY)


def get_default_launcher_property(property):
    settings = Gio.Settings.new_with_path(UNITY_COMPIZ_LAUNCHER_SETTINGS, UNITY_COMPIZ_LAUNCHER_SETTINGS_PATH)
    settings.delay()
    settings.reset(property)
    return settings.get_int(property)


def migrate_unity_launchers():

    gs_settings = Gio.Settings.new(GNOME_DASH_SETTINGS)
    if not gs_settings.is_writable(GNOME_DASH_FAVORITE_KEY):
        print("Can't migrate unity keys to GNOME Shell as they are not writable")
        return
    gs_favorites = gs_settings.get_strv(GNOME_DASH_FAVORITE_KEY)

    if gs_favorites != get_default_gnome_shell_favorites():
        print("Migration prevented as GNOME Shell launchers are modified from defaults")
        return

    unity_settings = Gio.Settings.new(UNITY_LAUNCHER_SETTINGS)
    unity_favorites = unity_settings.get_strv(UNITY_LAUNCHER_FAVORITE_KEY)

    new_favorites = []
    for fav in unity_favorites:
        if not fav.startswith(UNITY_APP_PREFIX):
            continue
        # change from u-c-c
        if fav == UNITY_APP_PREFIX + "unity-control-center.desktop":
            fav = UNITY_APP_PREFIX + "gnome-control-center.desktop"
        new_favorites.append(fav[len(UNITY_APP_PREFIX):])
    
    # we replace with unity existing keys
    gs_settings.set_strv(GNOME_DASH_FAVORITE_KEY, new_favorites)
    gs_settings.sync() # force sync to avoid race


def migrate_launcher_properties():
    unity_settings = Gio.Settings.new_with_path(UNITY_COMPIZ_LAUNCHER_SETTINGS, UNITY_COMPIZ_LAUNCHER_SETTINGS_PATH)
    dock_settings = Gio.Settings.new(DOCK_SETTINGS)

    intellihide = unity_settings.get_int("launcher-hide-mode")
    if intellihide == 1 and intellihide != get_default_launcher_property("launcher-hide-mode"):
        dock_settings.set_boolean("dock-fixed", False)

    icon_size = unity_settings.get_int("icon-size")
    if icon_size != get_default_launcher_property("icon-size"):
        dock_settings.set_int("dash-max-icon-size", icon_size)
    
    launcher_placement = unity_settings.get_int("num-launchers")
    if launcher_placement != get_default_launcher_property("num-launchers"):
        if launcher_placement == 0:
            dock_settings.set_boolean("multi-monitor", "True")
        else:
            dock_settings.set_int("preferred-monitor", launcher_placement - 1)
    dock_settings.sync() # force sync to avoid race


def reset_rhythmbox_plugins():
    '''We had a glib bug for list plugins, people installing 17.10 beta or before
    were reset to default non override defaults, if this is the case, reset them
    again.
    '''
    source = Gio.SettingsSchemaSource.get_default()
    if (source.lookup("org.gnome.rhythmbox.plugins", True) is None):
        print("Don't reset Rhythmbox key as not installed")
        return
    rh_settings = Gio.Settings.new("org.gnome.rhythmbox.plugins")
    if not rh_settings.is_writable("active-plugins"):
        print("Can't reset Rhythmbox key as not writable")
        return
    # only migrate if default system values were set
    if rh_settings.get_strv("active-plugins") != ['power-manager', 'generic-player', 'android', 'audiocd', 'iradio', 'mmkeys']:
        return
    rh_settings.reset("active-plugins")
    rh_settings.sync()


if __name__ == "__main__":
    source = Gio.SettingsSchemaSource.get_default()
    # Unity or GS not installed
    if (source.lookup(UNITY_LAUNCHER_SETTINGS, True) is None or
        source.lookup(UNITY_COMPIZ_LAUNCHER_SETTINGS, True) is None or
        source.lookup(GNOME_DASH_SETTINGS, True) is None):
        print("Unity or GNOME Shell not installed: no migration needed")
        sys.exit(0)

    migrate_unity_launchers()
    migrate_launcher_properties()
    reset_rhythmbox_plugins()