Rispondi 
 
Valutazione discussione:
  • 0 voti - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5
Scripts
08-12-2018, 11:36 (Questo messaggio è stato modificato l'ultima volta il: 18-12-2018 17:14 da tele.)
Messaggio: #1

Scripts
Script for download and install Firefox portable.
Codice:
#!/bin/bash

# Script designed to download and install Firefox portable.
VERSION="4"
LICENCE="GPL v3: https://www.gnu.org/licenses/gpl.html "
TRADEMARKS="Name Firefox is trademark Mozilla: https://www.mozilla.org/en-US/foundation/trademarks/list/"

#==================={
ERROR()
{
    echo "$@" ; exit 1
}
#===================}

#======================================={
change_language() {
    echo " "
    echo "--> Available other languages:"
    LIST_LANG=$(curl -v --silent https://ftp.mozilla.org/pub/firefox/releases/latest/README.txt --stderr - | grep -E "^   .* lang=")
    echo "$LIST_LANG"
    echo " "
    echo "--> Set new language or leave empty to set lang=en-US and click Enter key"
    read -p "lang=" LANG
    # If empty
    [[ -z "$LANG" ]] && LANGUAGE="en-US" || LANGUAGE="$LANG"
    # If wrong lang
    echo "$LIST_LANG" | grep -q "lang=$LANG"  || ERROR "lang="$LANG" not found :( "
    echo " "
    echo "Chosen language: lang=$LANG"
}
#=======================================}

#=========================={
change_version() {
list_version_firefox() {
    LIST_VER=$(curl -v --silent https://ftp.mozilla.org/pub/firefox/releases/ --stderr -  | sed -e '/releases\/[0-9]/!d' -e 's/[\t]*<\/*[^>]*>//g' -e 's/\///g' -e '/[a-Z]/d' )
}

list_version_firefox_esr() {
    LIST_VER=$(curl --silent https://ftp.mozilla.org/pub/firefox/releases/ --stderr -  |  sed -e '/[0-9]esr\//!d' -e 's/[\t]*<\/*[^>]*>//g' -e 's/\///g' )
}

    echo " "
    echo "--> Available versions :"
    echo " "
    echo "1. Firefox"
    echo "2. Firefox ESR"
    echo " "
    read -p "--> Write a number to choose:" branch_firefox
case "$branch_firefox" in
        1 ) BRANCH="Firefox" ; list_version_firefox ;;
        2 ) BRANCH="Firefox ESR" ; list_version_firefox_esr ;;
        * ) echo "###########################################"
            echo "--> Incorrect number."
            ERROR "###########################################" ;;
esac
    echo "Chosen branch: $BRANCH"
    echo " "
    echo "--> Available versions :"
    echo " "
    echo "$LIST_VER" | sort --version-sort | column
    echo " "
    echo "--> Set new version and click Enter key"
    read -p "version=" VERSION_FIREFOX
    # If wrong version
    echo "$LIST_VER" | grep -q "$VERSION_FIREFOX"  || ERROR "version="$VERSION_FIREFOX" not found :( "
    echo "Chosen version: $VERSION_FIREFOX"
}
#==========================}

#===============================================================================​=={
install_app_f() {
# Is installed "curl" ?
[ "$(curl --version)" ] || ERROR "--> Please install Curl before run this script."
LANGUAGE="en-US"
LINK1="https://download.mozilla.org/?product=firefox-latest-ssl&os=linux&lang=${LANGUAGE}"
RELEASE=$(curl  -s "${LINK1}" | sed -e 's/.*releases\/\(.*\)\/linux.*/\1/g' -e 1q)
LINK_ESR="https://download.mozilla.org/?product=firefox-esr-latest&os=linux&lang=${LANGUAGE}"
RELEASE_ESR=$(curl  -s "${LINK_ESR}" | sed -e 's/.*releases\/\(.*\)\/linux.*/\1/g' -e 1q)
VERSION_FIREFOX="$RELEASE"

LOOPS="y"
while [[ "$LOOPS" == "y" ]] ; do
echo " "
echo "=============================="
echo "--> Language: \"${LANGUAGE}\""
echo "--> Version: \"${VERSION_FIREFOX}\""
echo "   ( Latest Firefox:     ${RELEASE} )"
echo "   ( Latest Firefox ESR: ${RELEASE_ESR} )"
echo " "
echo "1. Change Language"
echo "2. Change Version"
echo "3. Exit"
echo "4. Install Firefox"
echo "=============================="
echo " "
read -p "--> Write a number to choose:" choice
case "$choice" in
        1 ) change_language ;;
        2 ) change_version ;;
        3 ) exit 0 ;;
        4 ) LOOPS="n";;
        * ) echo "###########################################"
            echo "--> Incorrect number."
            echo "###########################################" ;;
