Skip to content

Commit

Permalink
revision/optimization of some scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cremesk committed Dec 1, 2024
1 parent 5a015c7 commit b67e3d1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
### This file managed by Salt, do not edit by hand! ###

get_ip() { curl --interface "$1" -sL ip.envs.net ; }
Expand Down
24 changes: 15 additions & 9 deletions salt/freifunk/base/ddmesh/usr/local/bin/freifunk-manuell_update.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#!/bin/sh
#!/usr/bin/env sh
### This file managed by Salt, do not edit by hand! ###
#
# Freifunk - Manuell Server Update
#

REV='T_RELEASE_latest'
REPO_URL='https://github.com/Freifunk-Dresden/ffdd-server'
REV='T_RELEASE_latest'
INSTALL_DIR='/srv/ffdd-server'

if [ "$(id -u)" -ne 0 ]; then printf 'Please run as root!\n'; exit 1 ; fi

CUSTOM_REPO_URL="$(uci -qX get ffdd.sys.freifunk_repo)"
[ -n "$CUSTOM_REPO_URL" ] && [ "$CUSTOM_REPO_URL" != "$REPO_URL" ] && REPO_URL="$CUSTOM_REPO_URL"

if [ -f /usr/local/sbin/uci ] && [ -f /etc/config/ffdd ]; then
CUSTOM_REPO_URL="$(uci -qX get ffdd.sys.freifunk_repo)"
[ -n "$CUSTOM_REPO_URL" ] && [ "$CUSTOM_REPO_URL" != "$REPO_URL" ] && REPO_URL="$CUSTOM_REPO_URL"
CUSTOM_REV="$(uci -qX get ffdd.sys.branch)"
[ -n "$CUSTOM_REV" ] && [ "$CUSTOM_REV" != "$REV" ] && REV="$CUSTOM_REV"

CUSTOM_REV="$(uci -qX get ffdd.sys.branch)"
[ -n "$CUSTOM_REV" ] && [ "$CUSTOM_REV" != "$REV" ] && REV="$CUSTOM_REV"
fi
CUSTOM_INSTALL_DIR="$(uci -qX get ffdd.sys.install_dir)"
[ -n "$CUSTOM_INSTALL_DIR" ] && [ "$CUSTOM_INSTALL_DIR" != "$INSTALL_DIR" ] && INSTALL_DIR="$CUSTOM_INSTALL_DIR"


if [ "$(id -u)" -ne 0 ]; then printf 'Please run as root!\n'; exit 1 ; fi

[ -d "$INSTALL_DIR" ] && rm -rf "$INSTALL_DIR"
git clone "$REPO_URL" "$INSTALL_DIR"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
### This file managed by Salt, do not edit by hand! ###
#
# Freifunk - Autosetup for /etc/config/ffdd
#
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

#
# Get variables from /etc/config/ffdd
ddmesh_node="$(uci -qX get ffdd.sys.ddmesh_node)"
ddmesh_key="$(uci -qX get ffdd.sys.ddmesh_registerkey)"

if [ -z "$ddmesh_key" ] || [ "$ddmesh_key" = '-' ]; then

# set ddmesh_registerkey
ddmesh_key="$(ip link | sha256sum | sed 's#\(..\)#\1:#g;s#[ :-]*$##')"
uci set ffdd.sys.ddmesh_registerkey="$ddmesh_key"
Expand All @@ -24,5 +20,4 @@ if [ -z "$ddmesh_key" ] || [ "$ddmesh_key" = '-' ]; then
uci commit
fi

#
exit 0
19 changes: 13 additions & 6 deletions salt/freifunk/base/ddmesh/usr/local/bin/freifunk-version
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
### This file managed by Salt, do not edit by hand! ###
#
# Freifunk - Server Version Info
#

install_dir="$(uci -qX get ffdd.sys.install_dir)"
version="$(head -n3 "$install_dir"/init_server.sh | grep -oP '(?<=^#version=).+' | tr -d '"')"
rev="$(git --git-dir="$install_dir"/.git describe --all --abbrev=0 | cut -f2 -d"/")"
commit="$(git --git-dir="$install_dir"/.git show --oneline -s | awk '{print $1}')"
INSTALL_DIR='/srv/ffdd-server'

if [ "$install_dir" != '' ]; then
CUSTOM_INSTALL_DIR="$(uci -qX get ffdd.sys.install_dir)"
[ -n "$CUSTOM_INSTALL_DIR" ] && [ "$CUSTOM_INSTALL_DIR" != "$INSTALL_DIR" ] && INSTALL_DIR="$CUSTOM_INSTALL_DIR"

if [ -d "$INSTALL_DIR" ]; then
version="$(head -n3 "$INSTALL_DIR"/init_server.sh | grep -oP '(?<=^#version=).+' | tr -d '"')"
rev="$(git --git-dir="$INSTALL_DIR"/.git describe --all --abbrev=0 | cut -f2 -d"/")"
commit="$(git --git-dir="$INSTALL_DIR"/.git show --oneline -s | awk '{print $1}')"
printf '%s - %s (%s)\n' "$version" "$rev" "$commit"
else
printf 'n.a.\n'
Expand Down

0 comments on commit b67e3d1

Please sign in to comment.