Skip to content

Commit

Permalink
today
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Dec 26, 2014
1 parent 2d90c60 commit 44a18ce
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 92 deletions.
4 changes: 4 additions & 0 deletions Compression.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- http://www.7-zip.org/ http://tukaani.org/xz/
- https://code.google.com/p/snappy/ https://github.com/kubo/snzip
- https://code.google.com/p/zopfli/
- http://www.quicklz.com/
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,24 @@ Tools related to building webservers.

### Fast and safe transit of scripts (or any data) via copy&paste

Pack:
##### Pack

```bash
cat <SCRIPT>|xz -9|base64 -w $((COLUMNS-1))
# alias: cat <SCRIPT>|transit
```

Unpack:
##### Unpack

```bash
cat <PACKED>|base64 -d|xz -d > <SCRIPT>
cat <PASTED-FILE>|base64 -d|xz -d > <SCRIPT>
# alias: cat <PASTED-FILE>|transit-receive
```

### Backup all GitHub repos

```bash
GH_USER="szepeviktor"
wget -qO- "https://api.github.com/users/${GH_USER}/repos?per_page=100"|grep '"clone_url"'|cut -d'"' -f4 > github.repos
cat github.repos|xargs -L 1 git clone
```
51 changes: 41 additions & 10 deletions router.md → Router.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
# ASUS-merlin firmware

user name and password: non-root, non-admin
WAN (PPPoE) user/pass
### user name and password

non-root, non-admin

### WAN

(PPPoE) user/pass

### WiFi

SSID/WPA2-PSK AES

check firmware
### Firmware