esac
done



echo " "
# Download firefox
echo "--> Downloading..."
curl -O https://ftp.mozilla.org/pub/firefox/releases/${VERSION_FIREFOX}/linux-i686/${LANGUAGE}/firefox-${VERSION_FIREFOX}.tar.bz2

# Check if downloaded file exist.
[ "$(ls -A ./firefox*tar.bz2)" ] || ERROR "--> Firefox was not downloaded!"


# Check sum
SUM=$(curl -v --silent https://ftp.mozilla.org/pub/firefox/releases/${VERSION_FIREFOX}/SHA256SUMS --stderr - | grep "linux-i686/${LANGUAGE}/firefox-${VERSION_FIREFOX}.tar.bz2" \
| awk '{print $1}')

echo " "
echo "--> Checking the checksum sha256sum"
echo "$SUM firefox-${VERSION_FIREFOX}.tar.bz2" | sha256sum --check  
[ $? == 0 ] || ERROR "--> Downloaded file is broken or sha256sum not exist!"
echo " "

###################################
## Security theory:
# chown -R root:root /opt/firefox
# chmod -R 755 /opt/firefox
# find /opt/ -perm /4000 -o -perm /2000 -o -perm /6000 -o -perm /1000
#
## Important:
#  If the regular user can hang the program
#  (which is owned by the root user and has the suid or sgid flag set)
#  to get to the shell, then he will get the program owner's rights
#  (in this case the root user).
#  So avoid "suid" or "sgid" flag, if you can.

# Info: https://www.techrepublic.com/blog/it-security/understand-the-setuid-and-setgid-permissions-to-improve-security/
# Calculator: http://permissions-calculator.org/
# How find: https://www.tecmint.com/how-to-find-files-with-suid-and-sgid-permissions-in-linux/
#
## Update Menu theory:
# update-desktop-database /usr/share/applications
# update-menus

## Create link
# ln -s /opt/firefox/firefox ~/Desktop/Own.Firefox
###################################

# Own item to menu
cat <<'EOF' >> ownfirefox.desktop
[Desktop Entry]
Version=1.0
Name=Own.Firefox
GenericName=Web Browser
Comment=Browse the Web
Exec=/opt/firefox/firefox %u
Icon=firefox
Terminal=false
Type=Application
StartupWMClass=OwnFirefox
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;
Categories=GTK;Network;WebBrowser;X-MandrivaLinux-Internet-WebBrowsers;X-MandrivaLinux-CrossDesktop;
EOF

echo " "
# Unpack to /opt/
# Change owner to root
# Add icon to "Menu"
echo "--> Installation:"
su root -c 'rm -rf /opt/firefox ; bzip2 -dc firefox*tar.bz2 | tar xvf - -C /opt ; chown -R root:root /opt/firefox ; mv ownfirefox.desktop /usr/share/applications/ ; update-desktop-database /usr/share/applications'

# Checking file permissions
echo "  "
echo "------------------"
# Find files with "suid" or "sgid" flag.
if [[ ! "$(find /opt/firefox -perm /4000 -o -perm /2000 -o -perm /6000 | wc -l)" == "0" ]]; then
    RC='\e[0;31m' # Red Color
    NC='\e[0m' # No Color
    echo -e "${RC} Potentially dangerous files: ${NC}"
    find /opt/firefox -perm /4000 -o -perm /2000 -o -perm /6000
    echo -e "${RC} Warning!  ${NC}"
    echo -e "${RC} Found "suid" or "sgid" flag. Using firefox can be dangerous. ${NC}"
    exit 1
fi
# Find writable files
if [[ ! "$(find /opt/firefox -perm -o+w | wc -l)" == "0" ]]; then
    RC='\e[0;31m' # Red Color
    NC='\e[0m' # No Color
    echo -e "${RC} Potentially dangerous files: ${NC}"
    find /opt/firefox -perm -o+w
    echo -e "${RC} Warning!  ${NC}"
    echo -e "${RC} Found writable files. ${NC}"
    exit 1
