User:Andy Crowd/sandbox/Desktop users
Soon will be a full complete ArchLinux for average users that can be only cloned to other computers with needs only to configure settings for user needs.
I think that I am done with all scripts for single average user configuration.
Notes about configuration what to do
- Custom script for starting "failsafe section" based on xinitrc to put here, even: upgrade, update, reinstall and restore scripts
- Create a kind if the GUI failsafe environment with custom desktop and scripts combined with shell to GUI programs and lock only to a specific user.
- Openbox + iDesk
- upgrade.sh - upgrade the whole system even files within ignore lists
- force_update.sh - same a update_on_reboot.sh but with GUI
- reinstall_updates.sh - reinstall all except in ingnore list
- reinstall_all_files.sh - reinstall the whole system including files from the ignore list
- download Mirrors check and auto-config done: Mirrors#List_mirrors_only_for_a_specific_country
- Recovery tasks
- restore.sh - Restore "admin" user default settings from the back-up
- RePack.sh - restore damaged pacman files and database from back-up or if possible then download a new version of it
Extract package name from wget log
ZZ="pacman"; cat /tmp/log | \ awk -v XX=$ZZ -F'http' '//{if ( $0 ~ "//" ) AA=$2;} END{if( AA ~ "tar" )print substr(AA,index(AA,XX))}'
Search pacman in cache
Arch="x86_64"; PacFind="$(ls -1 /var/cache/pacman/pkg/ --sort=version| \ awk -v QQ=$Arch '//{if( match($0,"pacman-[0-9]") == "1" )ZZ=$1 } END{if(index(ZZ,QQ) != 0 )print ZZ}')"; echo $PacFind
PacName="pacman" LogName="down_pkg_log_" PathPKG="/tmp" Arch="x86_64" PacFind="$(ls -1 /var/cache/${PacName}/pkg/ --sort=version| \ awk -v QQ=$Arch -v WW=$PacName '//{if( match($0,WW"-[0-9]") == "1" )ZZ=$1 } END{if(index(ZZ,QQ) != 0 )print ZZ}')"; if [ ! -z "$PacFind" ];then tar --exclude-ignore='.MTREE' --exclude-ignore='.PKGINFO' --exclude '.INSTALL' -C / -xvf "/var/cache/${PacName}/pkg/${PacFind}" else wget --content-disposition -m -nd -nH https://www.archlinux.org/packages/core/x86_64/${PacName}/download/ -P /tmp/ -o "${PathPKG}/${LogName}" if [ "$?" != "0" ];then xmessage "No Internet connection is available and cannot find the $PacName file in the pacman cache." exit 1 else UnTarPKG="$(awk -v XX=${PacName} -F"$PathPKG" '//{AA=$1;if( $2 ~ "/" && index($2,"[") == "0" ){KK=$2; sub(".","",KK);split(KK,SS,"xz");print SS[1]"xz" }}' /tmp/down_pkg_log_)" tar --exclude-ignore='.MTREE' --exclude-ignore='.PKGINFO' --exclude-ignore='.INSTALL' -C / -xvf "${PathPKG}/${UnTarPKG}" fi fi
Spelling dictionary FIX for Firefox
The one that made me very irritated is when right clicking in the firefox menu to check spelling it shows a long list of en_* languages, to fix this i got to remove all unneeded from the
/usr/share/hunspell/
I made a back-up folder to move them /usr/share/hunspell/OLD_/
and same I did with the /usr/share/myspell/dicts/
by creating OLD_ folder for backup inside and moved useless for me languages there.
Hotkey managment
Power_management - ignore, poweroff, reboot, halt, suspend, hibernate, hybrid-sleep, lock or kexec, /etc/systemd/logind.conf
, HandlePowerKey=poweroff, HandleSuspendKey=suspend, HandleHibernateKey=hibernate, and HandleLidSwitch=suspend | examples from other wiki page.
obkeyAUR - change hotkeys in Openbox
Openbox scripts for config
Original scripts
/usr/bin/openbox-session /usr/lib/openbox/openbox-autostart
/usr/bin/openbox-session
#!/bin/sh if test -n "$1"; then echo "Syntax: openbox-session" echo echo "See the openbox-session(1) manpage for help." exit fi # Clean up after GDM xprop -root -remove _NET_NUMBER_OF_DESKTOPS \ -remove _NET_DESKTOP_NAMES \ -remove _NET_CURRENT_DESKTOP 2> /dev/null # Set up the environment A="/etc/xdg/openbox/environment" test -r $A && . $A A="${XDG_CONFIG_HOME:-"$HOME/.config"}/openbox/environment" test -r $A && . $A # Run Openbox, and have it run the autostart stuff exec /usr/bin/openbox --startup "/usr/lib/openbox/openbox-autostart OPENBOX" "$@"
/usr/lib/openbox/openbox-autostart
#!/bin/sh # Set a background color BG="" if which hsetroot >/dev/null 2>/dev/null; then BG=hsetroot elif which esetroot >/dev/null 2>/dev/null; then BG=esetroot elif which xsetroot >/dev/null 2>/dev/null; then BG=xsetroot fi test -z $BG || $BG -solid "#303030" GLOBALAUTOSTART="/etc/xdg/openbox/autostart" AUTOSTART="${XDG_CONFIG_HOME:-"$HOME/.config"}/openbox/autostart" # Run the global openbox autostart script if test -f $GLOBALAUTOSTART; then sh $GLOBALAUTOSTART elif test -f $GLOBALAUTOSTART.sh; then sh $GLOBALAUTOSTART.sh fi # Run the user openbox autostart script if test -f $AUTOSTART; then sh $AUTOSTART elif test -f $AUTOSTART.sh; then sh $AUTOSTART.sh fi # Run the XDG autostart stuff. These are found in /etc/xdg/autostart and # in $HOME/.config/autostart. This requires PyXDG to be installed. # See openbox-xdg-autostart --help for more details. /usr/lib/openbox/openbox-xdg-autostart "$@"
Xsessions - switch window managers
.dmrc - used by many to set up defaults for session and type of session
.dmrc
[Desktop] Session=openbox
Last used options - options that were used last time you logged in, as last_session, last_lang, last_langs.
KDE
$HOME/.kde4/env/wm.sh
#!/bin/bash #export KDEWM=xfwm4
$ kwin --replace
Create own exec bash script with custom window manager
/usr/bin/xfce4-kde-session
#!/bin/bash export KDEWM=xfwm4 startkde
Create own custom desktop file
/usr/share/xsessions/xfce4-kde.desktop
[Desktop Entry] Name=KDE/XFCE4 Comment=Use the XFWM4 window manager inside of the K Desktop Environment Exec=/usr/bin/xfce4-kde-session TryExec=/usr/bin/startkde Icon=openbox Type=Application
Add path to /usr/share/xsessions/
into the kdmrc file for the SessionsDirs variable
/usr/share/config/kdm/kdmrc | grep SessionsDir
SessionsDirs=/usr/share/config/kdm/sessions,/usr/share/apps/kdm/sessions,/usr/share/xsessions/
Openbox
$ openbox --replace
Add to autostart
/etc/xdg/openbox/autostart
/usr/bin/xfce4-clipman & startlxde openbox --exit
List and add CUPs zenity
if [ "$(whoami)" != "root" ] ;then gksudo "$0" else zenity --info --text="Klicka på OK och Vänta en stunt tills skrivaren hittas!" Plist=($(lpinfo -v |awk '//{if(match($0,"usb") != 0 ){AA=$2;sub(/.$/,"",AA);sub(/%20/," ",AA);split(AA,BB," ");KK=BB[1];sub("usb://","usb-",KK);sub("/"," ",KK);split(KK,Pname," ");sub(" ","_",KK);print KK;print Pname[2];sub(" ","%20",AA);print AA}}' )) if [ "${#Plist[@]}" == "0" ];then zenity --warning --text="Ingen skrivare har hittats!" exit 0 fi zenity --question --text="Vill du lägga till skrivaren med namn ${Plist[0]}" if [ "$?" == "0" ];then lpadmin -p "${Plist[0]}" -E -v "${Plist[2]}" -P "$(find /usr/share/ppd/ -name "*${Plist[1]}*" )" if [ "$?" == "0" ];then zenity --info --text="Skrivaren ${Plist[0]} har lagts till!" else zenity --warning --text="Det uppstod ett fel! Kontakta Admin" fi fi fi
Reset Printer configuration, add new and remove old USB printers
#!/bin/bash if [ "$(whoami)" != "root" ] ;then gksudo "$0" else systemctl stop org.cups.cupsd.socket cups-browsed.service sleep 1 cp /etc/cups/cupsd.conf.default /etc/cups/cupsd.conf systemctl stop org.cups.cupsd.socket cups-browsed.service sleep 1 lpstat -p | grep printer | awk '{ if(match($0," disabled since ") != "0" ){AA="$0";split($0,BB," disabled since ");split(BB[1],CC,"^printer "); system("cupsreject "CC[2]);system("cupsdisable "CC[2]);system("lpadmin -x "CC[2]) } if(match($0," is idle. ") != "0" ){AA="$0";split($0,BB," disabled since ");split(BB[1],CC,"^printer "); system("cupsreject "CC[2]);system("cupsdisable "CC[2]);system("lpadmin -x "CC[2]) } }' sleep 1 Plist=($(lpinfo -v |awk '//{if(match($0,"usb") != 0 ){AA=$2;sub(/.$/,"",AA);sub(/%20/," ",AA);split(AA,BB," ");KK=BB[1];sub("usb://","usb-",KK);sub("/"," ",KK);split(KK,Pname," ");sub(" ","_",KK);print KK;print Pname[2];sub(" ","%20",AA);print AA}}' )) if [ ${#Plist[@]} -gt 0 ];then lpadmin -p "${Plist[0]}" -E -v "${Plist[2]}" -P "$(find /usr/share/ppd/ -name "*${Plist[1]}*" )" fi zenity --info --text="En lista över installerade skrivare är uppdaterad! Frånkopplad är borttagna och inkopplade har laggtstill!" fi
Check AUR for update
Get file size before download wget Test download
wget -O- https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb -o wget.log | head -1 > /dev/null
Show size
awk '{if(index($4,"[") != 0)print $2" "$3}' wget.log
Read from stderr
wget -O- https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb |& head -5 | awk '{if(index($4,"[") != 0)print $2" "$3}'
curl
curl -sI https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb | awk '{if(index($0,"Content-Length") != 0)print $2}'
See also: curl get file size
Thinking about to set up own mirror with auto generation of the pepperflash PKGBUILD file.
Pepperflash PKGBUILD by Lahwaacz
Download and extract DEB pepperflash package Chose what you prefer to use here are pluses and minuses of the packages.
- RPM package contains version about chrome and have a big text part but can't be extracted by cpio directly to the destination. Lower package size.
- DEB very limited amount human readable data only some numbers about compressed packages but can be extracted directly to the destination. Higher package size.
wget -m -nd -nH https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb -o /tmp/_wget_log -P /tmp/ 7z e /tmp/google-chrome-stable_current_amd64.deb -so | \ tar -xv --strip-components=5 --wildcards ./opt/google/chrome/PepperFlash/* -C /usr/lib/PepperFlash/
Get build/version number by ava1ar
$ wget -qO- https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm | head -c96 | strings
awk '{if(match($0,"version") != 0){AA=$2;sub(/",/,"",AA);print substr(AA,2)}}' manifest.json grep version manifest.json | sed -e 's/[^*]*: "//m' -e 's/",//m' grep version manifest.json | awk -F'"' '{print $4}' awk -F'"' '{if(match($0,"version") != 0)print $4}' manifest.json
Check size of downloaded file without downloading it
wget --spider website/update.tar.gz -o log.log awk -v SIZE=$(du -b update.tar.gz | awk '{print $1}') '{if(match($4,"]") != "0") if(SIZE == $2)print $2" = "SIZE }' log.log
Download pepper flash binaries
#!/bin/bash # # Install pepper-flash # if [ "$EUID" -eq 0 ]; then if [ ! -d "/opt/.AUR/chromium-pepper-flash " ];then mkdir /opt/.AUR/chromium-pepper-flash --mode 777 -p ;fi if [ ! -d "/usr/lib/PepperFlash/" ];then mkdir /usr/lib/PepperFlash/ --mode=755 -p ;fi if [ "$(pgrep -c X)" -gt "0" ];then export DISPLAY=:0.0 xmessage -timeout 2 "Startar nedladdningen av Flash video spelare!" fi #### RPM part wget -m -nd -nH https://dl.google.com/linux/direct/google-chrome-stable_current_"${Arch}".rpm -P /path/to/.AUR/chromium-pepper-flash -o /tmp/chromium-pepper-flash.wget-log if [ "$(grep '100%' -c /tmp/chromium-pepper-flash.wget-log)" != "0" ];then wget -m -nd -nH https://dl.google.com/linux/direct/google-chrome-stable_current_${Arch}.deb -o /tmp/_wget_log -P /tmp/ 7z e /tmp/google-chrome-stable_current_amd64.deb -so | \ tar -xv --strip-components=5 --wildcards ./opt/google/chrome/PepperFlash/* -C /usr/lib/PepperFlash/ fi ########### DEB part # if [ ! -d "/tmp/PepperFlash/" ];then mkdir /tmp/PepperFlash/ --mode=755 -p ;fi # cd "/tmp/PepperFlash/" # 7z e /path/to/.AUR/chromium-pepper-flash/google-chrome-stable_current_"${Arch}".rpm -so | cpio -ivd ./opt/google/chrome/PepperFlash/* # chmod 644 /tmp/PepperFlash/opt/google/chrome/PepperFlash/* # cp --preserve=all -v /tmp/PepperFlash/opt/google/chrome/PepperFlash/* /usr/lib/PepperFlash/ # rm -fr /tmp/PepperFlash/. ############ if [ "$(pgrep -c X)" -gt "0" ];then export DISPLAY=:0.0 xmessage -timeout 2 "Klar med installation av Flash internet video spelare." fi fi fi fi
#!/bin/bash iOK="0" URLarray=(PKG1 URL1 PKG2 URL2) arrP=0;arrU=1 while [ "${#URLarray[@]}" -gt "$arrU" ];do wget -nd -nH -m "${URLarray[arrU]}" -P /tmp if [ "$?" != "0" ];then pacman -Sw "${URLarray[arrP]}" --needed --noconfirm else cd /tmp runuser -u user_name makepkg if [ "$?" == 0 ];then iOK="1";fi rm /tmp/PKGBUILD fi arrU=$((arrU+2)) arrP=$((arrP+2)) done if [ "$iOK" != "0" ]; then repo-add -s -n /path/to/custom.db.tar /path/to/*.xz fi
First must be created the GPG key and added to the makepkg
configuration file.
/etc/makepkg.conf
............... PKGDEST=/path/to/custom_repo GPGKEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ...............
- Compare version in PKGBUILD with installed.
- Get current installed package version. -
pacman -Qs package_name
. - Download
wget -nd-nH -m path_to_PKGBUILD -P /tmp/
- Use utilities like grep, awk, sed or bash expressions to search for the pkgver, pkgrel in the downloaded PKGBUILD for comparison with installed.
- Get current installed package version. -
- Start makepkg. - should be run in the same directory as the
PKGBUILD
file. When running as root or from cron userunuser -u user_name makepkg
. - Update custom repositories database file. -
repo-add -s -n custom.db.tar *.xz
- Check all repositories with pacman. -
pacman -Syy
- Update on reboot scheduled with crone. -
pacman -S --needed package_name
or add package_name in the shortlist of updates on boot script to avoid question about using of the sudo.
- An easier alternative is to compare checksum of the downloaded PKGBUILD file with old and replace after update is completed but it is sensitive to any changes in the file even if the version number is the same.
- Uncomment the [custom] repository and set correct path to the your custom repository.
- If wget will return error that file is not found then you can check with
pacman -Ss
if package is moved to the official repositories or make it before running wget.
With the curl is much easier to check for updates but with wget is easier to install update if available by using makepkg. This example checks only for a single package.
#!/bin/bash PKG="chromium-pepper-flash" CutN=$(echo ${PKG} | awk '{print substr($0,0,2)}') Ppath="/tmp" mkdir "${Ppath}/${PKG}" -p AA="$(pacman -Qs ${PKG} | sed -e 's/[^*]*://m' -e 's/-[^*]//m' | head -1)" # BB="$(curl https://aur.archlinux.org/packages/${CutN}/${PKG}/PKGBUILD | grep pkgver | sed 's/pkgver=//g')" wget -m -nd -nH https://aur.archlinux.org/packages/${CutN}/${PKG}/PKGBUILD -P "${Ppath}/${PKG}" BB=$(grep pkgver "${Ppath}/${PKG}/PKGBUILD" | sed 's/pkgver=//g') if [ "$AA" != "$BB" ];then cd "${Ppath}/${PKG}" && makepkg repo-add -s -n /opt/.AUR/custom.db.tar /opt/.AUR/*.tar.xz pacman -Sy pacman -S --needed --noconfirm chromium-pepper-flash #zenity --question --text="do you want update the package?"; fi
The aurgetrc example
~/.config/aurgetrc
build_directory="/opt/.AUR/tmp/" edit_pkgbuilds='never'
Screen saver On/Off
This will turn on or turn off the screen saver.
#!/bin/bash xSaverS=($(xset q | awk '//{if(match($0,"DPMS is") != 0 )DPMS=$3; if(match($0,"timeout:") != 0)STimeout=$2; if(match($0,"Standby:") != 0)Standby=$2 ;}END{print DPMS" "STimeout" "Standby }')); if [ "${xSaverS[0]}" == "Disabled" ] && [ "${xSaverS[1]}" == "0" ];then zenity --ellipsize --question --text="Skärmsläckare och skärmens strömsparläge är avstängda! Vill du aktivera de?"; if [ "$?" == "0" ];then xset +dpms s on;fi; else if [ "${xSaverS[0]}" == "Enabled" ] || [ "${xSaverS[1]}" != "0" ];then zenity --ellipsize --question --text="Skärmsläckare eller skärmens strömsparläge är påslagna! Vill du stänga av de helt?"; if [ "$?" == "0" ];then xset -dpms s off;fi; fi;fi
Set mime types
Use/set/view all mimetypes in specific *.desktop file
FileName="libreoffice-writer.desktop"; [[ -z $FilenName ]] && awk -F"=" -v Fil=$FileName '//{ if(index($1,"MimeType")){MT=$2;SizeArr=split(MT,ArrMime,";")}; }END{ for ( i = 0;i <= SizeArr;i++)if(ArrMime[i])print ArrMime[i]"="Fil;}' "$FileName"
List installed by reading *.desktop files
Instead of using right click for listing of installed applications with /usr/share/applications/*.desktop
list
#!/bin/bash if [ "XX$1" != "XX" ];then grep -i $1 -r /usr/share/applications/* |grep Categories | sed -e 's/[^.*]*\///g' -e 's/.desktop/ /m' -e 's/:Categories=/: /g' else echo The '"'$1'"' is not found'!' grep -i ';' -r /usr/share/applications/* |grep Categories | sed -e 's/[^.*]*\///g' -e 's/.desktop/ /m' -e 's/:Categories=/: /g' echo 'command line is empty - listed all!' echo 'Usage: list <Category>' fi
same but with only awk
#!/bin/bash [[ ! -z "$1" ]] && awk -v Seek="$1" -F"=" '{ if(index($1,"Categories") ) A=$2; if( index($1,"Exec") ) C=$2; split(C,B," "); Z=B[1]" ¤ "A; if(match(tolower(Z),tolower(Seek)) && A ) print Z; A=""}' /usr/share/applications/*.desktop
Start webbrowser in a full screen
Looking for a browsers and ways to start them from command line in a full screen, useful for e.g. startx /usr/bin/WebBrowser --full-screen
.
firefox
FireFox cannot be in a full screen from a command line but it is possible to set a window size.
$ firefox $(xrandr | awk '//{if ( $2 ~ /*/ )Res=$1} END {split(Res,FF,"x");print "-width "FF[1] " -height " FF[2]}')
The F11
key can be used to toggle full screen but it will only hide parts around web-page, if mouse on top border then it will show hidden.
epiphany
First run:
$ epiphany --profile myprofile_browser
Remove backup settings
$ rm "myprofile_browser/session_state.xml~"
Edit settings for window placement and size
myprofile_browser/session_state.xml
<?xml version="1.0"?> <session> <window x="0" y="0" width="1208" height="1020" active-tab="0" role="epiphany-window-735cd0ed"> <embed url="about:overview" title="Most Visited"/> </window> </session>
Second run
$ epiphany --profile=myprofile_browser
dwb
According to dwb manual some of -x, --execute=commands
command line options can be used
$ dwb -x fs
The fs
command can also be used as :fs
in the dwb window commands.
uzbl-browser
Commands -g, --geometry=GEOMETRY
to set size of window
$ uzbl-browser -g $(xrandr | awk '//{if ( $2 ~ /*/ )Res=$1} END {print Res}')
Reinstall all
Re-installs all except chosen to ignore packages, should be run a some kind of "FAIL SAFE Mode"
reinstall.sh
#!/bin/bash xset -dpms s off ST=($(upower -i "$(upower -e | grep 'BAT')" | grep -e "state" -e percentage | awk '{print $2}' | sed 's/%//g')) #NotAllowed=$(ps -eo comm | grep -v -e 'tmp' -e ^'lxdm-' -e | grep -i -e xfce -e openbox -e lx -e kde -e xfce -c ) NotAllowed="0" echo echo $NotAllowed if [ "${NotAllowed}" == "0" ];then if [ 'XX'${ST[0]} != 'XX' ]; then if [ ${ST[0]} == 'charging' ] || [ ${ST[0]} == 'fully-charged' ] || [ ${ST[1]} -gt 70 ];then ToIgnore="$(awk -F'=' '{if ( $1 ~ "IgnorePkg" )print $2 }' /etc/pacman.conf | sed 's/ / -e /g')" sudo pacman -Qqen | grep -v $ToIgnore | sudo pacman -S --noconfirm - else echo echo The battery not at least 70% charged echo cannot do the reinstall!!! fi fi else echo echo You are not in the failsafe mode! echo Restart computer and try again! echo echo cannot do the reinstall fi xset +dpms s on reboot
Upgrade whole Linux
GUI lock to the single user
#!/bin/bash MAXpower="70" AllowedUser="Jolin_Tsai" if [ "${AllowedUser}" != "$(whoami)" ]; then zenity --warning --text=" You are not allowed user! Only the $AllowedUser allowed to start upgrade!" exit 1 fi if [ "$(/usr/local/bin/CheckPower.sh $MAXpower )" != "OK" ];then PowerFailCheck=" The battery change is less then ${MAXpower}" fi ping -c 1 8.8.8.8 if [ "$?" != "0" ];then NetConnectionError=" Fail connect to the internet" fi if [ "$(ifconfig | grep ^ppp -c)" != "0" ]; then ModemConnected=" You are using MODEM! Files might be very big in size to download." fi if [ ! -z "$PowerFailCheck" ] || [ ! -z "$NetConnectionError" ] || [ ! -z "$ModemConnected" ];then zenity --warning --text="${PowerFailCheck}${NetConnectionError}${ModemConnected}" fi zenity --warning --text="Det är farligt att uppgradera systemet! It may fail to start up: If you will power off during upgrade Or will close the upgrade window." zenity --question --text="Är du säker på att uppgradera systemmets grundläggande funktioner?" if [ "$?" == "0" ];then pacman -Qu |awk '//{if(index($0,"[ignored]") != 0 )print $1 }'|pacman -Si -|grep ^[a-Z]|\ sed 's/ //g'|awk -F':' '//{ZZ=ZZ+1;XX[ZZ]=$1;SS[ZZ]=$2;} END{AA=ZZ/18;for(i=1;i <= AA;i++){print i" | " XX[i*18-16]": "SS[18*i-16]" | "XX[i*18-4]": "SS[i*18-4];}}' | \ zenity --text-info --width=440 --height=500 --title="Tillängliga filer system uppgrade!" fi #.................. #.................. Here will be upgrade part! #..................
Force update even if in ignore list
cupdate
#!/bin/bash ST=($(upower -i $(upower -e | grep 'BAT') | grep -e "state" -e percentage | awk '{print $2}' | sed 's/%//g')) if [ -z "${ST[0]}" ];then ST[0]="charging" ;fi echo "${ST[0]}" if [ "${ST[0]}" == "charging" ] || [ "${ST[0]}" == "fully-charged" ] ; then if [ 'XX'"$1" == 'XX' ];then kdesu xterm -e "$0" A else pacman-db-upgrade pacman -Syy --noconfirm pacman-db-upgrade pacman -Qq | pacman -S --needed --noconfirm - pacman-db-upgrade #aurget -Syu --noconfirm #freshclam reboot fi #fi else aplay /usr/share/apps/granatier/sounds/die.wav fi
Need to use safe close window before starting xterm.
#!/bin/sh wmctrl -l | while read -r line do wmctrl -c `echo "$line" | sed 's/.* [0-9]* [your_hostname] //'` done
Inline script to close all windows
wmctrl -l | \ grep -v -e 'Term' -e 'Firefox' | \ awk '{CloseIt=substr($0, index($0,$4));system("wmctrl -c "CloseIt)}'
Instead of sed
can be used awk.
The awk '{print substr($0, index($0,$4))}'
is the same as sed 's/.* [0-9]* '$(hostname)'//'
.
And sed
cannot handle -1 in output like 0x01000004 -1 your_host_name xfce4-panel
but awk
can.
Check if any network connection is available
$ ifconfig -a | grep -v -e ^' ' -e ^$ -e 'lo:' | \ awk -F':' '{ system("/sbin/ip -4 addr show dev "$1); system("/sbin/ip -6 addr show dev "$1) }' | \ grep -v ^' '| awk -F': ' '{print $2}'
Check if it is possible to ping own IP
ifconfig -a | grep -v -e ^' ' -e ^$ -e 'lo:' | \ awk '{system("/sbin/ip -4 addr show dev "$1);system("/sbin/ip -6 addr show dev "$1)}' | grep inet | \ awk '{system("ping -c 1 "$2);}' | grep ' 0% '
Check internet connection
ping -c 1 www.baidu.com if [ "$?" == "0" ]; then connection is working;fi
wget --delete-after http://www.baidu.com/baidu.html -P '/tmp/' if [ "$?" == "0" ]; then connection is working;fi
Upgrade script body
upgrade.sh
do_upgrade & disown
do_upgrade.sh
#!/bin/bash if [ 'XX'"$1" == 'XX' ];then #if [ ! -z $DISPLAY ]; then #wmctrl -l | awk '{CloseIt=substr($0, index($0,$4));system("wmctrl -c "CloseIt)}' #kdesu xterm -e "$0" A & disown kdesu xterm -e "$0" A #fi else #beep ISPPPD=$(ps -eo comm |awk -F'/' '{print $1}' | grep ^pppd$) if [ "$(CheckPower.sh)" == "OK" ];then if [ 'XX'"$ISPPPD" == 'XX' ] ;then ######### IS_Conn="0" GTest_Conn=$(ifconfig -a | grep -v -e ^' ' -e ^$ -e 'lo:' | awk '{system("/sbin/ip -4 addr show dev "$1);system("/sbin/ip -6 addr show dev "$1)}' | grep inet | awk '{system("ping -c 1 "$2);}' | grep ' 0% ') if [ 'XX'"${Test_Conn}" != 'XX' ];then ping -c 1 www.baidu.com > /dev/null if [ "$?" == "0" ]; then IS_Conn="1";else wget --delete-after http://www.baidu.com/baidu.html -P '/tmp/' if [ "$?" == "0" ]; then IS_Conn="1";fi fi ######### if [ ${IS_Conn} == "1" ];then pacman -Syy --noconfirm pacman-db-upgrade pacman -Su --noconfirm pacman-db-upgrade #aurget -Syu --noconfirm #freshclam rm /opt/.updated fi else # aplay /usr/share/apps/granatier/sounds/die.wav pacman-db-upgrade pacman -Su --noconfirm pacman-db-upgrade reboot fi #else aplay /usr/share/apps/granatier/sounds/die.wav fi #else pacman -Su --noconfirm fi pacman -Su --noconfirm fi #fi sleep 10
Crone - scheduled updates
To schedule updates need to about: Time for update, System state.
Update notifier
Inline code that can be used with xmessage or other GUI notifiers for the shell scripts or console programs
Version 1
pacman -Quqi|grep ^[a-Z]|awk -F':' '//{ZZ=ZZ+1;XX[ZZ]=$1;SS[ZZ]=$2;}END{AA=ZZ/21;for(i = 1;i <= AA;i++){print ""SS[i*21-20]":"SS[i*21-6]}}'
Version 2
pacman -Quq|pacman -Si -|grep ^[a-Z]|sed 's/ //g'|awk -F':' '//{ZZ=ZZ+1;XX[ZZ]=$1;SS[ZZ]=$2;}END{AA=ZZ/18;for(i=1;i <= AA;i++){print XX[i*18-16]": "SS[18*i-16]" | "XX[i*18-4]": "SS[i*18-4];}}'
Version 3
$ zenity --question --text="$(pacman -Quq|pacman -Si -|grep ^[a-Z]|sed 's/ //g'|awk -F':' '//{ZZ=ZZ+1;XX[ZZ]=$1;SS[ZZ]=$2;} END{AA=ZZ/18;for(i=1;i <= AA;i++){print XX[i*18-16]": "SS[18*i-16]" | "XX[i*18-4]": "SS[i*18-4];}}')"
System checks & limitations before update
CheckPower.sh
#!/bin/bash MAXpower="60" ST=($(upower -i "$(upower -e | grep 'BAT')" | grep -e "state" -e percentage | awk '{print $2}' | sed 's/%//g')) if [ ! -z ${ST[0]} ];then if [ ${ST[1]} -gt ${MAXpower} ] || [ ${ST[0]} == 'charging' ] || [ ${ST[0]} == 'fully-charged' ]; then echo "OK" else echo "Fail" fi else echo "OK" fi
NeededToUpdate.sh
#!/bin/bash pacman -Qq | \ grep -e smplayer \ -e smtube \ -e ^jre \ -e ^gst \ -e firefox \ -e ^ca-certificates \ -e flash \ -e keyring \ -e wicd \ -e sudo \ -e ^pacman \ -e binutils \ -e opera \ -e ^jdk \ -e bash \ -e ^ffmpeg \ -e ^iproute2 \ -e dhcpcd \ -e vlc \ -e ssl \ -e sudo \ -e binutils \ -e bash \ -e opera \ -e ^ffmpeg \ -e ^iproute2 \ -e dhcpcd \ -e webkit \ -e vlc \ -e ssl | \ grep -v 'chromium-pepper-flash'
Remove unneeded spell checks example
CleanSpell.sh
#!/bin/bash PtoSpells='/usr/lib/aspell-0.60' AA=( ...... british.alias british-ise.alias british-ise-w_accents.alias ...... ) if [ ! -d "${PtoSpells}/OLD_" ];then mkdir "${PtoSpells}/OLD_" if [ "${?}" != "0" ];then break;fi fi for i in ${AA[@]};do #echo ${i} if [ -f ${PtoSpells}'/'${i} ] || [ -h "${PtoSpells}/${i}" ]; then #echo ${i} mv -v "${PtoSpells}/${i}" "${PtoSpells}/OLD_/" fi done
Update scripts
Update and upgrade script
Do_upgradeAndUpdate.sh
#!/bin/bash if [ "$1" == "upDate" ];then yes | pacman -Su fi if [ "$1" == "upGrade" ];then yes | pacman -S --needed $(pacman -Qqn) fi
Check4Update.sh
#!/bin/bash if [ "$(whoami)" != "root" ] ;then gksudo "$0" else RepoCount="$(grep ^'\[' /etc/pacman.conf -c)" ProcCount=$((100 / RepoCount)) echo $ProcCount ChIPtext="zenity --warning --text='Ingen internet anslutning! Anslut till Internet och prova igen." StopCh="$(ps aux | grep -e DownloadShortList.sh -e download-all-updates.sh -e pacman -e ping -e zenity -e makepkg -e wget -c)" if [ "$(CheckPower.sh 70)" != "OK" ];then zenity --warning --text='Datorn är inte kopplat till ström eller battery är laddat under 70% !' fi if [ -f "/var/lib/pacman/db.lck" ] || [ ${StopCh} -gt 1 ];then zenity --warning --text='Automatiska uppdateringar körs redan i backgrunden. Prova igen senare!' fi if [ $(ifconfig | grep -v 'lo:'|grep RUNNING -c ) -gt 0 ];then ping -c 1 8.8.8.8 if [ "$?" != "0" ];then $ChIPtext fi else $ChIPtext fi pacman -Sy --noprogressbar |awk -v BB="${ProcCount}" '{AA=AA+BB;system("echo "AA)}' | zenity --progress --no-cancel pacman -Qu |awk '//{if(index($0,"[ignored]") == 0 )print $1 }'|pacman -Si - |grep ^[a-Z]| sed 's/ //g'|awk -F':' '//{ZZ=ZZ+1;XX[ZZ]=$1;SS[ZZ]=$2;} END{AA=ZZ/18;for(i=1;i <= AA;i++){print XX[i*18-16]": "SS[18*i-16]" | "XX[i*18-4]": "SS[i*18-4];}}' | zenity --text-info --title=Uppdateringar --width=500 --height=400 if [ "$?" == 0 ]; then echo down_all > /tmp/.updated_down_needed echo down_all > /tmp/.updated_down_all xterm -fullscreen -e Do_upgradeAndUpdate.sh upDate ; fi fi
Good to have a few hours between scripts
The update.sh can be run on every boot secheduled in crontab as @reboot /usr/local/bin/update
and download-updates.sh every 2 or 3 hours because it will stop downloading updates after the first lucky download and then after reboot. If computer runs for a few days without rebooting then it is good to shedule removing of /opt/.updated
file and change update
time or add one new time scehdule, every day and after reboot. Those scripts are for laptops only, yet.
- The
update.sh
is moved to github.
Schedulled to download and install updates between 0 and 6 at night when computer is idle for 1 hour
download-all-updates.sh
#!/bin/bash if [ ! -f /tmp/.updated_down_all ];then if [ ! -z $DISPLAY ];then TI=$(xprintidle) else PreTIm=$(w | grep $(whoami) | awk '{print $4}' | awk -F':' '{if ( $2 ~ "m" ){ A=$1; split(A,B,":");print B[1]} }') PreTIh=$(w | grep $(whoami) | awk '{print $4}' | awk -F':' '{if ( $2 ~ "h" ){ A=$1; split(A,B,":");print B[1]} }') PreTIs=$(w | grep $(whoami) | awk '{print $4}' | awk -F'.' '{if ( $2 ~ "s" ){ A=$1; split(A,B,".");print B[1]} }') if [ ! -z "$PreTIh" ];then TI=$((PreTIh * 3600000 )) fi if [ ! -z "$PreTIm" ];then TI=$((PreTIm * 60000 )) fi if [ ! -z "$PreTIs" ];then TI=$((PreTIs * 1000 )) fi fi echo $TI MAXw=$((3600000 / 2 * 3 )) echo $MAXw break #MAXw="10" echo 'down=yes' > /tmp/.updated_down_all if [ "${TI}" -gt "${MAXw}" ]; then #pacman -Qenq | pacman -Syw --needed --noconfirm - #pacman -Qenq | pacman -Sw --noconfirm - IS_Conn="0" #ST=($(upower -i "$(upower -e | grep 'BAT')" | grep -e "state" -e percentage | awk '{print $2}' | sed 's/%//g')) #if [ -z ${ST[0]} ];then ST[0]="No_battery";ST[1]="100"; #fi # if [ "${ST[1]}" -gt "60" ] || [ "${ST[0]}" == 'charging' ] || [ "${ST[0]}" == 'fully-charged' ] ; then if [ "$(CheckPower.sh)" == "OK" ];then #Test_Conn="$(ifconfig -a | grep -v -e ^' ' -e ^$ -e 'lo:' | awk '{system("/sbin/ip -4 addr show dev "$1); system("/sbin/ip -6 addr show dev "$1)}' | grep inet | awk '{system("ping -c 1 "$2);}' | grep ' 0% ')" # if [ 'XX'"${Test_Conn}" != 'XX' ];then # ping -c 1 www.baidu.com # if [ "$?" == "0" ]; then IS_Conn="1";else # wget --delete-after http://www.baidu.com/baidu.html -P '/tmp/' # if [ "$?" == "0" ]; then IS_Conn="1"; # fi # fi #Test_Conn="$(ping -c 1 8.8.8.8 | grep ' 0% ' -c)" ping -c 1 8.8.8.8 > /dev/null Err=${?} echo $Err AAA # if [ 'XX'"${Test_Conn}" != 'XX' ];then if [ "${Err}" == '0' ];then IS_Conn="1"; else IS_Conn="0" fi if [ ${IS_Conn} == "1" ];then pacman-db-upgrade pacman -Syw --needed --noconfirm echo 'down=yes' > /tmp/.updated_down_all pacman-db-upgrade pacman -Ssq | grep ^jre | grep 'openjdk'$ | pacman -Sw --noconfirm --needed - pacman-db-upgrade pacman -Su --needed --noconfirm systemctl daemon-reload #echo 'down=yes' > /tmp/.updated_down_all fi fi fi fi
Checks and download only needed updates once after powered on between 8 and 21 and if computer was idle for about 1 hour.
The latest version of download-needed-updates.sh
is on [https://github.com/AndyCrowd/cron-autoupdate-archlinux/raw/master/download-needed-updates.sh github}}.
download-needed-updates.sh
#!/bin/bash if [ ! -f /tmp/.updated_down_needed ];then if [ ! -z $DISPLAY ];then TI=$(xprintidle) else PreTIm=$(w | grep $(whoami) | awk '{print $4}' | awk -F':' '{if ( $2 ~ "m" ){ A=$1; split(A,B,":");print B[1]} }') PreTIh=$(w | grep $(whoami) | awk '{print $4}' | awk -F':' '{if ( $2 ~ "h" ){ A=$1; split(A,B,":");print B[1]} }') PreTIs=$(w | grep $(whoami) | awk '{print $4}' | awk -F'.' '{if ( $2 ~ "s" ){ A=$1; split(A,B,".");print B[1]} }') if [ ! -z "$PreTIh" ];then TI=$((PreTIh * 3600000 )) fi if [ ! -z "$PreTIm" ];then TI=$((PreTIm * 60000 )) fi if [ ! -z "$PreTIs" ];then TI=$((PreTIs * 1000 )) fi fi MAXw="3600000" #MAXw=10 if [ "${TI}" -gt "${MAXw}" ]; then IS_Conn="0" if [ "$(CheckPower.sh)" == "OK" ]; then #Test_Conn="$(ifconfig -a | grep -v -e ^' ' -e ^$ -e 'lo:' | awk '{system("/sbin/ip -4 addr show dev "$1); system("/sbin/ip -6 addr show dev "$1)}' | grep inet | awk '{system("ping -c 1 "$2);}' | grep ' 0% ')" # if [ 'XX'"${Test_Conn}" != 'XX' ];then # ping -c 1 www.baidu.com # if [ "$?" == "0" ]; then IS_Conn="1";else # wget --delete-after http://www.baidu.com/baidu.html -P '/tmp/' # if [ "$?" == "0" ]; then IS_Conn="1"; # fi # fi Test_Conn="$(ping -c 1 8.8.8.8 | grep ' 0% ' -c)" if [ 'XX'"${Test_Conn}" != 'XX' ];then IS_Conn="1"; fi if [ ${IS_Conn} == "1" ];then pacman-db-upgrade pacman -Sy --needed --noconfirm pacman -Ssq | grep ^jre | grep 'openjdk'$ | pacman -Sw --noconfirm --needed - pacman-db-upgrade pacman -Qq | NeededToUpdate.sh | grep -v 'chromium-pepper-flash' | \ pacman -Sw --noconfirm --needed - pacman-db-upgrade echo 'down=yes' > /tmp/.updated_down_needed fi fi fi fi
Reinstall packages
Those must configured to be able to run in failsafe mode.
reinstall.sh
#!/bin/bash xset -dpms s off ST=($(upower -i "$(upower -e | grep 'BAT')" | grep -e "state" -e percentage | awk '{print $2}' | sed 's/%//g')) NotAllowed=$(ps -eo comm | grep -v -e 'tmp' -e ^'lxdm-' -e | grep -i -e xfce -e openbox -e lx -e kde -e xfce -c ) #NotAllowed="0" echo ${ST[0]} echo ${#ST[@]} echo $NotAllowed if [ "${NotAllowed}" -eq "0" ];then if [ 'XX'${ST[0]} != 'XX' ]; then ST[0]="nobatt" ; fi; if [ "${ST[0]}" == 'charging' ] || [ "${ST[0]}" == 'fully-charged' ] || [ "${ST[1]}" -gt "70" ] || [ "${ST[0]}" == "nobatt" ] ;then sudo pacman -Qqen | grep -v -e mkinitcpio \ -e grub -e aspell -e hspell -e hunspell -e ispell -e shadow -e lib32-util-linux -e libutil-linux -e ^linux -e linux-api-headers -e linux-firmware -e linux-headers -e filesystem | sudo pacman -S --noconfirm - else echo echo The battery not at least 70% charged echo cannot do the reinstall!!! fi else echo echo You are not in the failsafe mode! echo Restart computer and try again! echo echo cannot do the reinstall fi xset +dpms s on
reinstall-all.sh
#!/bin/bash ST=($(upower -i "$(upower -e | grep 'BAT')" | grep -e "state" -e percentage | awk '{print $2}' | sed 's/%//g')) NotAllowed=$(ps -eo comm | grep -e xfce -e openbox -e lx -e kde | grep -v tmp -c) if [ "${NotAllowed}" == "0" ];then if [ 'XX'${ST[0]} != 'XX' ]; then if [ ${ST[0]} == 'charging' ] || [ ${ST[0]} == 'fully-charged' ] || [ ${ST[1]} -gt 70 ];then #pacman -Qqen | grep -v ^'linux-' | pacman -S --noconfirm - pacman -Qqen | pacman -S --noconfirm - else echo echo The battery not at least 70% charged echo cannot do the reinstall!!! fi fi else echo echo You are not in failsafe mode! echo cannot do the reinstall!!! fi
Laptop notify warnings
Shechedule
$ EDITOR=vim crontab -e
*/5 * * * * /usr/local/bin/checktemp.sh # JOB_ID_1
Beep if temperature is to high
#!/bin/bash CPU_GPU=($(sensors | grep -e 'Core 0' -e temp1 |awk -F'+' '{TT=$2;split(TT,II,".");print II[1]}')) SSD=($(smartctl -a /dev/sda | grep Temp | awk -F'-' '{TT=$2;split(TT,SS,"(");split(SS[1],AA," ");if( AA[1] != "fail" )print AA[1]}' | head -1)) if [ ${CPU_GPU[0]} -gt 80 ] || [ ${CPU_GPU[1]} -gt 85 ] || [ ${SSD} -gt 65 ];then beep for (( i=0; i <= 15; i++ )) ;do #aplay /usr/share/sounds/pop.wav beep sleep 15 done fi
Debian scripts & configurations
Here is the warriors information about configuration and the scripts for debian/ubuntu maintenance
Getting the latest distributions name and compare with installed
#URLs='http://mirrors.aliyun.com/debian/dists/README' #URLs='http://ftp.df.lth.se/pub/debian/dists/README' URLs='ftp://ftp.se.debian.org/debian/dists/README' # Check for Errors ping debian.org -c1 &> /dev/null ConnErr="$?" curl --head "$URLs" |& grep '404 Not Found'; WebErr="$?" if [ "$ConnErr" != "$WebErr" ]; then zenity --warning --text="Check: 1) Internet connection. 2) Firewall should allow pings. 3) Remote Server might be down for maintenance. Wait and try late. 4) Add new or uncomment existing URL in this script file." exit 1 else apt-get update; NeedUpdates=$(apt-get --just-print upgrade | grep -v '\[' | tail -1 | awk '{C=split($0,B,0);if (C != 5)print "NeedUpdates") }') if [ ! -z "$NeedUpdates" ];then zenity --warning --text="Your system need to be updated! Update it and start this script again!" exit 1 fi OnWeb="$(curl $URLs |& grep important | sort -V | head -1 | cut -d'-' -f1)" OnComp="$(awk '//{if (index($3,"-updates"))A=$3 }END{print A}' /etc/apt/sources.list)" if [ ! -f "/etc/apt/sources.list" ];then zenity --warning --text="The '/etc/apt/sources.list' doesn\'t exist" exit 1; fi; if [ "${OnWeb}-updates" != "$OnComp" ];then zenity --question --text="Are you sure to continue upgrade?" if [ "$?" == 0 ]; then BkupTime="$(date +"Clock_%m-%H-%S_Year_%Y-%B")" #cp /etc/apt/sources.list /etc/apt/sources.list"$BkupTime" cat /etc/apt/sources.list | sed "s/$OnComp/$OnWeb/g" ;fi zenity --info --text="Back up copy stored in the '/etc/apt/sources.list$BkupTime' file" apt-get update --yes | zenity --text-info --title="Updating existing - press Ok when done" --width=800 --height=600 apt-get upgrade --yes | zenity --text-info --title="Upgrading existing - press Ok when done" apt-get dist-upgrade --yes | zenity --text-info --title="Upgrading this distribution - press Ok when done" --width=800 --height=600 #reboot fi
Debian Mirrors and vbox installation
Install VirtualBox guest modules in Debian.
The repository tree (e.g. http://download.virtualbox.org/virtualbox/debian/dists/jessie/) for Debian follows pattern
- URL (e.g. http://download.virtualbox.org/virtualbox/debian/)
- distribution (e.g. jessie)
- Sub folders under dist (e.g. non-free contrib )
- distribution (e.g. jessie)
deb http://download.virtualbox.org/virtualbox/debian jessie contrib deb http://download.virtualbox.org/virtualbox/debian jessie non-free
On errors such as:
W: GPG error: http://download.virtualbox.org jessie InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 54422A4B98AB5139
To add the missing key 54422A4B98AB5139 use:
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 54422A4B98AB5139
Debian example sources.list
deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib ### deb http://security.debian.org/ jessie/updates main contrib non-free deb-src http://security.debian.org/ jessie/updates main contrib non-free deb http://ftp.df.lth.se/pub/debian/ jessie main deb-src http://ftp.df.lth.se/pub/debian/ jessie main deb http://security.debian.org/ jessie/updates main deb-src http://security.debian.org/ jessie/updates main deb http://ftp.df.lth.se/pub/debian/ jessie-updates main deb-src http://ftp.df.lth.se/pub/debian/ jessie-updates main
My /etc/apt/sources.list
deb http://ftp.se.debian.org/debian/ jessie main deb-src http://ftp.se.debian.org/debian/ jessie main deb http://security.debian.org/ jessie/updates main contrib non-free deb-src http://security.debian.org/ jessie/updates main contrib non-free deb http://download.virtualbox.org/virtualbox/debian jessie contrib deb http://download.virtualbox.org/virtualbox/debian jessie non-free
Skype official repository for debian/ubuntu. Forum
deb http://download.skype.com/linux/repos/debian/ stable non-free
List of variables
# /usr/share/applications Actions Categories Comment DBusActivatable DocPath Encoding Exec FilePattern GenericName Icon InitialPreference Keywords MimeType Name NoDisplay NotShowIn OnlyShowIn Path StartupNotify StartupWMClass TargetEnvironment Terminal TryExec Type Version X-AppInstall-Keywords X-Ayatana-Desktop-Shortcuts X-Desktop-File-Install-Version X-Geoclue-Reason X-GIO-NoFuse X-GNOME-AutoRestart X-GNOME-Autostart-Notify X-GNOME-Autostart-Phase X-GNOME-Bugzilla-Bugzilla X-GNOME-Bugzilla-Component X-GNOME-Bugzilla-ExtraInfoScript X-GNOME-Bugzilla-OtherBinaries X-GNOME-Bugzilla-Product X-GNOME-Bugzilla-Version X-GNOME-DocPath X-GNOME-Fullname X-GNOME-FullName X-GNOME-Keywords X-GNOME-Provides X-GNOME-UsesNotifications X-GNOME-WMName X-KDE-autostart-after X-KDE-Protocols X-KDE-StartupNotify X-LXQt-Need-Tray X-MB-INPUT-MECHANSIM X-MultipleArgs X-Osso-Service X-Osso-Type X-SingleInstance X-Ubuntu-Gettext-Domain X-XfceHelpComponent X-XfceHelpPage X-XfceHelpVersion X-XFCE-MimeType X-XfcePluggable X-XfceSettingsManagerHidden