forked from w0rp/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
144 lines (119 loc) · 3.56 KB
/
functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash -eu
# Create properties easily for PekWM.
propstring () {
echo -n 'Property '
xprop WM_CLASS | sed 's/.*"\(.*\)", "\(.*\)".*/= "\1,\2" {/g'
echo '}'
}
# Back up an entire domain very quickly.
quick-warc() {
if [ -f "$1".warc.gz ]; then
echo "$1.warc.gz already exists"
else
wget --warc-file="$1" --warc-cdx --mirror --page-requisites \
--no-check-certificate --restrict-file-names=windows \
-e robots=off --waitretry 5 --timeout 60 --tries 5 --wait 1 \
-U "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27" \
"http://$1/"
fi
}
# Create a .7z file from a directory or file in the same directory with
# .7z as the suffix.
mk7z() {
if [ -z "$1" ]; then
echo 'Please supply a file' 1>&2
return 1;
fi
src="$(basename "$1")"
dst="$src".7z
if [ -f "$dst" ]; then
echo "$dst already exists" 1>&2
return 1;
fi
7z a "$dst" "$src"
}
# Backup one director to another with rsync.
backup() {
if [ -z "$1" ] || [ -z "$2" ]; then
echo 'Usage: backup <src> <dest>' 1>&2
return 1
fi
if [ ! -d "$1" ]; then
echo "Not a source directory: $1" 1>&2
return 1
fi
if [ ! -d "$2" ]; then
echo "Not a destination directory: $2" 1>&2
return 1
fi
if [ -n "$3" ]; then
echo 'You supplied a third argument. Something is probably wrong.' 1>&2
return 1
fi
rsync -auv --delete "$1/" "$2"
}
validate_transcoding_filenames() {
if [ -z "$1" ]; then
echo "Not input filename was given!"
return 1
fi
if ! [ -f "$1" ]; then
echo "Input file does not exist: $1" 1>&2
return 1
fi
if [ -z "$2" ]; then
echo "Not output filename was given!"
return 1
fi
if [ -d "$2" ]; then
echo "The output filename is a directory: $2"
return 1
fi
}
to_x264_1080p_aac_192k() {
validate_transcoding_filenames "$1" "$2" && \
ffmpeg -i "$1" \
-vcodec libx264 -profile:v high -preset slow \
-b:v 2000k -maxrate 2000k -bufsize 4000k -vf \
scale=-1:1080 -threads 0 \
-acodec aac -b:a 192k -strict -2 \
"$2"
}
to_x264_720p_aac_128k() {
validate_transcoding_filenames "$1" "$2" && \
ffmpeg -i "$1" \
-codec:v libx264 -profile:v high -preset slow \
-b:v 1000k -maxrate 1000k -bufsize 2000k -vf \
scale=-1:720 -threads 0 \
-codec:a aac -b:a 128k -strict -2 \
"$2"
}
to_wav() {
validate_transcoding_filenames "$1" "$2" && \
ffmpeg -i "$1" -acodec pcm_s16le -ar 44100 "$2"
}
adfs_xml_url() {
domain=$(echo "$1" | sed -e 's/^\([a-zA-Z0-9]\+:\/\/\|\)\([^\/]\+\).*/\2/')
echo "https://$domain/FederationMetadata/2007-06/FederationMetadata.xml"
}
download_adfs_xml() {
domain=$(echo "$1" | sed -e 's/^\([a-zA-Z0-9]\+:\/\/\|\)\([^\/]\+\).*/\2/')
url="https://$domain/FederationMetadata/2007-06/FederationMetadata.xml"
wget --no-check-certificate "$url" -O "${domain}-metadata.xml" || rm -f "${domain}-metadata.xml"
}
# A function for conveniently adding remotes for GitHub forks.
add-github-remote() {
git remote add "$1" "git@github.com:${1}$(git remote -v | grep -o '/[^/]\+\.git' | uniq)"
}
# A function for killing processes with confirmation.
killit() {
if pgrep -af "$1"; then
echo
read -p 'Kill these processes? (y/N): ' -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
pkill -f "$1"
fi
else
echo 'No processes found.'
fi
}