家用老机的装机脚本 & 一些有用的脚本

仅供存放个人的配置文件,不要在本版发问。
回复
头像
chenjietao
帖子: 130
注册时间: 2010-09-21 1:50

家用老机的装机脚本 & 一些有用的脚本

#1

帖子 chenjietao » 2012-08-20 21:36

archlinux+openbox+tint2-svn+nitrogen+thunar+volumeicon+conky-lua+lxterminal
archlinux+openbox+tint2-svn+nitrogen+thunar+volumeicon+conky-lua+lxterminal
bang.tar.gz
archlinux+openbox+tint2-svn+nitrogen+thunar+volumeicon+conky-lua+lxterminal
(958.96 KiB) 已下载 391 次
conky.tar.gz
(83.56 KiB) 已下载 403 次
conky2.tar.gz
(73.9 KiB) 已下载 360 次
conky2
conky2
nitrogen自动换壁纸脚本(后台脚本):
[bash]#!/bin/bash
dir_of_wallpapers=/usr/share/wallpapers/
while true; do
sleep 300 ##避免开机马上换壁纸
file_path="`find "$dir_of_wallpapers" \(-iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) |shuf |head -1`" ##列出图像文件并乱序,取第一行
nitrogen --set-scaled --save "$file_path"
sleep 600
done[/bash]


osdlyrics随audacious启动及关闭(后台脚本):
[bash]#!/bin/bash
while true; do
[ -n "$(pgrep audacious)" ] && [ -z "$(pgrep osdlyrics)" ] && osdlyrics &
[ -z "$(pgrep audacious)" ] && [ -n "$(pgrep osdlyrics)" ] && killall osdlyrics
sleep 1
done[/bash]


播放网页flash时防止黑屏的脚本(后台脚本):
[bash]#!/bin/bash
while true; do
_pid=()
_pid=($(ps aux | grep -E "libflashplayer.so|operapluginwrapper-native" |grep -v "grep" | awk '{print $2}'))
for PID in ${_pid[@]}; do
[[ "$(lsof -p $PID |grep -E "/dev/snd/timer|/dev/shm/pulse-shm|/tmp/Flash" )" ]] && xset -dpms
done
xset +dpms
sleep 75
done[/bash]


视频播放时防止黑屏的脚本(后台脚本):
[bash]#!/bin/bash
while true; do
_pid=()
_pid=($(pidof mplayer smplayer totem vlc kaffeine)) # player commands such as 'mplayer' 'vlc' should be changed to what you have installed.
for PID in ${_pid[@]}; do
[ "$(lsof -p $PID |grep -E "/dev/snd/timer|/dev/shm/pulse-shm")" ] && xset -dpms
done
xset +dpms
sleep 60
done
[/bash]


音乐文件批量改名脚本:(修改自xiooli的脚本)
[bash]#!/bin/bash
# coded by xiooli
#用法:
# 1,重命名:先cd到你的音乐目录,然后在终端里运行脚本mrename,将会对当前目录的所有拥有标签
#的音乐进行重命名,格式为:艺人-标题.扩展名,改名对应情况会记录在当前目录下的 remane-时间.list 文
#件里,方便恢复;
# 2,恢复原名:mrename -r ./remane-时间.list
#注意:
# 需要安装python-mutagen包,运行时会更新音乐标签的编码为当前locale。

rename() {
list="rename-$(date +%m-%d-%k-%M).list"
>"$list"
ls |while read name;do
[[ $( mid3v2 -l "$name" |grep TIT2 |sed 's/^.*=//' ) ]] || continue
mid3iconv -e gb2312 "$name"
ar=`mid3v2 -l "$name" |grep TPE1 |sed 's/^.*=//'`
ti=`mid3v2 -l "$name" |grep TIT2 |sed 's/^.*=//'`
tl=`echo "$name" |sed 's/^.*\.//'`
[[ "$name" != "$ar-$ti.$tl" ]] && mv "$name" "$ar-$ti.$tl" &&\
echo -e "重命名\033[;32m <$name> \033[0m为\033[;32m <$ar-$ti.$tl> \033[0m" \
&& echo "$name:$ar-$ti.$tl" >>"$list"
done

}
recover() {
for lst in `cat $1 |sort |uniq`;do
nm1=`echo $lst |sed 's/^.*://'`
nm0=`echo $lst |sed 's/:.*$//'`
[ -e "$nm1" -a ! -e "$nm0" ] && mv "$nm1" "$nm0" &&\
echo -e "恢复\033[;32m <$nm1> \033[0m为\033[;32m <$nm0> \033[0m"
done
}

