Difference between revisions of "Some scripts"

From PeerFreedom Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 280: Line 280:
 
DATE_END="`date \"+%Y-%m-%d %H:%M:%S\"`"
 
DATE_END="`date \"+%Y-%m-%d %H:%M:%S\"`"
 
echo "* Script ended at $DATE_END\n\n\n" | tee -a $LOG_FILE
 
echo "* Script ended at $DATE_END\n\n\n" | tee -a $LOG_FILE
 +
</pre>
 +
 +
<pre>
 +
#!/bin/sh
 +
# copy installed package aaa from vm bbb to dom0 in folder bbb.aaa/
 +
 +
if [ "$#" -ne "2" ];
 +
then
 +
        echo "Usage: $0 [VMname] [packagename], if run with sudo then this copy all files to to ROOT fs /"
 +
        exit 1
 +
fi
 +
 +
if [ "$UID" == "0" ];
 +
then
 +
        echo "Run as root"
 +
fi
 +
 +
VM=$1
 +
PACKAGE=$2
 +
 +
TEMP_FILE1=temp1
 +
 +
mkdir ${VM}.${PACKAGE} && cd ${VM}.${PACKAGE}
 +
 +
echo "Import files from package ${PACKAGE} on ${VM}"
 +
qvm-run --pass-io ${VM} "dpkg -L ${PACKAGE}" > ${TEMP_FILE1}
 +
PACKAGE_IN_SYSTEM=$?
 +
 +
if [ ${PACKAGE_IN_SYSTEM} == "0" ];
 +
then
 +
for i in `cat ${TEMP_FILE1} | tr "\n" " "`; do
 +
        echo "Processing ${i}"
 +
        FILE_TYPE=`qvm-run --pass-io ${VM} "stat --printf=\"%F\n\" ${i}"`
 +
        case "${FILE_TYPE}" in "directory" )
 +
                if [ "$UID" == "0" ];
 +
                then
 +
                        echo "We create dir ... ${i}"
 +
                        sudo su -c "mkdir -p ${i}"
 +
                fi
 +
                ;;
 +
        esac
 +
        case "${FILE_TYPE}" in "regular file" | "regular empty file" | "symbolic link" )
 +
                if [ "$UID" != "0" ];
 +
                then
 +
                        echo "Run as normal user"
 +
                        FILE=`basename ${i}`
 +
                        echo "Copying file ${i} to ... ${FILE}"
 +
                        qvm-run --pass-io ${VM} "cat ${i}" > ${FILE}
 +
                fi
 +
                if [ "$UID" == "0" ];
 +
                then
 +
                        echo "Run as UNNormal user"
 +
                        echo "Copying file ${i} to ... root filesystem /"
 +
                        sudo su -c "qvm-run --pass-io ${VM} \"cat ${i}\" > ${i}"
 +
                fi
 +
 +
                ;;
 +
        esac
 +
done
 +
fi
 
</pre>
 
</pre>

Latest revision as of 01:28, 23 March 2020

cat cpufreq.sh
#!/bin/sh

CPUS=`cat /proc/cpuinfo | grep processor | awk -F ' ' '{printf("%s ",$3);}'`

for i in ${CPUS}; do
        FREQ=`cpufreq-info -c ${i} -f`
        echo "$i: $FREQ";
done
cat cputemp.sh
TEMPERATURECPU=`cat /sys/devices/virtual/thermal/thermal_zone0/temp`
T_CPU=`expr $TEMPERATURECPU / 1000`
echo "$T_CPU st C"
__red_color="\033[01;31m"
__green_color="\033[01;32m"
__yellow_color="\033[01;33m"
__blue_color="\033[01;34m"
__purple_color="\033[01;35m"
__lightgray_color="\033[00;37m"
__last_color="\033[01;00m"

function git_branch() {
    gb=$(__git_ps1 '%s')
    echo ${gb}
}

# use to show the current config local/global user/email in GIT
function git_userlocalglobal() {
    local exit=$?
    local ret=0
    local repo_info
    
    repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
        --is-bare-repository --is-inside-work-tree \
        --short HEAD 2>/dev/null)"
    rev_parse_exit_code="$?"
    
    if [ -z "$repo_info" ]; then
        return $exit
    fi
    
    local GIT_UN_LOCAL=`git config --local user.name`;
    local GIT_UN_GLOBAL=`git config --global user.name`;
    local GIT_UE_LOCAL=`git config --local user.email`;
    local GIT_UE_GLOBAL=`git config --global user.email`;
    
    gb=$(git_branch)

    if [[ $GIT_UN_LOCAL != "" ]];
    then
        GIT_UN_LOCAL=${GIT_UN_LOCAL:-"![local username empty]!"}
        GIT_UE_LOCAL=${GIT_UE_LOCAL:-"![local useremail empty]!"}
        __git_username="[ ${gb} # (${GIT_UN_LOCAL} / ${GIT_UE_LOCAL}) ]"
        ret=100
    else
        GIT_UN_GLOBAL=${GIT_UN_GLOBAL:="![global username empty]!"}
        GIT_UE_GLOBAL=${GIT_UE_GLOBAL:="![global useremail empty]!"}
        __git_username="[ ${gb} @ (${GIT_UN_GLOBAL} / ${GIT_UE_GLOBAL}) ]"
        ret=200
    fi;
    
    if [[ ret -eq 100 ]]; then
        printf -- "${__red_color}%s"  "${__git_username}"
    fi
    if [[ ret -eq 200 ]]; then
        printf -- "${__yellow_color}%s"  "${__git_username}"
    fi
}

