Add shell snippets
This commit is contained in:
parent
d535478afe
commit
379d90d9b5
|
@ -0,0 +1,16 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:add-section
|
||||||
|
# key:adds
|
||||||
|
# --
|
||||||
|
#############################################################
|
||||||
|
# 1 - STEP NAME
|
||||||
|
#############################################################
|
||||||
|
${3:my_func}() {
|
||||||
|
local step_name='STEP ${1:1} ${2:STEP NAME}'
|
||||||
|
warn "Press enter to proceed with $step_name"; read
|
||||||
|
info "$step_name"
|
||||||
|
|
||||||
|
$0
|
||||||
|
|
||||||
|
info "done"
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:cat-heredoc
|
||||||
|
# key:cat
|
||||||
|
# --
|
||||||
|
cat <<EOF | tee ${1:file-name.conf}
|
||||||
|
$0
|
||||||
|
EOF
|
|
@ -0,0 +1,9 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:read
|
||||||
|
# key:read
|
||||||
|
# --
|
||||||
|
read -p "Enter ${1:name}: " ${2:input}
|
||||||
|
if [[ -z $$2 ]]; then
|
||||||
|
echo "Error: $1 cannot be empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -0,0 +1,9 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:root-check
|
||||||
|
# key:root
|
||||||
|
# --
|
||||||
|
user=$(whoami)
|
||||||
|
if [ $user == root ]; then
|
||||||
|
error "You should NOT be using a root account"
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -0,0 +1,72 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:script
|
||||||
|
# key:script
|
||||||
|
# --
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#############################################################
|
||||||
|
# Author: Taryel Hlontsi, 2025
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>
|
||||||
|
#############################################################
|
||||||
|
|
||||||
|
doc=$(cat <<'EOF'
|
||||||
|
NOTES:
|
||||||
|
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
#############################################################
|
||||||
|
# SETUP SECTION
|
||||||
|
#############################################################
|
||||||
|
set -e
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
#############################################################
|
||||||
|
# HELPER FUNCTIONS
|
||||||
|
#############################################################
|
||||||
|
info() {
|
||||||
|
GREEN='\033[1;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo -e "\${GREEN}\${1}\${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
trace() {
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo -e "\${YELLOW}\${1}\${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
PURPLE='\033[1;35m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo -e "\${PURPLE}\${1}\${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
RED='\033[1;31m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo -e "\${RED}\${1}\${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
$0
|
||||||
|
|
||||||
|
#############################################################
|
||||||
|
# RUN SECTION
|
||||||
|
#############################################################
|
||||||
|
echo $(date +'%Y-%m-%d %H:%M')
|
||||||
|
info "$doc"
|
||||||
|
|
||||||
|
info "Bye!"
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,8 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:sourced-check
|
||||||
|
# key:sourced
|
||||||
|
# --
|
||||||
|
if [ \$0 == $BASH_SOURCE ]; then
|
||||||
|
error "Do not run the script in a subshell via ./ Instead you should 'source' it!"
|
||||||
|
exit 1
|
||||||
|
fi
|
|
@ -0,0 +1,23 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:systemd
|
||||||
|
# key:systemd
|
||||||
|
# --
|
||||||
|
[Unit]
|
||||||
|
Description=Description goes here
|
||||||
|
Wants=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Environment="VAR_NAME=value"
|
||||||
|
EnvironmentFile=-/etc/environment
|
||||||
|
ExecStart=/usr/bin/bash /home/myuser/myscript.sh${1}
|
||||||
|
SyslogIdentifier=my.service
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5
|
||||||
|
# Should exist!
|
||||||
|
WorkingDirectory=/var/my.service${2}
|
||||||
|
TimeoutStopSec=30
|
||||||
|
Type=simple
|
||||||
|
User=root
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
|
@ -0,0 +1,5 @@
|
||||||
|
# -*- mode: Shell-script -*-
|
||||||
|
# name:wget
|
||||||
|
# key:wget
|
||||||
|
# --
|
||||||
|
wget --continue ${1:link} --output-document ${2:file}
|
Loading…
Reference in New Issue