if [[ "$1" = "-r" ]];then
echo "即将从 "$2" 中恢复命名"
read -p "确认?y/n :" a
if [[ $a = "y" ]];then
[[ "$2" ]] && recover "$2"
[[ "$2" ]] || echo "未选择list文件!"
else
exit
fi
else
echo "即将重命名当前文件夹的所有音乐"
read -p "确认?y/n :" b
[[ $b = "y" ]] && rename
fi
[/bash]


搜狗词库转化成txt的python脚本:
[python]#!/usr/bin/python2
# -*- coding: utf-8 -*-


import struct
import sys
import binascii
import pdb
#搜狗的scel词库就是保存的文本的unicode编码,每两个字节一个字符(中文汉字或者英文字母)
#找出其每部分的偏移位置即可
#主要两部分
#1.全局拼音表,貌似是所有的拼音组合,字典序
# 格式为(index,len,pinyin)的列表
# index: 两个字节的整数 代表这个拼音的索引
# len: 两个字节的整数 拼音的字节长度
# pinyin: 当前的拼音,每个字符两个字节,总长len
#
#2.汉语词组表
# 格式为(same,py_table_len,py_table,{word_len,word,ext_len,ext})的一个列表
# same: 两个字节 整数 同音词数量
# py_table_len: 两个字节 整数
# py_table: 整数列表,每个整数两个字节,每个整数代表一个拼音的索引
#
# word_len:两个字节 整数 代表中文词组字节数长度
# word: 中文词组,每个中文汉字两个字节,总长度word_len
# ext_len: 两个字节 整数 代表扩展信息的长度,好像都是10
# ext: 扩展信息 前两个字节是一个整数(不知道是不是词频) 后八个字节全是0
#
# {word_len,word,ext_len,ext} 一共重复same次 同音词 相同拼音表

#拼音表偏移,
startPy = 0x1540;


#汉语词组表偏移
startChinese = 0x2628;

#全局拼音表

GPy_Table ={}

#解析结果
#元组(词频,拼音,中文词组)的列表
GTable = []

def byte2str(data):
'''将原始字节码转为字符串'''
i = 0;
length = len(data)
ret = u''
while i < length:
x = data + data[i+1]
t = unichr(struct.unpack('H',x)[0])
if t == u'\r':
ret += u'\n'
elif t != u' ':
ret += t
i += 2
return ret
#获取拼音表
def getPyTable(data):

if data[0:4] != "\x9D\x01\x00\x00":
return None
data = data[4:]
pos = 0
length = len(data)
while pos < length:
index = struct.unpack('H',data[pos]+data[pos+1])[0]
#print index,
pos += 2
l = struct.unpack('H',data[pos]+data[pos+1])[0]
#print l,
pos += 2
py = byte2str(data[pos:pos+l])
#print py
GPy_Table[index]=py
pos += l

#获取一个词组的拼音
def getWordPy(data):
pos = 0
length = len(data)
ret = u''
while pos < length:

index = struct.unpack('H',data[pos]+data[pos+1])[0]
ret += GPy_Table[index]
pos += 2
return ret

#获取一个词组
def getWord(data):
pos = 0
length = len(data)
ret = u''
while pos < length:

index = struct.unpack('H',data[pos]+data[pos+1])[0]
ret += GPy_Table[index]
pos += 2
return ret

#读取中文表
def getChinese(data):
#import pdb
#pdb.set_trace()

pos = 0
length = len(data)
while pos < length:
#同音词数量
same = struct.unpack('H',data[pos]+data[pos+1])[0]
#print '[same]:',same,

#拼音索引表长度
pos += 2
py_table_len = struct.unpack('H',data[pos]+data[pos+1])[0]
#拼音索引表
pos += 2
py = getWordPy(data[pos: pos+py_table_len])

#中文词组
pos += py_table_len
for i in xrange(same):
#中文词组长度
c_len = struct.unpack('H',data[pos]+data[pos+1])[0]
#中文词组
pos += 2
word = byte2str(data[pos: pos + c_len])
#扩展数据长度
pos += c_len
ext_len = struct.unpack('H',data[pos]+data[pos+1])[0]
#词频
pos += 2
count = struct.unpack('H',data[pos]+data[pos+1])[0]