function set_PS1 {
    local __user_and_host="${__green_color}\u@\h \t (\#)"
    local __cur_location="${__blue_color}\w"
    local __prompt_tail="${__lightgray_color}$"
        
    export PS1="${__user_and_host} ${__cur_location} \$(git_userlocalglobal) ${__prompt_tail} ${__last_color}\n"
}
set_PS1
#!/usr/bin/python

import sys
import csv
import os
import shutil

if len(sys.argv) < 2:
    print "{} file_name.txt".format(sys.argv[0])
    exit(1)
    
with open(sys.argv[1], 'rt') as file:
    folder_name=file.name.split(".")[0]
    #print folder_name
    
    if os.path.exists(folder_name):
        shutil.rmtree(folder_name)
        
    os.mkdir(folder_name)
    
    line = csv.reader(file, delimiter='|', quotechar='|')
    for l in line:
        #print l[0]
        #print l[1]
        
        cmd1 = "youtube-dl --no-check-certificate --no-playlist -x --audio-format mp3 -o template_file.mp3 '"+l[0]+"'"
        cmd2 = "/usr/bin/ffmpeg -i template_file.mp3 -metadata title='"+l[1]+"' -metadata author='"+l[1]+"' -metadata composer='"+l[1]+"' -codec:a libmp3lame -qscale:a 0 '"+folder_name+"/"+l[1]+".mp3'"
        cmd3 = "rm -f template_file.mp3"
        
        os.system(cmd1)
        os.system(cmd2)
        os.system(cmd3)
#!/bin/sh

EXTENSION_NAME="txt"
AUDIO_EXTENSION_NAME="mp3"
INDEX_FILENAME_START=1
RM_INTERACTIVE="" #-i

for FILES_TXT in `ls *.${EXTENSION_NAME}`;
do
    FILE_NAME=${FILES_TXT};
    NAME=`basename ${FILE_NAME} .${EXTENSION_NAME}`;
    INDEX=${INDEX_FILENAME_START};
    
    FOLDER_NAME=${NAME};
    
    NR_LINKS=`cat ${FILE_NAME} | wc -l`
    
    if [ ${NR_LINKS} -eq 0 ];
    then
        continue;
    fi
    
    mkdir ${FOLDER_NAME};
    
    for LINK_ORIGINAL in `awk -F "\n" '{print $1}' ${FILE_NAME} | grep -v '^#'`;
    do
        LINK=`echo ${LINK_ORIGINAL} | awk -F "&list=" '{print $1}'`;
        MP3_NAME="${NAME}_no${INDEX}.${AUDIO_EXTENSION_NAME}";
        
        PATH_OUT="${FOLDER_NAME}/${MP3_NAME}";
        
        #echo ${PATH_OUT};
        #echo ${LINK};
        
        #youtube-dl -f bestaudio  "${LINK}" --exec "/usr/bin/ffmpeg -i {}  -codec:a libmp3lame -qscale:a 0 ${PATH_OUT}"
        
        youtube-dl --no-playlist -x --audio-format mp3 -o template_file.mp3 "${LINK}" 
        /usr/bin/ffmpeg -i template_file.mp3 -codec:a libmp3lame -qscale:a 0 ${PATH_OUT}
        rm -f template_file.mp3
        
        INDEX=`expr ${INDEX} + 1`;
    done
done
#!/bin/bash

oldIFS=$IFS
IFS=$'\n'

for line in $(cat inputfile);
do
	start=$(echo $line | awk -F '|' '{printf("%s", $1)}')
	end=$(echo $line | awk -F '|' '{printf("%s", $2)}')
	title=$(echo $line | awk -F '|' '{printf("%s", $3)}')

	$(ffmpeg -ss $start -t $end -i $1 -acodec copy "$title.mp3")
	echo $title
done

IFS=$oldIFS
#!/bin/sh

OUTPUT_FILE="out.mp3"

for LIST_FOLDERS in `find . -type d -maxdepth 1 | cut -b3- | sort`;
do
    #echo ${LIST_FOLDERS};
    ( 
        cd ${LIST_FOLDERS};
        ls -1 -r --sort time *no*.mp3 | xargs printf "file '%s'\n" > list_mp3.txt;
        /usr/bin/ffmpeg -f concat -safe 0 -i list_mp3.txt -c copy "${LIST_FOLDERS}_output.mp3"
        rm -f list_mp3.txt
    )
done
#!/bin/sh

CPUS=`cat /proc/cpuinfo | grep processor | awk -F ' ' '{printf("%s ",$3);}'`

