Skip to content

Instantly share code, notes, and snippets.

@mxyq
mxyq / detect_os.sh
Last active March 3, 2022 05:45
[Detect OS] #Bash
# Detect OS
# $os_version variables aren't always in use, but are kept here for convenience
if grep -qs "ubuntu" /etc/os-release; then
os="ubuntu"
os_version=$(grep 'VERSION_ID' /etc/os-release | cut -d '"' -f 2 | tr -d '.')
elif [[ -e /etc/debian_version ]]; then
os="debian"
os_version=$(grep -oE '[0-9]+' /etc/debian_version | head -1)
elif [[ -e /etc/almalinux-release || -e /etc/rocky-release || -e /etc/centos-release ]]; then
os="centos"
@mxyq
mxyq / change_passwd.sh
Last active August 24, 2022 22:08
[MySQL] #Bash #MySQL
config_mysqld() {
_info "Change MySQL Password ..."
db_pass=""
${mysql_location}/bin/mysqld --initialize-insecure --user=mysql >>/var/log/initialize.log 2>&1
${mysql_location}/bin/mysql_ssl_rsa_setup
/usr/local/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"${db_pass}\" with grant option;"
/usr/local/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"${db_pass}\" with grant option;"
/usr/local/bin/mysql -uroot -p${db_pass} -e "grant all privileges on *.* to root@'%' identified by \"${db_pass}\" with grant option;"
@mxyq
mxyq / printf.sh
Last active August 1, 2022 09:09
[Log] #Bash #Log
_printargs() {
printf -- "%s" "$1"
printf "\n"
}
_info() {
_printargs "$@"
}
@mxyq
mxyq / While; do case.sh
Last active August 1, 2022 09:05
[Getting options] #Bash
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-V | --version )
echo $version
exit
;;
-s | --string )
shift; string=$1
;;
-f | --flag )
flag=1
@mxyq
mxyq / press any key to continue
Last active August 2, 2022 03:37
[Read from type] #Bash
read -n1 -r -p "Press any key to continue..."
@mxyq
mxyq / docker_archivebox.sh
Last active August 1, 2022 10:02
[Docker startup scripts] #Docker
docker run --rm -v $PWD:/data -it archivebox/archivebox init --setup
docker run -it \
--name archive_box \
-p 48000:8000 \
-v /data/ArchiveBox:/data \
--restart always \
-e HTTP_PROXY=http://192.168.1.10:10811 \
-e HTTPS_PROXY=http://192.168.1.10:10811 \
-e TIMEOUT=120 \
@mxyq
mxyq / nginx.dockerfile
Last active July 1, 2024 02:00
[docker run] #Docker #Dockerfile
FROM nginx:stable-alpine
ENV TimeZone=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TimeZone /etc/localtime && echo $TimeZone > /etc/timezone && export TZ=$TimeZone
ADD default.conf /etc/nginx/conf.d/
COPY --chown=nginx:nginx dist /usr/share/nginx/html
CMD ["nginx","-g","daemon off;"]
@mxyq
mxyq / profile
Last active August 24, 2023 01:24
Go环境变量
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin:~/go/bin
export GO111MODULE=on
export GOPROXY=https://goproxy.io,direct
@mxyq
mxyq / tc.sh
Created December 29, 2022 02:30
[tc 命令]
tc -s qdisc show dev eth0
tc qdisc replace dev eth0 root rtt 220ms cake ethernet besteffort
tc qdisc replace dev eth0 root cake rtt 150ms ethernet diffserv4
@mxyq
mxyq / nftables.conf
Created January 15, 2023 02:40
[Linux Firewall Configuration]
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain ports {
tcp dport 33333 counter accept
}
chain input {