#保存
GTable.append((count,py,word))

#到下个词的偏移位置
pos += ext_len


def deal(file_name):
print '-'*60
f = open(file_name,'rb')
data = f.read()
f.close()


if data[0:12] !="\x40\x15\x00\x00\x44\x43\x53\x01\x01\x00\x00\x00":
print "确认你选择的是搜狗(.scel)词库?"
sys.exit(0)
#pdb.set_trace()

print "词库名:" ,byte2str(data[0x130:0x338])#.encode('GB18030')
print "词库类型:" ,byte2str(data[0x338:0x540])#.encode('GB18030')
print "描述信息:" ,byte2str(data[0x540:0xd40])#.encode('GB18030')
print "词库示例:",byte2str(data[0xd40:startPy])#.encode('GB18030')

getPyTable(data[startPy:startChinese])
getChinese(data[startChinese:])


if __name__ == '__main__':

#将要转换的词库添加在这里就可以了
o = ['计算机词汇大全【官方推荐】.scel',
'IT计算机.scel',
'成语.scel',
'古诗词名句.scel',
'成语俗语【官方推荐】.scel',
'手机词汇大全【官方推荐】.scel',
'网络流行新词【官方推荐】.scel',
'歇后语集锦【官方推荐】.scel',
'饮食大全【官方推荐】.scel',
]

for f in o:
deal(f)

#保存结果
f = open('sougou.txt','w')
for count,py,word in GTable:
#GTable保存着结果,是一个列表,每个元素是一个元组(词频,拼音,中文词组),有需要的话可以保存成自己需要个格式
#我没排序,所以结果是按照上面输入文件的顺序
f.write( unicode('{%(count)s}' %{'count':count}+py+' '+ word).encode('GB18030') )#最终保存文件的编码,可以自给改
f.write('\n')
f.close()
[/python]

url编码解码脚本(就是那种%e7%bc%96%e7%a0%81的字符串):
[bash]#!/bin/bash
[ "$1" ] || exit
str="${1//+/ }"
echo -e "${str//\%/\x}"
[/bash]
或者
[bash]#!/bin/bash
[ "$1" ] || exit
str="$(echo $1 |sed 's/+/ /g; s/%\(..\)/\\x\1/g; ' )"
echo -e "$str"
[/bash]

修改及翻译:全屏看视频时延迟屏保和屏幕电源管理的脚本 修改自lightOn.sh
[bash]#!/bin/bash
# lightsOn.sh

# Copyright (c) 2013 iye.cba at gmail com
# url: https://github.com/iye/lightsOn
# This script is licensed under GNU GPL version 2.0 or above

# Description: Bash script that prevents the screensaver and display power
# management (DPMS) to be activated when you are watching Flash Videos
# fullscreen on Firefox and Chromium.
# Can detect mplayer, minitube, and VLC when they are fullscreen too.
# Also, screensaver can be prevented when certain specified programs are running.
# lightsOn.sh needs xscreensaver or kscreensaver to work.
# 说明:Bash脚本:在你看全屏Flash视频,或检测到用mplayer、minitube和VLC等播放器全屏时,
# 阻止屏幕保护程序和显示器电源管理(DPMS)被激活。当某些规定的程序运行时也能阻止屏保激活。


# HOW TO USE: Start the script with the number of seconds you want the checks
# for fullscreen to be done. Example:
# "./lightsOn.sh 120 &" will Check every 120 seconds if Mplayer, Minitube
# VLC, Firefox or Chromium are fullscreen and delay screensaver and Power Management if so.
# You want the number of seconds to be ~10 seconds less than the time it takes
# your screensaver or Power Management to activate.
# If you don't pass an argument, the checks are done every 50 seconds.
# 如何使用:用你想全屏检查间隔的秒数作为参数来启动脚本。例如:
# "./lightsOn.sh 120 &" 将每隔120秒检查一次进程是否运行或是否在全屏看视频并
# 延迟屏保和电源管理。 此秒数应当至少比你屏保或电源管理激活所需时间小10秒。
# 如果你没传递参数,默认每隔50秒做一次检查。
#
# An optional array variable exists here to add the names of programs that will delay the screensaver if they're running.
# This can be useful if you want to maintain a view of the program from a distance, like a music playlist for DJing,
# or if the screensaver eats up CPU that chops into any background processes you have running,
# such as realtime music programs like Ardour in MIDI keyboard mode.
# If you use this feature, make sure you use the name of the binary of the program (which may exist, for instance, in /usr/bin).
# 这里还有一个可选的数组变量,如果你希望一些程序运行时延迟屏保,你可以添加这些程序名到这个数组里。
# 这可能很有用:假如你想从远处能保持程序的视图,如DJ的音乐播放列表;或者假如你运行多个后台程序时屏保程序会占用CPU,
# 如Ardour in MIDI keyboard mode这样的实时音乐节目。
# 如果你要使用这个功能,确保你的二进制程序名称正确(可能存在于/usr/bin里)。