#F=$1
F=2400
for i in ${CPUS}; do
	echo "CPU $i: set max ${F} KHz";
	FREQ=`cpufreq-set -c ${i} -u 2.4GHz -g performance`
done
#!/bin/sh

CPUS=`cat /proc/cpuinfo | grep processor | awk -F ' ' '{printf("%s ",$3);}'`

F="ondemand"
for i in ${CPUS}; do
	echo "CPU $i: set ${F}";
	FREQ=`cpufreq-set -c ${i} -g ${F}`
done
#!/bin/sh

CPUS=`cat /proc/cpuinfo | grep processor | awk -F ' ' '{printf("%s ",$3);}'`

F="performance"
for i in ${CPUS}; do
	echo "CPU $i: set ${F}";
	FREQ=`cpufreq-set -c ${i} -g ${F}`
done
#!/bin/sh

CPUS=`cat /proc/cpuinfo | grep processor | awk -F ' ' '{printf("%s ",$3);}'`

F="powersave"
for i in ${CPUS}; do
	echo "CPU $i: set ${F}";
	cpufreq-set -c ${i} -g ${F}
done
#!/bin/bash

A=(vol-175a3b54 vol-382c477b vol-8c027acf vol-93d6fed0 vol-71600106 vol-79f7970e vol-e3d6a894 vol-d9d6a8ae vol-8dbbc2fa vol-98c2bbef vol-ae7ed9e3 vol-5540e618 vol-9e3bbed3 vol-993bbed4 vol-a83bbee5 vol-ff52deb2)
B=(vol-175a3b54 vol-e38d0c94 vol-2a19386a vol-b846c5cf vol-98c2bbef vol-7320102b vol-8f6226cc vol-27991850 vol-71600106 vol-615e1222)

not_in_a=()

for item1 in "${B[@]}"; do
    for item2 in "${A[@]}"; do
        [[ $item1 == "$item2" ]] && continue 2
    done

    # If we reached here, nothing matched.
    not_in_a+=( "$item1" )
done

printf '%s\n' "${not_in_a[@]}"
#!/bin/sh

COMMENT=""
if [ -n $1 ]
then
        COMMENT="$1"
fi

LOG_FILE="`basename -s .sh $0`.txt"
#LOG_FILE=/dev/null
DATE_START="`date \"+%Y-%m-%d %H:%M:%S\"`"
echo "* Script start at $DATE_START" | tee -a $LOG_FILE
if [ $COMMENT ]
then
echo "(Comment: $COMMENT)" | tee -a $LOG_FILE
fi
#for i in `find . -maxdepth 2 -type d -name ".git" -exec dirname {} \;`; do echo "Enter $i..." | tee -a $LOG_FILE; (cd $i && git fetch && git pull) | tee -a $LOG_FILE; done
for i in `find . -maxdepth 2 -type d -name ".git" -exec dirname {} \;`; do echo "Enter $i..." | tee -a $LOG_FILE; (cd $i && git fetch && git pull --rebase --stat) | tee -a $LOG_FILE; done
DATE_END="`date \"+%Y-%m-%d %H:%M:%S\"`"
echo "* Script ended at $DATE_END\n\n\n" | tee -a $LOG_FILE
#!/bin/sh
# copy installed package aaa from vm bbb to dom0 in folder bbb.aaa/

if [ "$#" -ne "2" ];
then
        echo "Usage: $0 [VMname] [packagename], if run with sudo then this copy all files to to ROOT fs /"
        exit 1
fi

if [ "$UID" == "0" ];
then
        echo "Run as root"
fi

VM=$1
PACKAGE=$2

TEMP_FILE1=temp1

mkdir ${VM}.${PACKAGE} && cd ${VM}.${PACKAGE}

echo "Import files from package ${PACKAGE} on ${VM}"
qvm-run --pass-io ${VM} "dpkg -L ${PACKAGE}" > ${TEMP_FILE1}
PACKAGE_IN_SYSTEM=$?

if [ ${PACKAGE_IN_SYSTEM} == "0" ];
then
for i in `cat ${TEMP_FILE1} | tr "\n" " "`; do
        echo "Processing ${i}"
        FILE_TYPE=`qvm-run --pass-io ${VM} "stat --printf=\"%F\n\" ${i}"`
        case "${FILE_TYPE}" in "directory" )
                if [ "$UID" == "0" ];
                then
                        echo "We create dir ... ${i}"
                        sudo su -c "mkdir -p ${i}"
                fi
                ;;
        esac
        case "${FILE_TYPE}" in "regular file" | "regular empty file" | "symbolic link" )
                if [ "$UID" != "0" ];
                then
                        echo "Run as normal user"
                        FILE=`basename ${i}`
                        echo "Copying file ${i} to ... ${FILE}"
                        qvm-run --pass-io ${VM} "cat ${i}" > ${FILE}
                fi
                if [ "$UID" == "0" ];
                then
                        echo "Run as UNNormal user"
                        echo "Copying file ${i} to ... root filesystem /"
                        sudo su -c "qvm-run --pass-io ${VM} \"cat ${i}\" > ${i}"
                fi

                ;;
        esac
done
fi