From 73eaa61bce4bc2e1154b46d45e12065e534ce5ec Mon Sep 17 00:00:00 2001 From: milisarge Date: Sun, 11 Jun 2017 21:09:40 +0300 Subject: [PATCH] milbit --- ayarlar/milbit/libmilisdialog | 635 ++++++++++++++++++++++++++++++++++ ayarlar/milbit/milbit.desktop | 9 + bin/milbit | 584 +++++++++++++++++++++++++++++++ 3 files changed, 1228 insertions(+) create mode 100644 ayarlar/milbit/libmilisdialog create mode 100644 ayarlar/milbit/milbit.desktop create mode 100755 bin/milbit diff --git a/ayarlar/milbit/libmilisdialog b/ayarlar/milbit/libmilisdialog new file mode 100644 index 000000000..bd0777511 --- /dev/null +++ b/ayarlar/milbit/libmilisdialog @@ -0,0 +1,635 @@ +#!/bin/bash +# xdialog kullanımını kolaylaştıran yordamlar. + +## milisarge +## brokenman librokenman betiğinden yararlanılmıştır. +################################### +## READ THE COMMENTS CAREFULLY TO +## KNOW THE ARGUMENTS REQUIRED !! +################################### + +## In most cases script returns variable $answ +## In this case 0=yes 1=no +## E.g is_64bit ($answ returns 0 then yes it is a 64bit machine) + +script=${0##*/} ### This is the users script name, not this one +scriptpath="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")" ### Full script path +answ=/tmp/.answ +log=/var/log/libmilisdialog.log + +# Generic output for errors +error(){ +echo $1 >> $log +} + +# Find which window desktop session we are in. It returns wm= +get_desktop_session(){ +# get desktop info +startx=`ps x | grep -c /usr/bin/startx` +if [ $startx -eq 2 ]; then + lxde=`ps x | grep -v grep | grep -c /usr/bin/lxsession` + trinity=`ps x | grep -v grep | grep tdeinit` + kde4=`ps x | grep -v grep | grep -c /usr/bin/starttde` + xfce=`ps x | grep -v grep | grep -c xfdesktop` +else + lxde=`ps aux | sed '/X '$(echo $DISPLAY|cut -d. -f1)'/,$ !d' | sed '1,/X / !d' | grep -c /usr/bin/lxsession` + trinity=`ps aux | sed '/ '$DISPLAY' /,$ !d' | sed '1,/X / !d' | grep tdeinit` + kde4=`ps aux | sed '/ '$DISPLAY' /,$ !d' | sed '1,/X / !d' | grep -c /usr/bin/startkde` + xfce=`ps aux | sed '/ '$(echo $DISPLAY|cut -d. -f1)' /,$ !d' | sed '1,/X / !d' | grep -c xfdesktop` +fi + +if [ "$lxde" -eq 1 ]; then + wm=lxde +elif [ "$trinity" ]; then + wm=tde +elif [ "$kde4" -eq 1 -a -z "$trinity" ]; then + wm=kde4 +elif [ "$xfce" -eq 1 ]; then + wm=xfce +fi +[ -z $wm ] && error "There was a problem finding the desktop session" +} + +# milis mimari tipi +is_64bit(){ +[ `uname -m|egrep "64"` ] && answ=0 || answ=1 +} + +# Silently kill a named process (number) +kills(){ +# Check that $1 was given +if [ $1 ]; then + kill $1 2>/dev/null & + wait $1 2>/dev/null + else + answ=3 + error "You must supply a process ID to kill!" + return +fi +} + +# Unpack a compressed file to current dir +# $1=compressed file +unpack_file(){ +if [ ! $1 ]; then + answ=3 + error "You must supply a compressed file" + cyan "Supported files: .zip .tar.gz .tar.bz2 .xzm" + return +fi + +# Make sure file has valid extension +local chkf +local ext +local nam +local nam2 +chkf=`echo $1|egrep "*.tar.gz|.tar.bz2|.zip|.xzm|.tar.xz|.txz|.tgz"` +if [ -z $chkf ]; then + answ=3 + error "ERROR:" "This type of file is not supported!" + return +fi + +# Get extension +ext=${chkf##*.} +nam=${1##*/} +case $ext in +gz ) +tar zxvf $1 >/dev/null|| answ=3 && error "ERROR unpacking $1" +;; +bz2 ) +tar xvjf $1 >/dev/null|| bzip2 -d $1 || answ=3 && error "ERROR unpacking $1" +;; +zip ) +unzip $1 >/dev/null|| answ=3 && error "ERROR unpacking $1" +;; +xzm ) +unsquashfs $1 >/dev/null 2>&1 answ=3 && error "ERROR unpacking $1" +;; +xz ) +tar -Jxf $1 >/dev/null || answ=3 && error "ERROR unpacking $1" +;; +txz ) +mktemp -d ./unpacked.XXXXXX +local targ +targ=`ls|grep unpacked` +installpkg -root $targ $1 >/dev/null 2>&1 || answ=3 && error "ERROR unpacking $1" +;; +tgz ) +mktemp -d ./unpacked.XXXXXX || answ=3 && error "ERROR unpacking $1" +local targ +targ=`ls|grep unpacked` +installpkg -root $targ $1 >/dev/null 2>&1 || answ=3 && error "ERROR unpacking $1" +;; +esac +} + +# Make a posix test +# $1=dir +make_posix_test(){ +f1=$1/._test1 +f2=$1/._test2 +touch $f1 +ln -s $f1 $f2 2>/dev/null && chmod +x $f1 2>/dev/null && [ -x $f1 ] && chmod -x $f1 2>/dev/null && [ ! -x $f1 ] && rm -f $f1 $f2 +if [ $? -ne 0 ]; then + answ=1 + rm -f $f1 $f2 >/dev/null 2>&1 + else + answ=0 +fi +} + +# Remove duplicates +# $1=file +remove_duplicates(){ +if [ ! $1 ]; then + answ=3 && error "You must supply a valid list" + return + elif [ ! -f $1 ]; then + error "Could not find $1" $FUNCNAME $LINENO + cyan "Make sure the file exists and is a list" + exit + else + sort -u $1 > /tmp/.hold + rm $1 + mv /tmp/.hold $1 +fi +} + +# A simple Xdialog download gauge +# $1=title $2=text $3=link $4=rc-file +download() { +if [ $# -lt 4 ]; then + error "You must supply 4 args to: $FUNCNAME" $FUNCNAME $LINENO + cyan "\$1=title, \$2=text, \$3=link \$4=rc-file" + cyan "If you don't have an rc-file just put anything" + exit + else +touch /tmp/.dload +dl=/tmp/.dload +wget $3 -o $dl & +( +while [ "$i" != "98" -a "$f" == "" ]; do + echo $i + i=$(cat $dl 2>/dev/null| grep "%" |awk '{print $(NF-2)}'|sed 's/\(.*\)./\1/'|tail -n1) + f=$(grep "100%" $dl) + sleep 0.1 +done +) | Xdialog --title "$1" --rc-file "$4" --icon "$5" --gauge "Downloading $2...." 400x150 +[ -f $dl ] && rm -f $dl +fi +[ -f $dl ] && rm $dl +} + +# Check that a filename is slackware compatible +# If name is bad will return badname=1 +# If field has -lt 4 will return $badflds +# If $PKG_ARCH is -ne i486,x86_64,noarch,fw will return $badarch +check_slackware_name(){ +if [ $# -eq 0 ]; then + error "You must supply a slackware file name!" $FUNCNAME $LINENO + else + local FILE=${1##*/} + + # Make sure all is in lower case + FILE=`echo $FILE|tr "[:upper:]" "[:lower:]"` + + # Make sure there are no less than 4 fields + local flds=`awk -F- '{print NF}' $FILE` + [ $flds -lt 4 ] && { answ=1; return; } + + # Split package name to individual elements + eval $(echo $FILE | sed 's/\(.*\)-\([^-]*\)-\([^-]*\)-\([0-9]*\)\(.*\)*/\ + PKG_NAME=\1 PKG_VER=\2 PKG_ARCH=\3 PKG_BUILD=\4 PKG_TAG=\5/') + + # Check that package arch is legit + [ ! `echo $PKG_ARCH|egrep "i*86|x86_64|noarch|fw"` ] && { answ=1; return; } + answ=0 +fi +} + +# makes sure that is a directory is chosen, it is not on aufs +# unless in tmp or home folder (never in root) +# This function returns nopermit=1 if dir is bad. +is_on_aufs(){ +if [ $# -ne 1 ]; then + answ=3 + return + else + [ ! -d $1 ] && { answ=3; return; } + [ "`df -T $1|tail -n1|awk '{print$1}'`" == "aufs" ] && answ=0 || answ=1 +fi +} + +# Verify that this is a milis module & identify squashfs version +# $1=module path +# Returns: badext=1 bad extension | sq=4 squashfs4 | sq=3 squashfs3 | sq=0 not valid +is_squash4(){ +if [ ! $1 ]; then + error "You must supply the path to a valid Milis module" $FUNCNAME $LINENO + return + else +mname=$1 +ftype=`file $mname|egrep -o "endian|data"` +[ -z $ftype ] && answ=0 || answ=1 +fi +} + +# Silently mount a module on loopback and check is module +# Mount module to /mnt/loop +mount_module(){ +if [ ! $1 ]; then + answ=3 + return + else + is_squash4 + if [ $answ -eq 1 ]; then + answ=3 + else + mloop "$1" >/dev/null 2>&1 && answ=0 || answ=3 + fi +fi +} + +# Check if a website is online and working (silently) +# Returns url=0 if it is avaiable +silent_check_url(){ +if [ $# -lt 1 ]; then + answ=3 + error "You must supply a URL to:" $FUNCNAME $LINENO + exit + else + if (wget -q --spider --force-html --inet4-only "$1" >/dev/null 2>&1); then + answ=0 + else + answ=1 + fi +fi +} + +# Check if a website is online and working (silently) +# Returns url=0 if it is avaiable +has_internet(){ +if (wget -q --spider --force-html --inet4-only http://www.google.com >/dev/null 2>&1); then + answ=0 + else + answ=1 +fi +} + +# Check that writable flag is set +is_writable(){ +[ -w $1 ] && answ=0 || answ=1 +} + +# Get the last field in a given string with given delimiter +# $1=delimiter +get_last_field(){ +awk -F"$1" '{print$NF}' +} + +# Get the field count for given string with given delimiter +get_field_count(){ +awk -F"$1" '{print NF}' +} + +# Make a free loop if one is not present +check_free_loop_device(){ +x=`grep /dev/loop /proc/mounts | tail -n1 | cut -d " " -f1 | sed 's@/dev/loop@@'`; let y=x+1 +loop=/dev/loop$y +if [ ! -e $loop ]; then mknod $loop b 7 $y; fi +unset x loop y +} + + +# Green colored output +green() { + echo -e "\033[01;32m$@\033[00m" +} + +# Yellow colored output +yellow() { + echo -e "\033[01;33m$@\033[00m" +} + +# Red colored output +function redd() { + echo -e "\033[01;31m$@\033[00m" +} + +# Cyan colored output +cyan() { + echo -e "\033[01;36m$@\033[00m" +} + +# Blue colored output +blue() { + echo -e "\033[01;34m$@\033[00m" +} + +# Magenta colored output +magenta() { + echo -e "\033[01;35m$@\033[00m" +} + +### GTKDIALOG LIBRARIES + +## Use manual progress update like so: +## echo "My message goes here" > /tmp/.message +## manual_progress "My title goes here" +## sleep 5 (or other code) +## echo "Second update goes here" > /tmp/.message +## sleep 3 (or other code) +## kill_manual_progress +manual_progress(){ +# Open a window for progress +export MANUAL_PROGRESS=' + + + + + + PROGRESS_TXT + + + PROGRESS_BAR + + prog_counter + + + + +' +gtkdialog -c -p MANUAL_PROGRESS 2>/tmp/.progress_trap & +}; export -f manual_progress + +## This is called by the manual_progress function. +prog_counter(){ +case $STATE in +MANUAL ) +while [ A != B ]; do + MSG=`cat /tmp/.message` + echo $MSG + sleep 0.3 +done +echo "ALL DONE" +unset STATE +;; +DOWNLOAD ) +while [ A != B ]; do + if [ -f /tmp/.cdload ]; then M=`cat /tmp/.cdload`; echo "$M"; fi + sleep 0.3 + [ `grep "100%" /tmp/.message` ] && echo 1 + i=$(grep -o "[^ ]*%[^ ]*" /tmp/.message|sed "s/%//g"|tail -n1) + [ "$i" == "100" ] && i=1 + [ "$i" != "" ] && echo "$i" + sleep 0.3 +done +echo "ALL DONE" +unset STATE +;; +BUILDMODULE ) +while [ A != B ]; do + if [ ! -f /tmp/.message ]; then echo "Waiting ..."; fi + [ `grep "100%" /tmp/.message` ] && echo Finished + i=$(grep -o ...% /tmp/.message|sed -e "s/%//g" -e 's/ //g'|tail -n1) + [ "$i" != "" ] && echo "$i" + sleep 0.3 +done +echo "ALL DONE" +unset STATE +;; +* ) +while [ A != B ]; do + MSG=`cat /tmp/.message` + echo $MSG + sleep 0.3 +done +echo "ALL DONE" +unset STATE +;; +esac +[ -f /tmp/.cdload ] && rm /tmp/.cdload 2>&- +[ -f /tmp/.message ] && rm /tmp/.message 2>&- +}; export -f prog_counter + +kill_manual_progress() { +myself=`ps ax|grep MANUAL_PROGRESS|awk '{print$1}'|head -n1` +for children in `ps -o pid --ppid $myself|sed '/PID/d'`; do +kill $children >/dev/null 2>&- +done +kill $myself >/dev/null 2>&- +[ -f /tmp/.message ] && rm /tmp/.message +[ -f /tmp/.progress_trap ] && rm /tmp/.progress_trap +}; export -f kill_manual_progress + +gtk_message(){ +echo ' + + + + + + + + + + + + + + + + +exit:abort main window by X + +' | gtkdialog -s +} + +## $1=message $2=width $3=icon(file) +gtk_message_custom(){ +echo ' + + + + + + '$3' + + + + + + + + + + +exit:abort main window by X + +' | gtkdialog -s +} + +gtk_choose_file(){ +echo ' + + + '$6' + + +' +} + +start_window(){ +echo ' +' +} + +end_window(){ +echo 'exit:Cancel' +} + +txtmarkup(){ +echo '' +} + +txtcolor(){ +echo '' +} + +txtfile(){ +echo ''$2'' +} + +pixmapstock(){ +echo '' +} + +pixmapicon(){ +echo ''$1''$2'' +} + +pixmapfile(){ +echo ''$1''$2''$3'' +} + +vsep(){ +echo '' +} + +hsep(){ +echo '' +} + +butstock(){ +echo '' +} + +butcancel(){ +echo '' +} + +butyes(){ +echo '' +} + +butno(){ +echo '' +} + +butreturn(){ +echo ' + '`butcustom "Mevcut Bilgi ekranını dosyaya yazdırır /root/psinfo.txt" "Dosyaya Yazdır" btnDump stock gtk-revert-to-saved false`' + '`butcustom "Kapsamlı sistem raporunu dosyaya yazdırır /root/Desktop/psinfo.txt" "Kapsamlı Rapor Yazdır" btnReport stock gtk-go-down true`' + '`butcancel`' + +'`end_window`' +' +gtkdialog -p MILIS_BILGI > $tmpsi/dump + +[ `egrep -o "Cancel|abort" $tmpsi/dump` ] && { rm -rf $tmpsi; exit; } + +[[ `grep "Açık Dosyayı Kaydet" $tmpsi/dump` ]] && gtk_upload_report + +if [[ `grep "Kapsamlı Rapor" $tmpsi/dump` ]]; then + export STATE=MANUAL + echo "kapsamlı rapor üretiliyor ..." > /tmp/.message + manual_progress "İşleniyor" + echo "MİLİS_SÜRÜM:" > $info + cat /etc/Milis-sürüm >> $info + echo "" >> $info + echo "KERNEL/İŞLEMCİ:" >> $info + echo `uname -r` `uname -m` `uname -p`>> $info + echo "" >> $info + echo "HAFIZA/SWAP:" >> $info + free -m >> $info + echo "" >> $info + echo "BLOK AYGITLARI:" >> $info + ls -1 /sys/block | grep -v loop | sed s/@// >> $info + echo "" >> $info + echo "BÖLÜMLER:" >> $info + blkid | grep -v squashfs >> $info + echo "" >> $info + echo "BAĞLANMIŞ BÖLÜMLER:" >> $info + df -Th | grep -v devtmpfs >> $info + echo "" >> $info + echo "CHEATCODES:" >> $info + cat /proc/cmdline >> $info + echo "" >> $info + echo "LIVEDBG BİLGİ:" >> $info + cat /var/log/Milis-livedbg >> $info + echo "" >> $info + echo "SES KARTLARI:" >> $info + cat /proc/asound/cards >> $info + echo "" >> $info + echo "LSPCI ÇIKTI:" >> $info + lspci -knn >> $info + echo "" >> $info + echo "LSUSB ÇIKTI:" >> $info + lsusb -t >> $info + echo "" >> $info + echo "LSMOD ÇIKTI:" >> $info + lsmod >> $info + echo "" >> $info + echo "PİL BİLGİSİ:" >> $info + dmidecode -t 22|sed -e '/dmidecode/d' -e '/SMBIOS/d' -e '/Handle/d' -e '/^$/d' >> $info + echo "" >> $info + echo "ANAGÖVDE BİLGİ:" >> $info + dmidecode -t 3|sed -e '/dmidecode/d' -e '/SMBIOS/d' -e '/Handle/d' -e '/^$/d' >> $info + echo "" >> $info + echo "SİSTEM BİLGİ:" >> $info + dmidecode -t 1|sed -e '/dmidecode/d' -e '/SMBIOS/d' -e '/Handle/d' -e '/^$/d' >> $info + echo "" >> $info + echo "KULLANICI BİLGİ:" >> $info + grep -v "\!" /etc/shadow|cut -d':' -f1 >> $info + echo "" >> $info + echo "SON AÇILMA:" >> $info + who -b|sed 's/^[ \t]*//' >> $info + echo "Uptime (hr:min) : `uptime|awk '{print$3}'|sed 's/,//g'`" >> $info + echo "" >> $info + echo "LOADED MODULES:" >> $info + ls -1 /mnt/live/memory/images >> $info + echo "" >> $info + echo "LOADED PACKAGES:" >> $info + ls -1 /var/log/packages >> $info + echo "" >> $info + echo "/var/log/messages:" >> $info + tac /var/log/messages | sed -n '1,/kmsg started./p' | tac >> $info + echo "" >> $info + echo "EKRAN:" >> $info + xrandr >> $info 2>/dev/null + echo "" >> $info + echo "OpenGL sürüm:" >> $info + glxinfo | grep -i opengl >> $info + echo "" >> $info + echo "/var/log/Xorg.0.log:" >> $info + cat /var/log/Xorg.0.log >> $info 2>/dev/null + echo "" >> $info + echo "XSESSION HATALARI:" >> $info + [ -f /root/.xsession-HATALARI ] && echo "Kullanıcı: root" >> $info && tail -n300 /root/.xsession-HATALARI >> $info + for a in `grep -v "\!" /etc/shadow|cut -d':' -f1|sed 'root/d'`; do + [ -f /home/$a/.xsession-HATALARI ] && echo "Kullanıcı: $a" >> $info && tail -n300 /home/$a/.xsession-HATALARI >> $info + done + kill_manual_progress + gtk_upload_report +fi + +pastebin_message(){ +echo ' + + + + + + + + + + + + + + + + + +' | gtkdialog -s +}; export -f pastebin_message + +## If Kullanıcı chose to upload then do it, else dump to /root/desktop +if [ `egrep -o "Yes|yes" $tmpsi/upload.tmp` ]; then + has_internet + if [ $answ -eq 0 ]; then + export STATE=MANUAL + echo "Lütfen bekleyiniz,yükleniyor" > /tmp/.message + manual_progress "Pastebin" + wgetpaste -n Milis-Kullanıcı -s codepad $info > $tmpsi/link.tmp + kill_manual_progress + export lnk=`awk '{print$NF}' < $tmpsi/link.tmp` + echo $lnk > /tmp/pastebin-link.txt + pastebin_message "Your file was uploaded to $lnk (You may select and copy this text) and this address is now in the file /tmp/pastebin-link.txt." 500 gtk-yes + else + cp $info /root/Desktop/psinfo_report.txt + gtk_message "No internet connection found. Your report was placed at /root/Desktop/psinfo_report.txt" 450 gtk-dialog-error + fi + else + cp $info /root/Desktop/psinfo_report.txt + gtk_message "Your file has been placed at /root/Desktop/psinfo_report.txt" 500 gtk-yes +fi +rm -rf $tmpsi