# Modify these variables if you want this script to detect if Mplayer,
# VLC, Minitube, or Firefox or Chromium Flash Video are Fullscreen and disable
# xscreensaver/kscreensaver and PowerManagement.
# 如果你想检测Mplayer、Minitube、VLC、Flash视频是否全屏并禁止屏保和电源管理的话,修改相应的值为1。
flash_detection=1
mplayer_detection=1
vlc_detection=1
minitube_detection=1
gnome_mplayer_detection=1
smplayer_detection=1
totem_detection=1

# Names of programs which, when running, you wish to delay the screensaver.
# 希望运行时延迟屏保的程序名
delay_progs=() # For example ('ardour2' 'gmpc')


# YOU SHOULD NOT NEED TO MODIFY ANYTHING BELOW THIS LINE
# 这一行下面的请不要修改任何东西

# enumerate all the attached screens
# 枚举所有连上的屏幕
displays=""
while read id
do
displays="$displays $id"
done < <(xvinfo | sed -n 's/^screen #\([0-9]\+\)$/\1/p')

# Detect screensaver been used
# 检测使用的屏保程序
if [ `pidof xscreensaver` ]; then
screensaver=xscreensaver
elif [ `pidof gnome-screensaver` ]; then
screensaver=gnome-screensaver
elif [ `pidof cinnamon-screensaver` ]; then
screensaver=cinnamon-screensaver
elif [ `pidof kscreensaver` ]; then # Effect on old KDE version 对旧版KDE有效
screensaver=kscreensaver
elif [ `grep -iw "enabled=true" $HOME/.kde*/share/config/kscreensaverrc` ]; then #Effect on new KDE version 对新版KDE有效
screensaver=kscreensaver
else
screensaver=None
echo "No screensaver detected"
fi


checkDelayProgs()
{
for prog in "${delay_progs[@]}"; do
if [ `pidof "$prog"` ]; then
echo "Delaying the screensaver because a program on the delay list, \"$prog\", is running..."
delayScreensaver
break
fi
done
}

checkFullscreen()
{
# loop through every display looking for a fullscreen window 遍历每个屏幕寻找一个全屏窗口
for display in $displays
do
#get id of active window and clean output 获得当前活动窗口id并整理输出
activ_win_id=`DISPLAY=:0.${display} xprop -root _NET_ACTIVE_WINDOW`
activ_win_id=${activ_win_id:40:9}
# Check if Active Window (the foremost window) is in fullscreen state 检查当前活动窗口是否全屏状态
isActivWinFullscreen=`DISPLAY=:0.${display} xprop -id $activ_win_id | grep _NET_WM_STATE_FULLSCREEN`
if [ "$isActivWinFullscreen" ];then
isAppRunning
var=$?
if [[ $var -eq 1 ]];then
delayScreensaver
fi
fi
done
}


