-
Notifications
You must be signed in to change notification settings - Fork 1
/
.profile
234 lines (201 loc) · 6 KB
/
.profile
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.
# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
### Aliases
alias la='ls -Flash --color=always'
### Functions
# ls with octal permissions (e.g. 755)
function lap { ls -Flah --color=always "$@" | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}'; }
# find things
function ggg { grep -rIlnws --exclude-dir={tmp,boot,dev,media,mnt,proc,run} $@ / ; }
# restart nginx
function rnx {
sudo nginx -t
sudo nginx -s reload
}
# enter docker conainter
function bin {
if [ $# -eq 0 ]; then
echo "You must supply an app name!"
return 1
fi
if [ $# -eq 2 ] && [ "$2" = "-s" ] || [ "$2" = "sudo" ]; then
sudo docker exec -it $1.web.1 /bin/bash;
else
docker exec -it $1.web.1 /bin/bash;
fi
}
# copy to docker container
# dcp -[<i/o>] [<source>] [<appname>] [<destination>]
function dcp {
if [ "$1" != "-i" ] && [ "$1" != "-o" ]; then
echo "$1"
echo "You must specify in (-i) or out (-o)!"
return 1
fi
if [ $# -lt 3 ]; then
echo "You must supply a [<source>], an [<appname>] and a [<destination>]!"
return 1
fi
case $1 in
"-i" )
docker cp $2 $3.web.1:$4
;;
"-o" )
docker cp $3.web.1:$2 $4
;;
esac
}
# download git repo, extract, set ownership/permissions, clean up.
# @example wgit [<user/repo>]
function wgit {
if [ $# -eq 0 ]; then
echo "You must supply a valid user & repo (i.e. user/repo)!"
return 1
fi
DIR=$(echo $1 | cut -d'/' -f2- ) && \
sudo rm -f master.zip && sudo rm -f "$DIR" \
sudo wget https://github.com/$1/archive/master.zip && \
sudo unzip -q master.zip && sudo rm -f master.zip && \
sudo mv -n "$DIR-master" "$DIR" && \
sudo chown -R 32767:32767 "$DIR" && \
sudo find "$DIR" -type d -exec chmod -- 755 {} \; && \
sudo find "$DIR" -type f -exec chmod -- 644 {} \; && \
echo "" && \
ls -Flahd "$DIR" | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}';
}
# extract, set ownership & permissions
function uzp {
file=$1
if [ $# -eq 0 ] || [ ${file##*.} -ne "zip" ]; then
echo "You must specify a .zip file!"
return 1
fi
DIR=$(echo $1 | sed 's/\(.*\)\..*/\1/')
sudo unzip -q $1 && sudo rm -f $1 && \
sudo chown -R 32767:32767 "$DIR" && \
sudo find "$DIR" -type d -exec chmod -- 755 {} \; && \
sudo find "$DIR" -type f -exec chmod -- 644 {} \; && \
echo "" && \
ls -Flahd "$DIR" | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/)*2^(8-i));if(k)printf(" %0o ",k);print}';
}
# fix permissions
function pfix {
sudo chown -R 32767:32767 . && \
sudo find . -type d -exec chmod -- 755 {} \; && \
sudo find . -type f -exec chmod -- 644 {} \;
}
# turn on/off sophos av
function av {
if [ $# -eq 0 ]; then
echo "You must specify off (-o) or on (-i)!"
return 1
fi
case $1 in
"-o" | "--off" | "off" )
sudo echo "turning OFF sophos av..."
echo "$ sudo /opt/sophos-av/bin/savdctl disable"
sudo /opt/sophos-av/bin/savdctl disable
echo "$ sudo systemctl stop sav-protect.service"
sudo systemctl stop sav-protect.service
echo "$ sudo systemctl stop sav-rms.service"
sudo systemctl stop sav-rms.service
;;
"-i" | "--on" | "on" )
sudo echo "turning ON sophos av..."
echo "$ sudo systemctl start sav-rms.service"
sudo systemctl start sav-rms.service
echo "$ sudo systemctl start sav-protect.service"
sudo systemctl start sav-protect.service
echo "$ sudo /opt/sophos-av/bin/savdctl enable"
sudo /opt/sophos-av/bin/savdctl enable
;;
esac
}
# clear up ram
function clr {
free -h
echo "Clearing PageCache, dentries and inodes."
echo 3 > sudo /proc/sys/vm/drop_caches
echo "Clearing Swapfile"
sudo swapoff -a && sudo swapon -a
printf '\n%s\n' 'Ram-cache and Swap Cleared'
free -h
}
# export or import database dump
function db {
if [ $# -eq 0 ]; then
echo "You must specify export (-e) or import (-i)!"
return 1
fi
case $1 in
"export" | "-e" )
if [ $# -eq 2 ]; then
# destination filename provided
dokku mariadb:export stdb-wp > ~/.sql/$2
else
local TIMESTAMP=$(date +"%Y%m%d%H%M%S")
dokku mariadb:export stdb-wp > ~/.sql/stdb-wp_$TIMESTAMP.sql
echo "~/.sql/stdb-wp_$TIMESTAMP.sql"
return 0
fi
;;
"import" | "-i" )
if [ $# -eq 1 ]; then
echo "You must specify .sql file to import!"
return 1
fi
dokku mariadb:import stdb-wp < $2
echo "$2 imported to stdb-wp"
return 0
;;
esac
}
###
# SYNC DEV <--> PROD
# (Only works on Vagrant)
###
# sync wp-content files down (-d) or up (-u) to/from a specified host ([<hostname or USER@]HOST>])
function sync {
if [ $# -eq 0 ]; then
echo "You must specify down (-d) or up (-u)!"
return 1
elif [ $# -eq 1 ]; then
echo "You must specify [<hostname or USER@]HOST>]"
return 1
fi
case $1 in
"down" | "-d" )
rsync -rltzvpa --super --delete --filter='dir-merge,-n /.gitignore' $2:/var/lib/dokku/data/storage/new/wp-content/ /var/lib/dokku/data/storage/new/wp-content/
rsync -rltzvpa --super --delete $2:~/.ssh/ ~/.ssh/
;;
"up" | "-u" )
rsync -rltzv --super --delete --filter='dir-merge,-n /.gitignore' --rsync-path="sudo rsync" --chmod=D0755,F0644 --perms --chown=32767:32767 --owner --group /var/lib/dokku/data/storage/new/wp-content/ $2:/var/lib/dokku/data/storage/new/wp-content/
rsync -rltzv --super --delete ~/.ssh/ $2:~/.ssh/
;;
esac
}
###
# iTerm Integeration
###
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"