File yuga-firstboot-gnome of Package branding-Yuga

#!/bin/bash

# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Copyright 2024 SUSE LLC
# SPDX-FileCopyrightText: Copyright 2024 Richard Brown
# SPDX-FileCopyrightText: Copyright 2024 Raymond Yip

installFlatpakRepo(){
        /usr/bin/flatpak remote-add --user --if-not-exists flathub /usr/share/yuga/flathub.flatpakrepo
        if [ "$?" != 0 ] ; then
                zenity --error \
                --text="Adding Flathub Repo Failed"
                exit 1
        fi
}

installFlatpakPackage(){
    /usr/bin/flatpak install --user --noninteractive flathub $1
    if [ "$?" != 0 ] ; then
            zenity --error \
            --text="Installing $1 Failed"
            exit 1
    fi
}

waitforNet(){
until /usr/bin/curl -s --max-time 5 https://flathub.org > /dev/null; do sleep 1; done
}

defaultOptions() {
    pkgs=("org.mozilla.firefox" "org.gnome.Calculator" "org.gnome.TextEditor")
}

customizeOptions() {
    #User has decided to customize their installed flatpaks
    selection=$(zenity --list --width=1000  --height=1025 --title="Choose software to install" \
    --text="Select which software you would like to install\nMore software can be found in the <b>Software</b> App" \
    --checklist --column="" --column="AppName" --column="Application" --column="Description" \
    --hide-column=2 \
TRUE org.mozilla.firefox "Mozilla Firefox" "Default Web Browser" \
TRUE org.gnome.Calculator "Calculator" "Basic Calculator" \
TRUE org.gnome.TextEditor "Text Editor" "Basic Text Editor" \
FALSE com.mattjakeman.ExtensionManager "Extension Manager" "Shell Extensions Manager" \
FALSE com.github.tchx84.Flatseal "Flatseal" "Application Permissions Manager" \
FALSE com.valvesoftware.Steam "Steam" "Steam Games Launcher" \
FALSE org.gnome.Loupe "Image Viewer" "Basic Image Viewer" \
FALSE org.gnome.gThumb "gThumb" "Advanced Image Viewer" \
FALSE io.github.celluloid_player.Celluloid "Celluloid" "Basic Video Player" \
FALSE org.videolan.VLC "VLC" "Advanced Video Player" \
FALSE org.mozilla.Thunderbird "Thunderbird" "Mail Client" \
FALSE org.telegram.desktop "Telegram Desktop" "Telegram Messaging Client" \
FALSE org.libreoffice.LibreOffice "LibreOffice" "LibreOffice Office Suite" \
FALSE org.gimp.GIMP "GNU Image Manipulation Program" "Image Editor" \
FALSE org.gnome.Builder "Builder" "Graphical IDE" \
FALSE io.github.dvlv.boxbuddyrs "BoxBuddy" "Distrobox Container Manager" \
FALSE org.gnome.Boxes "Boxes" "Virtualisation" \
FALSE org.gnome.World.PikaBackup "Pika Backup" "Basic Backup Tool" \
FALSE org.gnome.SimpleScan "Document Scanner" "Basic Document Scanner" \
)
    #the above command outputs pipe-delimeted lists of all the flathub app names people chose..eg
    #org.mozilla.firefox|org.gnome.Calculator|org.gnome.TextEditor|com.github.tchx84.Flatseal|com.valvesoftware.Steam|org.telegram.desktop
    #So that could be parsed to figure out the number of apps chosen and fed into flatpak —user —noninteractive flathub and allow people to pick what they install on first boot
    if [[ -z "${selection}" ]]; then
        #if cancel is pressed, $custom variable is empty so we go back to use the default options
        defaultOptions
    else
        IFS='|' read -a pkgs <<< "$selection" 
    fi
}

firstMSG() {
    #Insert Welcome message here
    zenity --question --icon=distributor-logo-steamos --no-wrap --title 'Welcome to Yuga Linux' \
      --text 'Almost done, there is one last step\n\nWe need to download some applications to get you started\n\nYou can add more software later using the <b>Software</b> App' \
      --width 300 --height 300 \
      --ok-label OK \
      --cancel-label Customise
    option=$?
    if [ "$option" != 0 ]; then
        #User wants to customize software
        customizeOptions
    else
        #OK Button selected, running with defaults
        defaultOptions
    fi
}