[check firmware version](https://www.mediafire.com/folder/bkfq2a6aebq68//Asuswrt-Merlin#yvgnw5wo8wrco)

### USB disk

enable scheduled disk scan

### LAN

router LAN IP 192.168.12.1
LAN IP range 129.168.12.129 - 129.168.12.190

### NTP

NTP servers 0.hu.pool.ntp.org

### SSH

SSH key

DDNS egry.no-ip.com
IPv6 tunnel SixXS
### DDNS

egry.no-ip.com

### IPv6 tunnel

SixXS

- Native/PPP
- DNS 2001:4860:4860::8888 2001:4860:4860::8844

Backup!
### Backup

```bash
#!/bin/sh

# opkg update
# opkg upgrade
opkg update
opkg upgrade

# backup items: settings, jffs, root files, USB drive

# backup: settings, jffs, root files, USB drive
USB_ROOT="/tmp/mnt/optware"

[ -d "${USB_ROOT}/backup/" ] || exit 1
Expand All @@ -41,6 +69,9 @@ tar cf root-bck.tar ../root/ || exit 1
echo -------------------------------

# USB drive backup
echo "listen: nc -l -p 123 | gzip -9 > /opt/router-bck/router.tar.gz"
read
tar cv "$USB_ROOT" | nc szerver4. 123 || exit 1
# listen: nc -l -p 123 | gzip -9 > /opt/router-bck/router.tar.gz
echo -------------------------------

```
29 changes: 29 additions & 0 deletions backup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Criteria

- compression (speed, efficiency)
- encryption
- speed
- integrity checking
- fault tolerance
- deduplication: file, block, rolling hash (sliding window), soft collision, multiple backup sources
- remote source, remote target
- source file modification detection (file content/file meta data) on incremental backups (disk throughput)
- backup file modification on incremental backups (create-only/modified old backup files)
- network traffic
- protocols (S3, swift, FTP)
- keep policy
- one filesystem at a time
- backup/no backup [tag files](http://www.brynosaurus.com/cachedir/spec.html)

### Options

- separate backups (etc, home, DB, mail, web)
- excludes (DB, cache, spool, tmp)
- logging
- monitoring: send email

### Softwares

- https://github.com/zbackup/zbackup
- https://github.com/jborg/attic
- http://obnam.org/
12 changes: 10 additions & 2 deletions debian-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ sed -e 's/\(#.*enable bash completion\)/#\1/' -e '/#.*enable bash completion/,+8
echo -e "\ncontent_disposition = on" >> /etc/wgetrc
update-alternatives --set pager /usr/bin/most
update-alternatives --set editor /usr/bin/mcedit
# ~/.config/mc/mc.ext
# ### Markdown ###
# # cp /etc/mc/mc.ext ~/.config/mc/mc.ext && apt-get install -y pandoc
# regex/\.md(own)?$
# View=pandoc -s -f markdown -t man %p | man -l -

# bash as default shell
echo "dash dash/sh boolean false"|debconf-set-selections -v
Expand All @@ -76,6 +81,9 @@ alias iotop='iotop -d 0.1 -qqq -o'
alias grep='grep $GREP_OPTIONS'
# putty / Connection / Data / Terminal-type string: putty-256color
export MC_SKIN="modarin256root-defbg"
alias transit='xz -9|base64 -w $((COLUMNS-1))'
alias transit-receive='base64 -d|xz -d'


# user
U="viktor"
Expand Down Expand Up @@ -305,9 +313,9 @@ sed -i 's|^date.timezone = .*$|date.timezone = ${PHP_TZ}|' /etc/php5/fpm/php.ini
grep -v "^#\|^;\|^$" /etc/php5/fpm/php.ini|most

# suhosin: https://github.com/stefanesser/suhosin/releases
# version 0.9.37
SUHOSIN_URL="<RELEASE-TAR-GZ>"
SUHOSIN_URL="https://github.com/stefanesser/suhosin/archive/suhosin-0.9.37.tar.gz"
# version 0.9.37.1
SUHOSIN_URL="https://github.com/stefanesser/suhosin/archive/0.9.37.1.tar.gz"
wget -qO- "$SUHOSIN_URL"|tar xz && cd suhosin-suhosin-*
phpize && ./configure && make && make test || echo "ERROR: suhosin build failed."
make install && cp -v suhosin.ini /etc/php5/fpm/conf.d/00-suhosin.ini && cd ..
Expand Down
39 changes: 25 additions & 14 deletions install-cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#
# Install cron jobs from the script header.
# E.g. "# CRON-HOURLY :/usr/local/bin/example.sh"
# In cron syntax "# CRON-D :09,39 * * * * root /usr/local/bin/example.sh"
# See: man 5 crontab
#
# VERSION :0.1
# DATE :2014-11-04
# VERSION :0.2
# DATE :2014-12-26
# AUTHOR :Viktor Szépe <viktor@szepe.net>
# LICENSE :The MIT License (MIT)
# URL :https://github.com/szepeviktor/debian-server-tools
Expand All @@ -24,7 +26,6 @@ Valid_cron_interval() {
for VALID in cron.daily cron.hourly cron.monthly cron.weekly; do
if [ "$QUESTION" == "$VALID" ]; then
return 0
return
fi
done

Expand All @@ -35,25 +36,35 @@ Valid_cron_interval() {

[ "$(id --user)" = 0 ] || Die 1 "Only root is allowed to install cron jobs."

[ -f "$1" ] || Die 2 "Please specify a script."

SCRIPT="$1"
[ -f "$SCRIPT" ] || Die 2 "Please specify a script."

CRON_JOBS="$(head -n 40 "$SCRIPT" | grep -i "^# CRON-")"
#TODO rewrite: loop through valid crons and `head -n 30 "$SCRIPT"|grep -i "^# ${CRON}")"|cut -d':' -f2 >> "$CRON_FILE"`
CRON_JOBS="$(head -n 30 "$SCRIPT" | grep -i "^# CRON-")"

[ -z "$CRON_JOBS" ] && Die 3 "No cron job in script."

declare -i JOB_ID="0"
declare -i JOB_ID_D="0"

while read -r JOB; do
INTERVAL="$(echo "$JOB" | cut -d' ' -f 2)"
INTERVAL="$(tr '[:upper:]' '[:lower:]' <<< "$INTERVAL")"
INTERVAL="${INTERVAL/-/.}"
CRON_INTERVAL="$(echo "$JOB" | cut -d' ' -f 2 | tr '[:upper:]' '[:lower:]')"
CRON_INTERVAL="${CRON_INTERVAL/-/.}"

if Valid_cron_interval "$INTERVAL"; then
CRON_FILE="/etc/${INTERVAL}/$(basename "$SCRIPT")"
echo -e ":#!/bin/bash\n${JOB}" | cut -d':' -f 2 > "$CRON_FILE"
if Valid_cron_interval "$CRON_INTERVAL"; then
CRON_FILE="/etc/${CRON_INTERVAL}/$(basename "${SCRIPT%.*}")$(( ++JOB_ID ))"
( echo "#!/bin/bash"; echo "${JOB}" | cut -d':' -f 2 ) >> "$CRON_FILE"
chmod 755 "$CRON_FILE"
echo "${SCRIPT} -> ${CRON_FILE}"
echo "[cron] ${SCRIPT} -> ${CRON_FILE}"
elif [ "$CRON_INTERVAL" == cron.d ]; then
CRON_FILE="/etc/cron.d/$(basename "${SCRIPT%.*}")"
if [ $(( ++JOB_ID_D )) -eq 1 ]; then
# initialize cron.d file
echo -n > "$CRON_FILE"
fi
echo "${JOB}" | cut -d':' -f 2 >> "$CRON_FILE"
echo "[cron] ${SCRIPT} -> ${CRON_FILE}"
else
Die "Invalid cron interval in script header: (${INTERVAL})"
Die "Invalid cron interval in script header: (${CRON_INTERVAL})"
fi
done <<< "$CRON_JOBS"
88 changes: 48 additions & 40 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,22 @@ Die() {
}

#####################################################
# Parses out the version from a script
# Parses out a meta value from a script
# Arguments:
# FILE
# META
#####################################################
GetVersion() {
local FILE="$1"
local VER="$(head -n30 "$FILE" | grep -m1 "^# VERSION\s*:" | cut -d":" -f2-)"

if [ -z "$VER" ]; then
VER="(unknown)"
Get_meta() {
# defaults to self
local FILE="${1:-$0}"
# defaults to "VERSION"
local META="${2:-VERSION}"
local VALUE="$(head -n 30 "$FILE" | grep -m 1 "^# ${META}\s*:" | cut -d':' -f 2-)"

if [ -z "$VALUE" ]; then
VALUE="(unknown)"
fi
echo "$VER"
}

#####################################################
# Parses out LOCATION from a script
# Arguments:
# FILE
#####################################################
GetLocation() {
local FILE="$1"

head -n30 "$FILE" | grep -m1 "^# LOCATION\s*:" | cut -d":" -f2
echo "$VALUE"
}

#####################################################
Expand All @@ -51,7 +44,7 @@ GetLocation() {
# PERMS
# <file> <file> ...
#####################################################
DoInstall() {
Do_install() {
local LOCATION="$1"
local OWNER="$2"
local PERMS="$3"
Expand Down Expand Up @@ -79,13 +72,19 @@ DoInstall() {

# check for existence
if [ -f "$TARGET" ]; then
echo -n "replacing $(GetVersion "$TARGET") with $(GetVersion "$TOOL") "
echo -n "replacing $(Get_meta "$TARGET") with $(Get_meta "$TOOL") "
fi

# copy and set owner and permissions
#TODO install -v --no-target-directory --preserve-timestamps --owner="${OWNER%:*}" --group="${OWNER#*:}" --mode "${PERMS}" \
# "$TOOL" "$TARGET" || Die 11 "install failure (${TOOL})"
cp -v "$TOOL" "$TARGET" || Die 11 "copy failure (${TOOL})"
chown --changes ${OWNER} "$TARGET" || Die 12 "cannot set owner (${TOOL})"
chmod --changes ${PERMS} "$TARGET" || Die 13 "cannot set permissions (${TOOL})"

if head -n 30 "$TOOL" | grep -qi "^# CRON-"; then
./install-cron.sh "$TOOL"
fi
done
}

Expand All @@ -96,7 +95,7 @@ DoInstall() {
# OWNER
# PERMS
#####################################################
DoDir() {
Do_dir() {
local DIR="$1"
local OWNER="$2"
local PERMS="$3"
Expand All @@ -105,40 +104,49 @@ DoDir() {

find "$DIR" -maxdepth 1 -type f \
| while read FILE; do
LOCATION="$(GetLocation "$FILE")"
LOCATION="$(Get_meta "$FILE" LOCATION)"

if ! [ -z "$LOCATION" ]; then
# warn on different actual file name and file name in LOCATION
if ! [ "$(basename "$FILE")" = "$(basename "$LOCATION")" ]; then
echo "[WARNING] different file name in LOCATION comment ("$(basename "$FILE")" != "$(basename "$LOCATION")")"
fi
if [ -z "$LOCATION" ] || [ "$LOCATION" == "(unknown)" ]; then
continue
fi

DoInstall "$(dirname "$LOCATION")" "$OWNER" "$PERMS" "$FILE"
# warn on different actual file name and LOCATION meta
if [ "$(basename "$FILE")" != "$(basename "$LOCATION")" ]; then
echo "[WARNING] different file name in LOCATION header ($(basename "$FILE") != $(basename "$LOCATION"))" >&2
fi

Do_install "$(dirname "$LOCATION")" "$OWNER" "$PERMS" "$FILE"
done
}


#########################################################

[ "$(id --user)" = 0 ] || Die 1 "only root is allowed to install"
if [ "$(id --user)" -ne 0 ]; then
Die 1 "Only root is allowed to install"
fi

# version
if [ "$1" = "--version" ]; then
GetVersion "$0"
if [ "$1" == "--version" ]; then
Get_meta
exit 0
fi

echo "debian-server-tools installer"

DoDir ./backup root:staff 755
DoDir ./monitoring root:staff 755
DoDir ./package root:staff 755
DoDir ./webserver root:staff 755
DoDir ./webserver/nginx-incron root:staff 755
Do_dir ./backup root:staff 755
Do_dir ./image root:staff 755
Do_dir ./mail root:staff 755
Do_dir ./monitoring root:staff 755
Do_dir ./mysql root:staff 755
Do_dir ./package root:staff 755
Do_dir ./security root:staff 755
Do_dir ./tools root:staff 755
Do_dir ./webserver root:staff 755
Do_dir ./webserver/nginx-incron root:staff 755

# special cases
DoInstall /root/hdd-bench root:root 700 ./monitoring/hdd-seeker/hdd-bench.sh
DoInstall /root/hdd-bench root:root 644 ./monitoring/hdd-seeker/seeker_baryluk.c \
Do_install /root/hdd-bench root:root 700 ./monitoring/hdd-seeker/hdd-bench.sh
Do_install /root/hdd-bench root:root 644 \
./monitoring/hdd-seeker/seeker_baryluk.c \
./monitoring/hdd-seeker/seekmark-0.9.1.c

Loading

0 comments on commit 44a18ce

Please sign in to comment.