isAppRunning()
{
#Get PID of active window 获取活动窗口的PID
activ_win_pid=`xprop -id $activ_win_id | grep "_NET_WM_PID(CARDINAL)"`
activ_win_pid=${activ_win_pid##* }
if [ $flash_detection == 1 ]; then
if [[ `lsof -p $activ_win_pid | grep flashplayer` ]]; then
return 1
fi
fi
if [ $mplayer_detection == 1 ];then
if [[ `ps p $activ_win_pid o comm=` = "mplayer" ]];then
return 1
fi
fi
if [ $vlc_detection == 1 ];then
if [[ `ps p $activ_win_pid o comm=` = "vlc" ]];then
return 1
fi
fi
if [ $minitube_detection == 1 ];then
if [[ `ps p $activ_win_pid o comm=` = "minitube" ]];then
return 1
fi
fi
if [ $gnome_mplayer_detection == 1 ];then
if [[ `ps p $activ_win_pid o comm=` = "gnome-mplayer" ]];then
return 1
fi
fi
if [ $smplayer_detection == 1 ];then
if [[ `ps p $activ_win_pid o comm=` = "smplayer" ]];then
return 1
fi
fi
if [ $totem_detection == 1 ];then
if [[ `ps p $activ_win_pid o comm=` = "totem" ]];then
return 1
fi
fi
return 0
}


delayScreensaver()
{
# reset inactivity time counter so screensaver is not started 重置不活动时间令屏幕保护程序不启动
if [ "$screensaver" == "xscreensaver" ]; then
xscreensaver-command -deactivate > /dev/null
elif [ "$screensaver" == "gnome-screensaver" ]; then
gnome-screensaver-command --deactivate > /dev/null
elif [ "$screensaver" == "cinnamon-screensaver" ]; then
cinnamon-screensaver-command --deactivate > /dev/null
elif [ "$screensaver" == "kscreensaver" ]; then
qdbus org.freedesktop.ScreenSaver /ScreenSaver SimulateUserActivity > /dev/null
fi
#Check if DPMS is on. If it is, deactivate and reactivate again. If it is not, do nothing. 检查DPMS是否启用。如果是,使其关闭并重新激活。如果不是,不做任何事。
dpmsStatus=`xset -q | grep -ce 'DPMS is Enabled'`
if [ $dpmsStatus == 1 ];then
xset -dpms
xset dpms
fi
}


delay=$1
# If argument empty, use 50 seconds as default.If argument is not integer quit.
# 假如参数为空,使用50秒作为默认值。参数不是整数时退出。
if [ -z "$1" ];then
delay=50
fi
if [[ $1 = *[^0-9]* ]]; then
echo "The Argument \"$1\" is not valid, not an integer"
echo "Please use the time in seconds you want the checks to repeat."
echo "You want it to be ~10 seconds less than the time it takes your screensaver or DPMS to activate"
exit 1
fi

while true
do
checkDelayProgs
checkFullscreen
sleep $delay
done

exit 0
[/bash]
上次由 chenjietao 在 2013-04-08 3:56,总共编辑 15 次。
头像
cuihao
帖子: 4793
注册时间: 2008-07-24 11:33
来自: 郑州
联系:

Re: 家用老机的装机脚本。

#2

帖子 cuihao » 2012-08-20 22:08

:em01 byousokugosenchimiitoru
继续使用桌面环境省事儿……
求人不如求它仨: 天蓝的Wiki 屎黄的Wiki 绿
Site: CUIHAO.TK    Twitter: @cuihaoleo
Machine: Athlon64 X2 5200+ / 2x2GB DDR2-800 / GeForce GTS 450
AD: ~まだ見ぬ誰かの笑顔のために~
头像
chenjietao
帖子: 130
注册时间: 2010-09-21 1:50

Re: 家用老机的装机脚本。

#4

帖子 chenjietao » 2012-08-21 1:32

http://www.deviantart.com/deviation/26279189/

Sent from my GT-S5830i using Tapatalk 2
头像
mickeywaley
帖子: 1427
注册时间: 2009-03-19 9:19
系统: ubuntu
来自: 江苏
联系:

Re: 家用老机的装机脚本 & 一些有用的脚本

#5

帖子 mickeywaley » 2012-10-12 21:55

不错 :em11
头像
adagio
论坛版主
帖子: 22110
注册时间: 2008-02-17 23:47
来自: 美丽富饶的那啥星球

Re: 家用老机的装机脚本 & 一些有用的脚本

#6

帖子 adagio » 2012-10-12 22:18

:em11
明天就换大三八!
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……

---------------------------------------------------------------------------------
[图片版]新手当自强(续)FAQ
[新手进阶]挂载、fstab、调整linux分区
[图片版]E17桌面环境配置手把手
endle
帖子: 184
注册时间: 2011-02-27 20:46
联系:

Re: 家用老机的装机脚本 & 一些有用的脚本

#7

帖子 endle » 2013-01-12 19:47

我只是围观LZ的壁纸来了
==我的博客==
一连串的意外把我推上了 fedora 的前卫的道路。
我用A卡,安装驱动无压力
---------公益广告---------
Freerice 背单词 送大米
Boinc 用电脑的闲置时间助力科学研究
回复