lastMSG() {
    #Insert Welcome message here
    zenity --info --icon=distributor-logo-steamos --no-wrap --title 'Welcome to Yuga Linux' \
      --text 'Congratulations!\n\nYour system is ready to be used\n\nWe hope you enjoy using <b>Yuga Linux</b>' \
      --width 300 --height 300
    rm ~/.config/autostart/yuga-firstboot.desktop
}

detectLocale() {
    if [[ ! "${LANG}" =~ ^en_ ]]; then
    need_locale=${LANG}
    fi

}

select_language() {
    languages=(
        "aa_DJ.UTF-8" "Afar" "(Djibouti)"
        "af_ZA.UTF-8" "Afrikaans" "(South Africa)"
        "an_ES.UTF-8" "Aragonese" "(Spain)"
        "ar_AE.UTF-8" "Arabic" "(U.A.E)"
        "ar_BH.UTF-8" "Arabic" "(Bahrain)"
        "ar_DZ.UTF-8" "Arabic" "(Algeria)"
        "ar_EG.UTF-8" "Arabic" "(Egypt)"
        "ar_IQ.UTF-8" "Arabic" "(Iraq)"
        "ar_JO.UTF-8" "Arabic" "(Jordan)"
        "ar_KW.UTF-8" "Arabic" "(Kuwait)"
        "ar_LB.UTF-8" "Arabic" "(Lebanon)"
        "ar_LY.UTF-8" "Arabic" "(Libya)"
        "ar_MA.UTF-8" "Arabic" "(Morocco)"
        "ar_OM.UTF-8" "Arabic" "(Oman)"
        "ar_QA.UTF-8" "Arabic" "(Qatar)"
        "ar_SA.UTF-8" "Arabic" "(Saudi Arabia)"
        "ar_SD.UTF-8" "Arabic" "(Sudan)"
        "ar_SY.UTF-8" "Arabic" "(Syria)"
        "ar_TN.UTF-8" "Arabic" "(Tunisia)"
        "ar_YE.UTF-8" "Arabic" "(Yemen)"
        "ast_ES.UTF-8" "Asturian" "(Spain)"
        "be_BY.UTF-8" "Belarusian" "(Belarus)"
        "bg_BG.UTF-8" "Bulgarian" "(Bulgaria)"
        "bhb_IN.UTF-8" "Bhojpuri" "(India)"
        "br_FR.UTF-8" "Breton" "(France)"
        "bs_BA.UTF-8" "Bosnian" "(Bosnia and Herzegovina)"
        "ca_AD.UTF-8" "Catalan" "(Andorra)"
        "ca_ES.UTF-8" "Catalan" "(Spain)"
        "ca_FR.UTF-8" "Catalan" "(France)"
        "ca_IT.UTF-8" "Catalan" "(Italy)"
        "cs_CZ.UTF-8" "Czech" "(Czech Republic)"
        "cy_GB.UTF-8" "Welsh" "(United Kingdom)"
        "da_DK.UTF-8" "Danish" "(Denmark)"
        "de_AT.UTF-8" "German" "(Austria)"
        "de_BE.UTF-8" "German" "(Belgium)"
        "de_CH.UTF-8" "German" "(Switzerland)"
        "de_DE.UTF-8" "German" "(Germany)"
        "de_IT.UTF-8" "German" "(Italy)"
        "de_LI.UTF-8" "German" "(Liechtenstein)"
        "de_LU.UTF-8" "German" "(Luxembourg)"
        "el_CY.UTF-8" "Greek" "(Cyprus)"
        "el_GR.UTF-8" "Greek" "(Greece)"
        "en_AU.UTF-8" "English" "(Australia)"
        "en_BW.UTF-8" "English" "(Botswana)"
        "en_CA.UTF-8" "English" "(Canada)"
        "en_DK.UTF-8" "English" "(Denmark)"
        "en_GB.UTF-8" "English" "(United Kingdom)"
        "en_HK.UTF-8" "English" "(Hong Kong)"
        "en_IE.UTF-8" "English" "(Ireland)"
        "en_NZ.UTF-8" "English" "(New Zealand)"
        "en_PH.UTF-8" "English" "(Philippines)"
        "en_SC.UTF-8" "English" "(Seychelles)"
        "en_SG.UTF-8" "English" "(Singapore)"
        "en_US.UTF-8" "English" "(United States)"
        "en_ZA.UTF-8" "English" "(South Africa)"
        "en_ZW.UTF-8" "English" "(Zimbabwe)"
        "es_AR.UTF-8" "Spanish" "(Argentina)"
        "es_BO.UTF-8" "Spanish" "(Bolivia)"
        "es_CL.UTF-8" "Spanish" "(Chile)"
        "es_CO.UTF-8" "Spanish" "(Colombia)"
        "es_CR.UTF-8" "Spanish" "(Costa Rica)"
        "es_DO.UTF-8" "Spanish" "(Dominican Republic)"
        "es_EC.UTF-8" "Spanish" "(Ecuador)"
        "es_ES.UTF-8" "Spanish" "(Spain)"
        "es_GT.UTF-8" "Spanish" "(Guatemala)"
        "es_HN.UTF-8" "Spanish" "(Honduras)"
        "es_MX.UTF-8" "Spanish" "(Mexico)"
        "es_NI.UTF-8" "Spanish" "(Nicaragua)"
        "es_PA.UTF-8" "Spanish" "(Panama)"
        "es_PE.UTF-8" "Spanish" "(Peru)"
        "es_PR.UTF-8" "Spanish" "(Puerto Rico)"
        "es_PY.UTF-8" "Spanish" "(Paraguay)"
        "es_SV.UTF-8" "Spanish" "(El Salvador)"
        "es_US.UTF-8" "Spanish" "(United States)"
        "es_UY.UTF-8" "Spanish" "(Uruguay)"
        "es_VE.UTF-8" "Spanish" "(Venezuela)"
        "et_EE.UTF-8" "Estonian" "(Estonia)"
        "eu_ES.UTF-8" "Basque" "(Spain)"
        "fi_FI.UTF-8" "Finnish" "(Finland)"
        "fo_FO.UTF-8" "Faroese" "(Faroe Islands)"
        "fr_BE.UTF-8" "French" "(Belgium)"
        "fr_CA.UTF-8" "French" "(Canada)"
        "fr_CH.UTF-8" "French" "(Switzerland)"
        "fr_FR.UTF-8" "French" "(France)"
        "fr_LU.UTF-8" "French" "(Luxembourg)"
        "ga_IE.UTF-8" "Irish" "(Ireland)"
        "gd_GB.UTF-8" "Scottish Gaelic" "(United Kingdom)"
        "gl_ES.UTF-8" "Galician" "(Spain)"
        "gv_GB.UTF-8" "Manx" "(United Kingdom)"
        "he_IL.UTF-8" "Hebrew" "(Israel)"
        "hr_HR.UTF-8" "Croatian" "(Croatia)"
        "hsb_DE.UTF-8" "Upper Sorbian" "(Germany)"
        "hu_HU.UTF-8" "Hungarian" "(Hungary)"
        "id_ID.UTF-8" "Indonesian" "(Indonesia)"
        "is_IS.UTF-8" "Icelandic" "(Iceland)"
        "it_CH.UTF-8" "Italian" "(Switzerland)"
        "it_IT.UTF-8" "Italian" "(Italy)"
        "ja_JP.UTF-8" "Japanese" "(Japan)"
        "ka_GE.UTF-8" "Georgian" "(Georgia)"
        "kk_KZ.UTF-8" "Kazakh" "(Kazakhstan)"
        "kl_GL.UTF-8" "Kalaallisut" "(Greenland)"
        "ko_KR.UTF-8" "Korean" "(South Korea)"
        "ku_TR.UTF-8" "Kurdish" "(Turkey)"
        "kw_GB.UTF-8" "Cornish" "(United Kingdom)"
        "lg_UG.UTF-8" "Ganda" "(Uganda)"
        "lt_LT.UTF-8" "Lithuanian" "(Lithuania)"
        "lv_LV.UTF-8" "Latvian" "(Latvia)"
        "mg_MG.UTF-8" "Malagasy" "(Madagascar)"
        "mi_NZ.UTF-8" "Maori" "(New Zealand)"
        "mk_MK.UTF-8" "Macedonian" "(North Macedonia)"
        "ms_MY.UTF-8" "Malay" "(Malaysia)"
        "mt_MT.UTF-8" "Maltese" "(Malta)"
        "nb_NO.UTF-8" "Norwegian Bokmål" "(Norway)"
        "nl_BE.UTF-8" "Dutch" "(Belgium)"
        "nl_NL.UTF-8" "Dutch" "(Netherlands)"
        "nn_NO.UTF-8" "Norwegian Nynorsk" "(Norway)"
        "no_NO.UTF-8" "Norwegian" "(Norway)"
        "oc_FR.UTF-8" "Occitan" "(France)"
        "om_KE.UTF-8" "Oromo" "(Kenya)"
        "pl_PL.UTF-8" "Polish" "(Poland)"
        "pt_BR.UTF-8" "Portuguese" "(Brazil)"
        "pt_PT.UTF-8" "Portuguese" "(Portugal)"
        "ro_RO.UTF-8" "Romanian" "(Romania)"
        "ru_RU.UTF-8" "Russian" "(Russia)"
        "ru_UA.UTF-8" "Russian" "(Ukraine)"
        "sk_SK.UTF-8" "Slovak" "(Slovakia)"
        "sl_SI.UTF-8" "Slovenian" "(Slovenia)"
        "so_DJ.UTF-8" "Somali" "(Djibouti)"
        "so_KE.UTF-8" "Somali" "(Kenya)"
        "so_SO.UTF-8" "Somali" "(Somalia)"
        "sq_AL.UTF-8" "Albanian" "(Albania)"
        "st_ZA.UTF-8" "Southern Sotho" "(South Africa)"
        "sv_FI.UTF-8" "Swedish" "(Finland)"
        "sv_SE.UTF-8" "Swedish" "(Sweden)"
        "tcy_IN.UTF-8" "Tulu" "(India)"
        "tg_TJ.UTF-8" "Tajik" "(Tajikistan)"
        "th_TH.UTF-8" "Thai" "(Thailand)"
        "tl_PH.UTF-8" "Tagalog" "(Philippines)"
        "tr_CY.UTF-8" "Turkish" "(Cyprus)"
        "tr_TR.UTF-8" "Turkish" "(Turkey)"
        "uk_UA.UTF-8" "Ukrainian" "(Ukraine)"
        "uz_UZ.UTF-8" "Uzbek" "(Uzbekistan)"
        "wa_BE.UTF-8" "Walloon" "(Belgium)"
        "xh_ZA.UTF-8" "Xhosa" "(South Africa)"
        "yi_US.UTF-8" "Yiddish" "(United States)"
        "zh_CN.UTF-8" "Chinese" "(China)"
        "zh_HK.UTF-8" "Chinese" "(Hong Kong)"
        "zh_SG.UTF-8" "Chinese" "(Singapore)"
        "zh_TW.UTF-8" "Chinese" "(Taiwan)"
        "zu_ZA.UTF-8" "Zulu" "(South Africa)"
    )

    lang_options=()
    for ((i=0; i<${#languages[@]}; i+=3)); do
        lang_options+=("${languages[i]}" "${languages[i+1]}" "${languages[i+2]}")
    done

    selected_language=$(zenity --list --radiolist --title "Select Language" --width=600 --height=400 --column "Select" --column "Language" --column "Region" "${lang_options[@]}")
    if [ -n "$selected_language" ]; then
        echo "Setting language to $selected_language"
        echo "export LANG=$selected_language" >> ~/.bashrc
        export LANG=$selected_language
        need_locale=$selected_language
    fi
}

show_progress() {
    (
    sleep 1
    echo "# Waiting for Internet connection"
    waitforNet
    while /usr/bin/pgrep -f '/usr/bin/flatpak|/usr/sbin/transactional-update|/usr/bin/pkexec' >/dev/null; do
    echo "# Installing Packages"
    sleep 1
    done
    )| zenity --progress --title="Final Setup" --width=300 --pulsate --auto-close --no-cancel
}

install_locale() {
    pkexec /usr/bin/yuga-set-language "${need_locale}"
    if [ "$?" != 0 ] ; then
            zenity --error \
            --text="Installing Locales Failed"
            exit 1
    fi

    xdg-user-dirs-update --force
}

run_tasks() {
    waitforNet
    if [[ -n "${need_locale}" ]]; then
       install_locale &
    fi
    installFlatpakRepo
    for pkg in "${pkgs[@]}"; do 
        installFlatpakPackage $pkg &
    done
}

gio set ~/Desktop/org.valve.gamescope.desktop metadata::trusted true

detectLocale
firstMSG
select_language
run_tasks &
show_progress
lastMSG
openSUSE Build Service is sponsored by