fi

# Remove superfluous file
rm ./firefox*tar.bz2

# Info.
echo "--> Own.Firefox installed now, check."
}
#===============================================================================​==}

#======================{
uninstall_app_f() {
su root -c 'rm -rfv /opt/firefox ; rm -rfv /usr/share/applications/ownfirefox.desktop ; update-desktop-database /usr/share/applications'
}
#======================}

###################{
case $1 in
    "--install")
    install_app_f
    ;;

    "--uninstall")
    uninstall_app_f
    ;;

    "--help")
    echo "Usage: [SCRIPT NAME] [OPTION]"
    echo " "
    echo "                              without option will also install own.firefox"
    echo "      --install               install or reinstall own.firefox"
    echo "      --uninstall             remove own.firefox"
    echo "      --help                  display this help and exit"
    echo "      --version               output version information and exit"
    ;;

    "--version")
    echo "Script Version: $VERSION"
    echo "Licence: $LICENCE"
    echo "Trademarks: $TRADEMARKS"
    ;;

    *)
    install_app_f
    ;;
esac
###################}

Last edit: 18.12.2018
- Added option changing the version because in the last version / release of Firefox missing dependencies


Last edit: 18.12.2018
- Added branch ESR version to download
Trova tutti i messaggi di questo utente
Cita questo messaggio nella tua risposta
08-01-2019, 14:28 (Questo messaggio è stato modificato l'ultima volta il: 09-01-2019 02:23 da tele.)
Messaggio: #2

RE: Scripts
Installer for download Steam installer.
To many installers ? Big Grin
Write to Steam support for better app Steam. (portable app) ;-)

Codice:
#!/bin/bash

# Script designed to download and install steam-latest.deb
# from https://store.steampowered.com/about/
VERSION="1"
LICENCE="
License only of this script is GPL v3
   https://www.gnu.org/licenses/gpl.html
License downloaded files is STEAM®_SUBSCRIBER_AGREEMENT
   https://store.steampowered.com/subscriber_agreement/?l=english"
TRADEMARKS="Steam is trademark Valve Corporation
   https://store.steampowered.com/legal/
                                       "

#==================={
ERROR()
{
    echo "$@" ; exit 1
}
#===================}


#===============================================================================​​=={
install_app_f() {
# Is installed "curl" ?
[ "$(curl --version)" ] || ERROR "--> Please install Curl before run this script."
LINK1="https://steamcdn-a.akamaihd.net/client/installer/steam.deb"


echo "$LICENCE"
echo "$TRADEMARKS"
echo " "
echo "--> Downloading steam.deb ..."
GET_FILE=$(curl -si "$LINK1" | grep Location | awk '{print $2}' | tr -d '\r')
echo $GET_FILE
curl -O $GET_FILE
echo " "
echo "--> Checking if downloaded file exist ..."
[ "$(ls -A ./steam_latest.deb)" ] || ERROR "--> Steam was not downloaded!"
echo " "
echo "--> Unpackin ..."
mkdir unpack ; cd unpack
ar vx ../steam_latest.deb
tar -xzvf data.tar.gz
tar -xzvf control.tar.gz
echo " "
echo "--> Checking hash ... "
# test:
# echo "w" >> usr/bin/steam
cat md5sums | md5sum --check
[[ "$?" -eq "0" ]] || ERROR "--> Sorry Steam files are broken, please check files, internet connection or write to Steam support."

###################################
## Security theory:
# chown -R root:root /opt/firefox
# chmod -R 755 /opt/firefox
# find /opt/ -perm /4000 -o -perm /2000 -o -perm /6000 -o -perm /1000
#
## Important:
#  If the regular user can hang the program
#  (which is owned by the root user and has the suid or sgid flag set)
#  to get to the shell, then he will get the program owner's rights
#  (in this case the root user).
#  So avoid "suid" or "sgid" flag, if you can.

# Info: https://www.techrepublic.com/blog/it-security/understand-the-setuid-and-setgid-permissions-to-improve-security/
# Calculator: http://permissions-calculator.org/
# How find: https://www.tecmint.com/how-to-find-files-with-suid-and-sgid-permissions-in-linux/

###################################
cd ../
echo " "
echo "--> Installation:"
# https://unix.stackexchange.com/questions/269462/manual-pages-uses-the-quotation-character-string-quoting-string-inside-gr
su root -c 'chown -R root:root ./unpack/usr ; chmod -R 755 ./unpack/usr ; cp -Riv  ./unpack/usr / | cut -d" " -f3 | sed -e 's/‘//g' -e 's/’//g' | tee installed.steam.files ; update-desktop-database /usr/share/applications ; echo "--> Removing silently downloaded files ..." ; rm -r ./steam_latest.deb ./unpack'
[[ "$?" -eq "0" ]] || ERROR "--> Instalation aborted."

# Info.
echo "--> Installed files should saved to installed.steam.files file, check."
echo "--> Steam installer should be installed now, check."
}
#===============================================================================​​==}

