File yuga-firstboot-kde of Package branding-Yuga

#!/bin/bash

# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Copyright 2024 Tobias Görgens

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

installFlatpakPackage(){
    /usr/bin/flatpak install --user --noninteractive flathub $1
    if [ "$?" != 0 ] ; then
        kdialog --error "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.kde.kcalc")
}

customizeOptions() {
    selection=$(kdialog --geometry 600x400 --checklist "Choose software to install" \
    org.mozilla.firefox "Mozilla Firefox" on \
    org.kde.kcalc "KCalc" on \
    org.kde.kwrite "KWrite" off \
    com.github.tchx84.Flatseal "Flatseal" off \
    org.kde.gwenview "Gwenview" off \
    org.kde.krita "Krita" off \
    org.kde.kdenlive "Kdenlive" off \
    io.github.celluloid_player.Celluloid "Celluloid" off \
    org.videolan.VLC "VLC" off \
    org.mozilla.Thunderbird "Thunderbird" off \
    org.telegram.desktop "Telegram Desktop" off \
    org.libreoffice.LibreOffice "LibreOffice" off \
    org.gimp.GIMP "GNU Image Manipulation Program" off \
    org.kde.kate "Kate" off \
    io.github.dvlv.boxbuddyrs "BoxBuddy" off \
    org.kde.kbackup "KBackup" off \
    org.kde.skanlite "Skanlite" off)

    if [[ -z "${selection}" ]]; then
        defaultOptions
    else
        pkgs=($(echo "$selection" | sed 's/\"//g' | sed 's/ /\n/g' | awk '{print $1}'))
    fi
}

firstMSG() {
    kdialog --geometry 600x400 --title 'Welcome to Yuga Linux' \
      --yesnocancel '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 Discover App' \
      --yes-label OK \
      --no-label Customise \
      --cancel-label Exit

    option=$?
    if [ "$option" == 2 ]; then
        exit 0
    elif [ "$option" == 1 ]; then
        customizeOptions
    else
        defaultOptions
    fi
}

lastMSG() {
    kdialog --geometry 600x400 --msgbox 'Congratulations!\n\nYour system is ready to be used\n\nWe hope you enjoy using Yuga Linux' --title 'Welcome to Yuga Linux'
    rm ~/.config/autostart/yuga-firstboot.desktop
}

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

show_progress() {
    local step="$1"
    local label="$2"

    qdbus6 $dbusRef setLabelText "$label"
    qdbus6 $dbusRef Set "" value "$step"
}

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+=2)); do
        lang_options+=("${languages[i]}" "${languages[i+1]}" off)
    done

    selected_language=$(kdialog --geometry 600x400 --radiolist "Choose your preferred language" "${lang_options[@]}" | awk '{print $1}')
    if [ -n "$selected_language" ]; then
        echo "Setting language to $selected_language"
        echo "export LANG=$selected_language" >> ~/.bashrc
        export LANG=$selected_language
        if [ -f ~/.config/plasma-localerc ]; then
            sed -i "/^LANG=/c\LANG=$selected_language" ~/.config/plasma-localerc
            sed -i "/^LANGUAGE=/c\LANGUAGE=${selected_language%.*}" ~/.config/plasma-localerc
        fi
        key_var="${selected_language#\"}"
        cat > ~/.config/kxkbrc <<EOF
[Layout]
LayoutList=${key_var%_*}
Use=true
EOF
        need_locale=$selected_language
    fi
}

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

    xdg-user-dirs-update --force
}

run_tasks() {
    dbusRef=$(kdialog --title "Final Setup" --geometry 600x400 --progressbar "Final Setup" 100)
    show_progress 10 "Waiting for Internet connection"
    waitforNet

    show_progress 30 "Installing Locales"
    if [[ -n "${need_locale}" ]]; then
       install_locale
    fi

    show_progress 50 "Adding Flathub"
    installFlatpakRepo

    show_progress 70 "Installing packages"
    for pkg in "${pkgs[@]}"; do
        echo $pkg
        installFlatpakPackage $pkg
    done

    show_progress 100 "Installation complete"
    qdbus6 $dbusRef close
}

detectLocale
firstMSG
select_language
run_tasks
lastMSG
openSUSE Build Service is sponsored by