#!/bin/bash if [ $EUID -ne 0 ]; then echo "This script must be run with super user privileges" exit 1 fi arch=`arch` if [ $arch != "x86_64" ]; then echo "Architecture is not supported" exit 1 fi if ! locale -a 2> /dev/null | grep ^ru_RU.utf8 &> /dev/null; then echo "Operating system does not meet the technical requirements (https://sbis.ru/help/plugin/sbis3plugin/requirements). Russian localization is required (ru_RU.utf8). Please contact your system administrator." exit 1 fi readonly INSTALL_FLAG_DIR="/usr/share/Sbis3Plugin/installer_flags" readonly INSTALL_FLAG_NAME="install_in_progress" mkdir -p $INSTALL_FLAG_DIR touch $INSTALL_FLAG_DIR/$INSTALL_FLAG_NAME readonly TMP_DIR_NAME='.'`tr -dc A-Za-z0-9 /dev/null & sleep 5 sudo $OWNER_TMPDIR -E -u $OWNER /opt/sbis3plugin/sbis3plugin install_done --app=$installed_configurations &>/dev/null & sleep 10 fi fi if [ -f $INSTALL_FLAG_DIR/$INSTALL_FLAG_NAME ]; then rm $INSTALL_FLAG_DIR/$INSTALL_FLAG_NAME fi rm -rf ./$TMP_DIR_NAME exit $1 } # example: try_wget [message] [wget_parameters] [skip_on_error] try_wget() { if (( $# == 0 )); then "Error downloading. Insufficient parameters"; custom_exit 1; fi if (( $# >= 1 )); then local link=$1; fi if (( $# >= 2 )); then local msg=$2; fi if (( $# >= 3 )); then local params=$3; fi skip_on_error=false if (( $# >= 4 )); then local skip_on_error=$4; fi if man wget | grep show-progress &> /dev/null; then local showprogress="--show-progress"; fi if [[ $msg != "" ]]; then echo "$msg"; fi wget $link $params -P ./$TMP_DIR_NAME -t 3 -T 60 -q $showprogress if [ $? -ne 0 ]; then if ! $skip_on_error; then echo "Error downloading $link..."; custom_exit 1; fi return 1 fi if [[ $msg != "" ]]; then echo "Done."; fi return 0 } get_last_build(){ python_vers='python' if ! python --version ;then python_vers='python3' fi try_wget "https://test-update.sbis.ru/Sbis3Plugin/Sbis3Plugin.json" "Getting Sbis3Plugin..." "" false readonly json_path=$TMP_DIR_NAME/Sbis3Plugin.json counter=-1 status='empty' build=" " right_status='active' readonly keys_sum=`sudo cat $json_path | $python_vers -c "import json,sys;obj=json.load(sys.stdin);print(len(obj.keys()))"` while [[ $status != $right_status ]] && [[ $counter < $keys_sum ]] do status=`sudo cat $json_path| $python_vers -c "import json,sys;obj=json.load(sys.stdin);dict_keys = sorted(obj.keys());print(obj[dict_keys["$counter"]]['status'])"` if [[ $status == "active" ]];then build=`sudo cat $json_path | $python_vers -c "import json,sys;obj=json.load(sys.stdin);dict_keys = sorted(obj.keys());print(dict_keys["$counter"])"` echo "last build:$build" break fi (( ++counter )) done } ASTRA_PACKAGES_URL=https://update.sbis.ru/Sbis3Plugin/astra_se/ MAIN_UPDATE_DOMAIN="update.sbis.ru" CUSTOM_UPDATE_DOMAIN="" IS_INSTALL_PLUGIN=true IS_INSTALL_ADDITIONS=false IS_INSTALL_SABYTEL=false i=1 while [ $i -le "$#" ]; do option=${!i} next_i=$((i+1)) next=${!next_i} if [ -n "$option" ] then case "$option" in -test) echo "Found the -test option" if [ -n "$next" ] then readonly build_type=`echo ${next/-/} | tr -cd . | wc -m` if [[ $build_type == 2 ]]; then UPDATE_URL=https://${option/-/}-update.sbis.ru/Sbis3Plugin/${next/-/}/linux ; else last_build=`get_last_build | grep "last build" | cut -d":" -f2` UPDATE_URL=https://${option/-/}-update.sbis.ru/Sbis3Plugin/${last_build}/linux fi i=$((i+1)) else echo "Enter the version number" custom_exit 1 fi ;; -fix) echo "Found the -fix option" if [ -n "$next" ] then UPDATE_URL=https://${option/-/}-update.sbis.ru/Sbis3Plugin/${next/-/}/linux ; i=$((i+1)) else echo "Enter the branch type" custom_exit 1 fi ;; -master) echo "Found the -master option" UPDATE_URL=https://update.sbis.ru/Sbis3Plugin/${option/-/}/linux ;; -rc) echo "Found the -rc option" UPDATE_URL=https://update.sbis.ru/Sbis3Plugin/${option/-/}/linux ;; -mirror) echo "Found -mirror option" UPDATE_URL=http://${next}/Sbis3Plugin/master/linux ASTRA_PACKAGES_URL=http://${next}/astra_se i=$((i+1)) ;; -plugin-full) echo "Found -plugin-full option" IS_INSTALL_PLUGIN=true IS_INSTALL_ADDITIONS=true IS_INSTALL_SABYTEL=false installed_configurations="plugin" ;; -plugin) echo "Found -plugin option" IS_INSTALL_PLUGIN=true IS_INSTALL_ADDITIONS=false IS_INSTALL_SABYTEL=false installed_configurations="plugin" ;; -sabyapps) echo "Found -sabyapps option" IS_INSTALL_PLUGIN=true IS_INSTALL_ADDITIONS=true IS_INSTALL_SABYTEL=true installed_configurations="plugin,saby_tel" ;; -sabytel) echo "Found -sabytel option" IS_INSTALL_PLUGIN=false IS_INSTALL_ADDITIONS=false IS_INSTALL_SABYTEL=true installed_configurations="saby_tel" ;; -update-domain) echo "Found -update-domain option" if [ -n "$next" ]; then CUSTOM_UPDATE_DOMAIN=$next i=$((i+1)) fi ;; *) echo "$option is not an update option" custom_exit 1 ;; esac fi i=$((i+1)) done if [ -z ${UPDATE_URL+x} ]; then UPDATE_URL=https://update.sbis.ru/Sbis3Plugin/master/linux fi if [ -n "$CUSTOM_UPDATE_DOMAIN" ]; then UPDATE_URL=`sed "s/${MAIN_UPDATE_DOMAIN}/${CUSTOM_UPDATE_DOMAIN}/g" <<< $UPDATE_URL` ASTRA_PACKAGES_URL=`sed "s/${MAIN_UPDATE_DOMAIN}/${CUSTOM_UPDATE_DOMAIN}/g" <<< $ASTRA_PACKAGES_URL` fi echo "Current download url: $UPDATE_URL" # Определяем конфигурацию OC, примеры содержимого файла /etc/os-release: # Centos: ID="centos", ID_LIKE="rhel fedora", VERSION="7 (Core)", VERSION_ID="7" # ubuntu22: ID="ubuntu", ID_LIKE="debian", VERSION="22.04 LTS(Jammy JellyFish)", VERSION_ID="22.04" # rosa: ID="rosa", ID_LIKE=нет поля , VERSION="12.2", VERSION_ID=2021.1 # ALT: ID="altlinux", ID_LIKE=нет поля, VERSION="10.0", VERSION_ID=10.0 # Astra 1.7SE: NAME="Astra Linux", ID=astra, ID_LIKE=debian, VERSION=нет поля, VERSION_ID=1.7_x86-64 # Astra 1.6SE: NAME="Astra Linux (Smolensk)", ID=astra, ID_LIKE=debian, VERSION=нет поля, VERSION_ID=1.6 grep "\(\\|\\)" /etc/os-release | grep debian IS_DEBIAN=$? grep "\(\\|\\)" /etc/os-release | grep ubuntu IS_UBUNTU=$? grep "\(\\|\\)" /etc/os-release | grep fedora IS_FEDORA=$? grep "\(\\|\\)" /etc/os-release | grep altlinux IS_ALTLINUX=$? grep "\(\\|\\)" /etc/os-release | grep opensuse IS_OPENSUSE=$? grep "\(\\)" /etc/os-release | grep "Astra Linux" IS_ASTRA_SE=$? grep "\(\\|\\)" /etc/os-release | grep rosa IS_ROSA_FRESH=$? function install_if_not_found { package_to_find=$1 echo -ne "Checking package $package_to_find... " is_installed=`dpkg -s $package_to_find 2>/dev/null | grep "Status: install ok installed"` if [ -z "$is_installed" ]; then echo "not found" for ((i=2; i<=$#; i++)); do package_to_install=${!i} try_wget $ASTRA_PACKAGES_URL/$package_to_install "Trying to download $package_to_install..." "" true if [ $? -eq 0 ]; then apt-get install ./$TMP_DIR_NAME/$package_to_install -y &> /dev/null if [ $? -eq 0 ]; then echo "Package $package_to_install installed successfully" return 0 fi fi done echo "Cannot install $package_to_find" else echo "OK" fi return 1 } function install_astra_packages { #Порядок установки ВАЖЕН! install_if_not_found "libnss3-tools" "libnss3-tools_3.49-1astra4_amd64.deb" "libnss3-tools_3.35.2-astra1_amd64.deb" install_if_not_found "libccid" "libccid_1.4.30-1_amd64.deb" "libccid_1.4.26-1_amd64.deb" install_if_not_found "libpcre16-3" "libpcre16-3_8.39-12_amd64.deb" "libpcre16-3_8.39-3_amd64.deb" install_if_not_found "gcr" "gcr_3.28.1-1_amd64.deb" "gcr_3.20.0-5.1_amd64.deb" install_if_not_found "libpcsclite1" "libpcsclite1_1.8.24-1_amd64.deb" "libpcsclite1_1.8.20-1_amd64.deb" install_if_not_found "pcscd" "pcscd_1.8.24-1_amd64.deb" "pcscd_1.8.20-1_amd64.deb" install_if_not_found "opensc-pkcs11" "opensc-pkcs11_0.19.0-1_amd64.deb" "opensc-pkcs11_0.16.0-3_amd64.deb" install_if_not_found "opensc" "opensc_0.19.0-1_amd64.deb" "opensc_0.16.0-3_amd64.deb" install_if_not_found "libxcb-xinerama0" "libxcb-xinerama0_1.14-2astra.se10_amd64.deb" "libxcb-xinerama0_1.13-1astra.se1_amd64.deb" } # check system version of libstdc++.so.6 function is_sbis_libstdcxx_required { lib_location=`whereis libstdc++.so.6 | head -n 1 | cut -d ' ' -f 2` [ ! -f "$lib_location" ] && echo "Library libstdc++.so.6 not found" && return 0 lib_version=`stat $lib_location | head -n 1 | sed -e 's/^[[:space:]]*//' | cut -d ' ' -f 4 | cut -d '.' -f 5 | sed 's/[^0-9]*//g'` [[ -z $lib_version ]] && echo "Library libstdc++.so.6 version not detected" && return 0 [ "$lib_version" -lt 30 ] && echo "Library libstdc++.so.6 version is less than required" && return 0 return 1 } # Возвращает 0, если пакет установлен, иначе не установлен function is_package_installed { package=$1 res=0 if [[ ${IS_FEDORA} -eq 0 ]] || [[ ${IS_ALTLINUX} -eq 0 ]] || [[ ${IS_OPENSUSE} -eq 0 ]] || [[ ${IS_ROSA_FRESH} -eq 0 ]]; then rpm -q $package &> /dev/null res=$? fi if [[ ${IS_DEBIAN} -eq 0 ]] || [[ ${IS_UBUNTU} -eq 0 ]]; then PKG_IS_INSTALLED=`dpkg -s \$1 2>/dev/null | grep "Status: install ok installed"` if [ -z "$PKG_IS_INSTALLED" ]; then res=1 else res=0 fi fi return $res } # получение версии системы без дробных долей function get_os_version { os_version="" if [ -f /etc/lsb-release -o -d /etc/lsb-release.d ]; then os_version=$(lsb_release -r | cut -d: -f2 | sed s/'^\t'// | cut -d'.' -f1) elif [ -f /etc/os-release ]; then os_version=$(grep "\" /etc/os-release | cut -d'=' -f2 | sed 's/[^0-9.]//g' | cut -d'.' -f1) fi echo $os_version } # восстановление ca-bundle.crt, если он был удален function check_ca_bundle { if [ ! -e /etc/pki/tls/certs/ca-bundle.crt ]; then # debian, ubuntu if [ -e /etc/ssl/certs/ca-certificates.crt ]; then mkdir -p /etc/pki/tls/certs/ ln -sf /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt echo "Восстановлен ca-bundle.crt (debian-based)" # opensuse elif [ -e /var/lib/ca-certificates/ca-bundle.pem ]; then mkdir -p /etc/pki/tls/certs/ ln -sf /var/lib/ca-certificates/ca-bundle.pem /etc/pki/tls/certs/ca-bundle.crt echo "Восстановлен ca-bundle.crt (opensuse)" # centos, redos elif [ -e /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem ]; then mkdir -p /etc/pki/tls/certs/ ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/pki/tls/certs/ca-bundle.crt echo "Восстановлен ca-bundle.crt (fedora-based)" fi fi } check_ca_bundle if [[ ${IS_FEDORA} -eq 0 ]] || [[ ${IS_ROSA_FRESH} -eq 0 ]]; then if is_package_installed "sbis3plugin"; then if ! is_package_installed "saby-minimal-core"; then echo "Removing old SBIS Plugin..." yum remove -y sbis3plugin fi fi echo "Adding repository /etc/yum.repos.d/tensor.repo..." rm -rf /etc/yum.repos.d/tensor.repo cat > "/etc/yum.repos.d/tensor.repo" << EOF [Sbis3Plugin] name=Sbis3Plugin baseurl=$UPDATE_URL/rpm_repo enabled=1 gpgcheck=0 EOF echo "Updating yum repos..." yum --enablerepo=Sbis3Plugin clean metadata if is_sbis_libstdcxx_required; then echo "Installing runtime..." yum install -y sbis-libstdc++12 if [ $? -ne 0 ]; then echo "yum install runtime failed" custom_exit 1 fi fi if ! is_package_installed "gvfs"; then echo "Installing GVFS for Saby Disk support..." yum install -y gvfs if [ $? -ne 0 ]; then echo "gvfs install failed. Saby Disk may not work correctly" fi fi if $IS_INSTALL_PLUGIN; then echo "Installing SBIS Plugin..." yum install -y sbis3plugin if [ $? -ne 0 ]; then echo "yum install -y sbis3plugin failed" custom_exit 1 fi fi if $IS_INSTALL_ADDITIONS; then echo "Installing additions for SBIS Plugin..." yum install -y sbis3plugin-additions if [ $? -ne 0 ]; then echo "yum install -y sbis3plugin-additions failed" custom_exit 1 fi fi if $IS_INSTALL_SABYTEL; then echo "Installing SabyTel..." yum install -y sabytel if [ $? -ne 0 ]; then echo "yum install -y sabytel failed" custom_exit 1 fi fi custom_exit 0 fi if [ $IS_DEBIAN -eq 0 ] || [ $IS_UBUNTU -eq 0 ]; then if [ $IS_ASTRA_SE -eq 0 ]; then if is_package_installed "sbis-libstdc++12"; then echo "Uninstalling old runtime..." apt-get remove sbis-libstdc++12 -y -o=Dpkg::Use-Pty=no fi if ! is_package_installed "ca-certificates"; then try_wget "$ASTRA_PACKAGES_URL/ca-certificates_20161130+nmu1_all.deb" "Downloading certificates..." "--no-check-certificate" if [ $? -eq 0 ]; then echo "Installing ca-certificates..." apt-get install ./$TMP_DIR_NAME/ca-certificates_20161130+nmu1_all.deb -y 1> /dev/null fi fi install_astra_packages fi echo "Debian: adding repository /etc/apt/sources.list.d/tensor.list" rm -rf /etc/apt/sources.list.d/tensor.list cat > "/etc/apt/sources.list.d/tensor.list" << EOF deb $UPDATE_URL/deb_repo ./ EOF try_wget $UPDATE_URL/deb_repo/tensor.pub.gpg "Downloading gpg-key for SBIS Plugin..." gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/tensor.gpg --import ./$TMP_DIR_NAME/tensor.pub.gpg 1> /dev/null if [ $? -ne 0 ]; then echo "gpg import failed" custom_exit 1 fi chown _apt /etc/apt/trusted.gpg.d/tensor.gpg 1> /dev/null if [ $? -ne 0 ]; then echo "chown _apt tensor.gpg failed" custom_exit 1 fi echo "Updating packages..." apt-get update if [ $? -ne 0 ]; then echo "apt-get update failed" custom_exit 1 fi if is_package_installed "sbis3plugin"; then if ! is_package_installed "saby-minimal-core"; then echo "Removing old SBIS Plugin..." apt-get remove -y sbis3plugin fi fi if is_sbis_libstdcxx_required; then echo "Installing runtime..." apt-get install sbis-libstdc++12 -y -o=Dpkg::Use-Pty=no if [ $? -ne 0 ]; then echo "install -y sbis-libstdc++12 failed" custom_exit 1 fi fi echo "Installing SabyCore..." apt-get install saby-minimal-core -y -o=Dpkg::Use-Pty=no if [ $? -ne 0 ]; then echo "install sabycore failed" custom_exit 1 fi if $IS_INSTALL_PLUGIN; then echo "Installing SBIS Plugin..." apt-get install sbis3plugin -y -o=Dpkg::Use-Pty=no if [ $? -ne 0 ]; then echo "install sbis3plugin failed" custom_exit 1 fi fi if $IS_INSTALL_ADDITIONS; then echo "Installing additions for SBIS Plugin..." apt-get install sbis3plugin-additions -y -o=Dpkg::Use-Pty=no if [ $? -ne 0 ]; then echo "install sbis3plugin-additions failed" custom_exit 1 fi fi if $IS_INSTALL_SABYTEL; then echo "Installing SabyTel..." apt-get install sabytel -y -o=Dpkg::Use-Pty=no if [ $? -ne 0 ]; then echo "install sabytel failed" custom_exit 1 fi fi if [ $IS_UBUNTU -eq 0 ] && [ "$(get_os_version)" -ge "22" ]; then echo "Installing flatpak..." apt-get install flatpak -y -o=Dpkg::Use-Pty=no if [ $? -ne 0 ]; then echo "Cannot install flatpak" else echo "Setting permissions for flatpak..." bash -c "sudo -E -u $(get_user_name) flatpak permission-set webextensions ru.tensor.sbis_plugin_nmh snap.firefox yes" if [ $? -ne 0 ]; then echo "Cannot set flatpak permissions for sbis3plugin" fi fi fi echo "Installation completed." custom_exit 0 fi if [ $IS_ALTLINUX -eq 0 ]; then if is_package_installed "sbis3plugin"; then if ! is_package_installed "saby-minimal-core"; then echo "Removing old SBIS Plugin..." apt-get remove -y sbis3plugin fi fi echo "Updating packages..." apt-get update if [ $? -ne 0 ]; then echo "apt-get update failed" custom_exit 1 fi if is_sbis_libstdcxx_required; then try_wget "$UPDATE_URL/rpm_repo/sbis-libstdc++12-12.2.1-4.el7.x86_64.rpm" "Downloading runtime..." echo "Installing runtime..." apt-get install -y ./$TMP_DIR_NAME/sbis-libstdc++12-12.2.1-4.el7.x86_64.rpm if [ $? -ne 0 ]; then echo "apt-get install runtime failed" custom_exit 1 fi fi try_wget "$UPDATE_URL/saby-minimal-core.rpm" "Downloading Saby Minimal Core for Alt Linux..." echo "Installing Saby Minimal Core..." apt-get install -y ./$TMP_DIR_NAME/saby-minimal-core.rpm if [ $? -ne 0 ]; then echo "apt-get install saby-minimal-core failed" fi if $IS_INSTALL_PLUGIN; then try_wget "$UPDATE_URL/sbis3plugin.rpm" "Downloading Saby Plugin for Alt Linux..." echo "Installing SBIS Plugin..." apt-get install -y ./$TMP_DIR_NAME/sbis3plugin.rpm if [ $? -ne 0 ]; then echo "apt-get install plugin failed" custom_exit 1 fi fi if $IS_INSTALL_ADDITIONS; then try_wget "$UPDATE_URL/sbis3plugin-additions.rpm" "Downloading Saby Plugin additions for Alt Linux..." echo "Installing additions for SBIS Plugin..." apt-get install -y ./$TMP_DIR_NAME/sbis3plugin-additions.rpm if [ $? -ne 0 ]; then echo "apt-get install plugin additions failed" custom_exit 1 fi fi if $IS_INSTALL_SABYTEL; then try_wget "$UPDATE_URL/sabytel.rpm" "Downloading SabyTel for Alt Linux..." echo "Installing SabyTel..." apt-get install -y ./$TMP_DIR_NAME/sabytel.rpm if [ $? -ne 0 ]; then echo "apt-get install SabyTel failed" custom_exit 1 fi fi custom_exit 0 fi if [ $IS_OPENSUSE -eq 0 ]; then is_package_installed "sbis3plugin" if [[ $? -eq 0 ]]; then is_package_installed "saby-minimal-core" if [[ $? -ne 0 ]]; then echo "Removing old SBIS Plugin..." zypper remove -y sbis3plugin fi fi echo "Deleting current repository..." zypper rr sbis3plugin echo echo "Adding repository..." zypper ar -G -f $UPDATE_URL/rpm_repo sbis3plugin echo "Installing mozilla-nss-tools for openSUSE..." zypper install -y mozilla-nss-tools echo "Installing Saby Minimal Core..." zypper install -y saby-minimal-core if $IS_INSTALL_PLUGIN; then echo "Installing SBIS Plugin..." zypper install -y sbis3plugin fi if $IS_INSTALL_ADDITIONS; then echo "Installing additions for SBIS Plugin..." zypper install -y sbis3plugin-additions fi if $IS_INSTALL_SABYTEL; then echo "Installing SabyTel..." zypper install -y sabytel fi custom_exit 0 fi echo "Unknown OS. Install failed." custom_exit 1