#======================{
uninstall_app_f() {
su root -c 'xargs rm -v < installed.steam.files ; echo "--> Removing empty folders." ; rmdir -v /usr/lib/steam /usr/share/doc/steam /usr/share/doc/steam-launcher ; rm -r ./installed.steam.files'
echo " "
echo -e "--> Do you want remove also steam files from home directory ?"
    read -p "--> Write Y to agree or N to abort:" REMOVEHOMEFILES
case "$REMOVEHOMEFILES" in
        Y|y ) rm -rv $HOME/.steam $HOME/.steampath $HOME/.steampid ;;
        N|n ) echo "--> Home files will be intact." ;;
        * ) echo "###########################################"
            echo "--> Incorrect, try write Y or N."
            ERROR "###########################################" ;;
esac
echo "--> Files removed, check."

exit
# ==== Own notes ===={
# Home Files
# You can find with "locate steam"
$HOME/.steam
$HOME/.steampath
$HOME/.steampid
$HOME/.local/share/Steam
# Empty Folders
/usr/lib/steam
/usr/share/doc/steam
/usr/share/doc/steam-launcher
# ==== Own notes ====}
}
#======================}

###################{
case $1 in
    "--install")
    install_app_f
    ;;

    "--uninstall")
    uninstall_app_f
    ;;

    "--help")
    echo "Usage: [SCRIPT NAME] [OPTION]"
    echo " "
    echo "      --install               install or Steam installer"
    echo "      --uninstall             remove Steam"
    echo "      --help                  display this help and exit"
    echo "      --version               output version information and exit"
    echo " "
    echo -e "Licence: $LICENCE"
    echo -e "Trademarks: $TRADEMARKS"
    ;;

    "--version")
    echo "Script Version: $VERSION"
    ;;

    *)
    echo "Please use: script --install or script --uninstall"
    echo "or script --help"
    ;;
esac
###################}

This script caused for me some problems.
1. Command "cp" and "install" create strange apostrophe, I removed it with sed, but I don't know how it will with your language.
https://unix.stackexchange.com/questions...-inside-gr
2. I used cp -i (--interactive prompt before overwrite)
I don't have time find how compare /user folder and abort installation before overwrite files.
But with this option you can abort installation manually "Ctrl+C" or just kill script.
If want, you can overwrite files and you may broke system.
( maybe not with this version, but overwrite files sometimes this is not good idea )
3. Command "rm -v" will delete only files, I added name folders manually (with script).
( for me option force don't looks safe, but maybe we can use safely in this case )
If you don't want this, you can use with option force and it will remove also folders.
With option force script may also remove better, when you will download newer Steam installer.
For example above Firefox use only one folder /opt/firefox and it is easy and safe to remove.

Edited. 9.01.2019
4. Small explanation.
- To cp -Riv you can add option a
Citazione:-a, --archive same as -dR --preserve=all -->
--preserve[=ATTR_LIST] preserve the specified attributes (default:
mode,ownership,timestamps)
However on UPLOS result is the same.
- Other is sometimes mode.
For set this I used chmod and chown.
For example default icons have -rw-r--r--
after chmod 755 it will have -rwxr-xr-x, for me no big difference, open icon with any app or with any app and alone.
If this is problem for you, you can remove chmod command from script. ( or use chmod 644 for icons )

However for me working, I hope also for you will work.
Trova tutti i messaggi di questo utente
Cita questo messaggio nella tua risposta
08-01-2019, 17:21
Messaggio: #3

RE: Scripts
If you like games why you do not use steamos?
Trova tutti i messaggi di questo utente
Cita questo messaggio nella tua risposta
Rispondi 


Vai al forum:


Utente(i) che stanno guardando questa discussione: 1 Ospite(i)

              Scrivici   Home   Top   Visualizza contenuti   Feed