Last active
March 19, 2023 17:22
-
-
Save adde88/c711343b2322e66cd0e308421ef9a8d9 to your computer and use it in GitHub Desktop.
My private OpenWRT (SDK) Build Helper Scripts, for easy building of packages on my Kali/Debian/Arch distros.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE# Version 2, December 2004 | |
# Copyright (C) 2023 Andreas Nilsen <adde88@gmail.com> | |
# | |
# Everyone is permitted to copy and distribute verbatim or modified | |
# copies of this license document, and changing it is allowed as long | |
# as the name is changed. | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
# | |
# 0. You just DO WHAT THE FUCK YOU WANT TO. | |
# | |
# This script will contain some personal / private material. Keep that in mind if you want to use them, you better tweak them | |
# | |
#-------------------------------------------------------- | |
# Setup vars. and functions to make usage of the OpenWRT buildroot alot easier to handle, as i keep alot of packages up to date | |
# This script will alow you to build a package with 1 command, and 2 arguments (1 arg is optional) | |
# Example: opkgmake aircrack-ng mk7 (opkgmake <package> <board (mk6/mk7)/snap> | |
# Example: opkgmakeall aircrack-ng (opkgmakeall <package> - (Will compile said package for both MK6, MK7, snapshot, and 15.05 | |
#-------------------------------------------------------- | |
# SETTINGS: | |
export SCRIPT_VERSION="1.2b" | |
export LAST_UPDATE="19.03.23" | |
# XXX: Allow to launch the build as root: | |
export FORCE_UNSAFE_CONFIGURE=1 | |
# XXX: This big function defines all of the variables needed for the setup process for this entire OpenWRT SDK script | |
function setup-openwrt-variables() { | |
source /etc/.openwrt_aliases | |
export CFLAGS=${OCFLAGS:=} | |
export LDFLAGS=${OLDFLAGS:=} | |
unset CFLAGS LDFLAGS | |
export ORIG_PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools:/usr/local/go/bin:/usr/lib/jvm/java-17-openjdk-amd64/bin:/usr/share/maven/bin:/usr/local/cuda/bin" | |
#---------------------------------------------------------------------------------------------------------------- | |
export OPENWRT='/etc/openwrt' | |
export GITS='/root/gits' | |
#---------------------------------------------------------------------------------------------------------------- | |
export ASUS='192.168.1.1:/root/ipks/' | |
export TETRA='192.168.1.6:/root/ipks/' | |
export NANO='172.16.42.1:/root/ipks/' | |
export MK7='192.168.1.8:/root/ipks/' | |
export MK6='192.168.1.6:/root/ipks/' | |
#---------------------------------------------------------------------------------------------------------------- | |
export STAGING_DIR1=$GITS'/openwrt-snapshot/staging_dir' | |
export STAGING_DIR2=$GITS'/openwrt-15.05/staging_dir' | |
export STAGING_DIR3=$GITS'/openwrt-19.07/staging_dir' | |
export STAGING_DIR4=$GITS'/openwrt-21.02/staging_dir' | |
export STAGING_DIR5=$GITS'/openwrt-22.03/staging_dir' | |
set-staging-dir | |
#---------------------------------------------------------------------------------------------------------------- | |
export XDIR1=$GITS'/openwrt-useful-tools-mk7' | |
export XDIR2=$GITS'/openwrt-useful-tools-mk6' | |
export XDIR3=$GITS'/openwrt-useful-tools-15.05' | |
export XDIR4=$GITS'/openwrt-useful-tools-21.02' | |
export XDIR5=$GITS'/openwrt-useful-tools-22.03' | |
export XDIR6=$GITS'/openwrt-useful-tools-snapshot' | |
#---------------------------------------------------------------------------------------------------------------- | |
export PWD1=$GITS'/openwrt-snapshot' | |
export PWD2=$GITS'/openwrt-19.07' | |
export PWD3=$GITS'/openwrt-15.05' | |
export PWD4=$GITS'/openwrt-21.02' | |
export PWD5=$GITS'/openwrt-22.03' | |
#---------------------------------------------------------------------------------------------------------------- | |
export MK7CONF=$OPENWRT'/mk7.config' | |
export MK6CONF=$OPENWRT'/mk6.config' | |
export MK6CCCONF=$OPENWRT'/mk6.cc.config' | |
export MKNANOCONF=$OPENWRT'/mknano.cc.config' | |
#---------------------------------------------------------------------------------------------------------------- | |
} | |
# XXX: Function: Get current CPU architecture from .config | |
function CURARCH() { grep CONFIG_ARCH "$(pwd)"/.config | awk -F'"' '{print $2}' ;} | |
# XXX: Function: Get info about current board from .config | |
function CURBOARD() { grep CONFIG_TARGET_BOARD "$(pwd)"/.config | awk -F'"' '{print $2}' ;} | |
# XXX: Function: Get the current branch from repo | |
function CURBRANCH() { eval git branch | grep '.*' | awk -F' ' '{printf "%s",$2} END {print ""}';} | |
# XXX: Function: Remove the recently built package, or the one defined by the 'find-opkg command' | |
function opkgrm() { rm -rf "$XFILE" ;} | |
#XXX: Set correct staging_dir directory, based on current openwrt dir | |
function set-staging-dir() { sdir="$(pwd)/staging_dir" ; export STAGING_DIR=$sdir; } | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Check current OpenWRT buildroot architecture (reade from '.config' file) and setup correct CFLAGS/LDFLAGS accordingly | |
function current-architecture() { | |
setup-openwrt-variables | |
check_gcc_version | |
current-board | |
if [[ $(CURARCH) = 'mipsel' ]]; then | |
export ARCH='mipsel' | |
if [[ ! $PATH == *"toolchain-mipsel_"* ]]; then | |
export PATH="${PATH}:${STAGING_DIR}/toolchain-mipsel_24kc_gcc-${CONFIG_GCC_VERSION}_musl/bin/" | |
#echo "$PATH" # XXX: UN-COMMENT FOR EASIER DEBUGGING | |
fi | |
if [[ ! ${CFLAGS:=} == *"-mfix-24k"* ]]; then | |
export CFLAGS=${CFLAGS:=}' -O3 -pipe -mno-branch-likely -mips32r2 -mtune=24kec -mdsp -mfix-24k' | |
#echo CFLAGS="${CFLAGS:=}" # XXX: UN-COMMENT FOR EASIER DEBUGGING | |
fi | |
if [[ ! ${LDFLAGS:=} == *"target-mipsel_24kc_musl/usr/lib"* ]]; then | |
export LDFLAGS=${LDFLAGS:=}' -L'$STAGING_DIR'/target-mipsel_24kc_musl/usr/lib' | |
#echo "${LDFLAGS:=}" # XXX: UN-COMMENT FOR EASIER DEBUGGING | |
fi | |
elif [[ $(CURARCH) = 'mips' ]]; then | |
export ARCH='mips' | |
if [[ ! $PATH == *"toolchain-mips_"* ]]; then | |
export PATH="${PATH}:${STAGING_DIR}/toolchain-mips_24kc_gcc-${CONFIG_GCC_VERSION}_musl/bin/" | |
#echo "$PATH" # XXX: UN-COMMENT FOR EASIER DEBUGGING | |
fi | |
if [[ ! ${CFLAGS:=} == *"-mdspr2"* ]]; then | |
export CFLAGS=${CFLAGS:=}' -O3 -pipe -mno-branch-likely -mips32r2 -mtune=24kc -mdspr2' | |
#echo CFLAGS="${CFLAGS:=}" # XXX: UN-COMMENT FOR EASIER DEBUGGING: + IDEA: actual CFLAGS pulled live each time from current config file as with other funcs phaps? | |
fi | |
if [[ ! ${LDFLAGS:=} == *"target-mips_24kc_musl/usr/lib"* ]]; then | |
export LDFLAGS=${LDFLAGS:=}' -L'$STAGING_DIR'/target-mips_24kc_musl/usr/lib' | |
#echo "${LDFLAGS:=}" # XXX: UN-COMMENT FOR EASIER DEBUGGING | |
fi | |
else | |
ARCH=$(CURARCH) | |
export ARCH | |
fi | |
if [[ ! ${CFLAGS:=} == *"target-${ARCH}_24kc_musl/usr/include"* ]]; then | |
export CFLAGS=${CFLAGS:=}' -I'$STAGING_DIR'/target-'$ARCH'_24kc_musl/usr/include' | |
fi | |
if [[ -z ${BOARD:=unknown} ]]; then | |
export BOARD="unknown" | |
fi | |
echo -e "\n[STATUS]: Finished setting up and tweaking the OpenWRT toolkit for the environment. Added PATH, and optimized 'CFLAGS' / 'LDFLAGS' variables for the: Pineapple" "$BOARD" | |
[[ ${CONFIG_GCC_VERSION:=} != "" ]] && echo -e '[INFO] : Toolkit GCC version was successfully detected as: v'"$CONFIG_GCC_VERSION" | |
[[ ${CFLAGS:=} != "" ]] && echo -e "[CFLAGS] :${CFLAGS:=}" | |
[[ ${LDFLAGS:=} != "" ]] && echo -e "[LDFLAGS]:${LDFLAGS:=}\n" | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Read the currently defined OpenWRT's board from the .config file | |
function current-board() { | |
if [[ $(CURBOARD) = 'ar71xx' ]]; then | |
export BOARD='MK6' | |
elif [[ $(CURBOARD) = 'ramips' ]]; then | |
export BOARD='MK7' | |
else | |
BOARD=$(CURBOARD) | |
export BOARD | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Return the current OpenWRT version | |
function current-sdk-version() { | |
if [[ $(CURBRANCH) = 'master' ]]; then | |
export CURVER='snapshot' | |
elif [[ $(CURBRANCH) = 'openwrt-22.03' ]]; then | |
export CURVER='openwrt-22.03' | |
elif [[ $(CURBRANCH) = 'openwrt-21.02' ]]; then | |
export CURVER='openwrt-21.02' | |
elif [[ $(CURBRANCH) = 'openwrt-19.07' ]]; then | |
export CURVER='openwrt-19.07' | |
elif [[ $(CURBRANCH) = 'chaos_calmer' ]]; then | |
export CURVER='openwrt-15.05' | |
else | |
CURVER=$(CURBRANCH) | |
export CURVER | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function to set the current .config's GCC toolchain version as a variable | |
function check_gcc_version() { | |
local conf='./.config' | |
if [[ ! -f $conf ]]; then | |
echo -e '[ERROR]: Wrong directory?' | |
echo -e "OpenWRT's '.config' file was not located." | |
echo -e "Please check your current directory, settings, and check if OpenWRT's '.config' file has been created" | |
return 1 | |
fi | |
gcc_version=$(grep "CONFIG_GCC_VERSION" ./.config) | |
eval "$gcc_version" | |
} | |
#---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Locate OpenWRT .IPK package files, and export the filepath as a variable | |
function find-opkg() { | |
local XPKG=$1 | |
local XARCH=_"$2"_ | |
XFILE=$(find "$(pwd)"/bin -name "$XPKG*.ipk" | grep "$XARCH") | |
export XFILE | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Main-message | |
function mainmsg() { | |
echo -e '' | |
echo -e '-----------------------------------------------------------------------------------------' | |
echo -e "| OpenWRT Build Toolkit v${SCRIPT_VERSION:=unknown} - Author: Andreas Nilsen - <adde88@gmail.com> / @adde88" | |
echo -e "| Last Updated: ${LAST_UPDATE:=unknown}" | |
echo -e '|----------------------------------------------------------------------------------------' | |
echo -e "| BOARD: Hak5 WiFi Pineapple $BOARD" | |
echo -e "| CPU ARCHITECTURE: $ARCH" | |
echo -e "| OpenWRT: ${CURVER:=unknown}" | |
echo -e "| PACKAGE: ${OPKG:=unknown}" | |
if [[ ! ${MKALL:=0} ]]; then | |
echo -e '|' | |
echo -e "| This will build packages for WiFI Pineapple: MK6, MK7, but also Snapshot-builds." | |
echo -e '| ' | |
fi | |
echo -e '-----------------------------------------------------------------------------------------' | |
echo -e '' | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Some checks to complete during startup | |
function startup-check() { | |
if [[ -z ${OPKG:=} ]]; then | |
echo -e '[ERROR]: No arguments provided!\nPlease provide atleast a package to build/compile.' | |
return 2 | |
fi | |
set-staging-dir | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Copy default board .config to build dir. | |
function copy-board-config() { | |
if [[ $BOARD = *[mMkK]7* ]]; then | |
#cp $MK7CONF .config | |
export XDIR=$XDIR1 | |
elif [[ $BOARD = *[mMkK]6* ]]; then | |
#cp $MK6CONF .config | |
export XDIR=$XDIR2 | |
elif [[ $BOARD = *[cC][cC]* ]]; then | |
#cp $MK6CCCONF .config | |
export XDIR=$XDIR3 | |
elif [[ $BOARD = *[sSnNaApP]* ]]; then | |
#cp $MK7CONF .config | |
export XDIR=$XDIR6 | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Transfer/SCP the IPK/Package to the CORRECT device, based on default (auto-detect) or by manual override. | |
function transfer-opkg() { | |
if [[ $BOARD = 'MK6' || $BOARD = 'MK7' ]]; then | |
scp -rpC "$XFILE" "$BOARD" | |
echo -e "[TRANSFER]: The toolkit should now have properly transferred the above IPK's to the selected device and directory:" | |
echo -e "'$BOARD:/root/ipks/'" | |
else | |
echo -e "[ERROR]: Unknown device, or unknown board to transfer the built IPK's to!" | |
return 1 | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: restore old settings | |
function restore-settings() { | |
unset CFLAGS LDFLAGS | |
unset MKALL WRTDBG ac_cv_env_CFLAGS_value SCRIPT_VERSION LAST_UPDATE | |
#export PATH=$ORIG_PATH | |
export LDFLAGS=${OLDFLAGS:-} | |
export CFLAGS=${OCFLAGS:-} | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: This will test if you currently are within a OpenWRT SDK dir. | |
function testdir() { | |
local testf='./scripts/feeds' | |
if [[ -f $testf ]]; then | |
return 0 | |
else | |
echo -e "[ERROR]: Not within a OpenWRT build directory!" | |
return 1 | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: This function will update the local 'custom' repo | |
function opkgupdate() { | |
testdir | |
local retVal=$? | |
if [[ $retVal -eq 1 ]]; then | |
echo -e "\n[ERRROR]: This will ONLY work within a OpenWRT build directory/environment!" | |
return 1 | |
else | |
./scripts/feeds update custom | |
echo -e "\n[SUCCESS]: Successfully updated the local 'custom' repository!" | |
return 0 | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: This generates both MK6 & MK7 packages | |
function opkgmakeall() { | |
export MKALL=1 | |
local PKG=$1 | |
opkgmake "$PKG" MK7 | |
opkgmake "$PKG" MK6 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Work that package! | |
function opkgmaker() { | |
if [ "${WRTDBG:=0}" == "1" ]; then | |
time make package/"$OPKG"/{download,prepare,compile} package/index V=sc VERBOSE=1 -j $(($(nproc) + 1)) JOBS=$(($(nproc) + 1)) 2>&1 | tee "$(pwd)"/custom-logs/complete-openwrt-build.log | grep -i -E "^make.*(error|[1-9]...Entering directory)" | |
else | |
time make package/"$OPKG"/{download,prepare,compile} package/index V=sc VERBOSE=1 -j $(($(nproc) + 1)) JOBS=$(($(nproc) + 1)) 2>&1 | tee "$(pwd)"/custom-logs/complete-openwrt-build.log | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: In dev.: mass package function: WORKING? | |
function opkgmake-all() { | |
testdir | |
if [ "${WRTDBG:=0}" == "1" ]; then | |
time make V=sc VERBOSE=1 -j $(($(nproc) + 1)) JOBS=$(($(nproc) + 1)) 2>&1 | tee "$(pwd)"/custom-logs/complete-openwrt-build.log | grep -i -E "^make.*(error|[1-9]...Entering directory)" | |
else | |
time make V=sc VERBOSE=1 -j $(($(nproc) + 1)) JOBS=$(($(nproc) + 1)) 2>&1 | tee "$(pwd)"/custom-logs/complete-openwrt-build.log | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Debug function. Analyzes the last log for errors and such | |
function opkgdbg() { | |
DBGF="$(pwd)/custom-logs/complete-openwrt-build.log" | |
if [[ ! -f $DBGF ]]; then | |
echo -e "[ERROR]: Unable to locate build-log to analyze within the 'custom-logs' folder." | |
echo -e "Check if file exists: '${DBGF}'" | |
elif [[ -f $DBGF ]]; then | |
grep -i -E "^make.*(error|[1-9]...Entering directory)" "$DBGF" | |
else | |
echo -e "[ERROR]: Unknown Error..WTF??? DERP!" | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Installs all the correct packages from custom repo, while avoiding collisions with the default repos. (Prio custom > default) | |
function install_all_pkgs(){ | |
testdir | |
echo -e "\n[STATUS]: Installing every package from the 'custom' repo, while at the same time avoiding package-collisions with other repos." | |
echo -e "[UPDATING]: All repositories...\n" | |
./scripts/feeds update -a | |
echo -e "\n[INSTALLING]: All packages, from all repositories.\n" | |
./scripts/feeds install -a | |
echo -e "\n[UN-INSTALLING]: Every package with the same names as all the packages within the 'custom' repository.\n" | |
./scripts/feeds uninstall "$(ls /root/custom)" | |
echo -e "\n[INSTALLING 'CUSTOM' REPO]: All packages, only from the 'custom' repository.\n" | |
./scripts/feeds install -a -p custom | |
echo -e "\n[STATUS]: Finished 'installing' every package flagged for installation within the 'custom' repo. into OpenWRT's build environment" | |
echo -e "You can find them within the 'Custom Repo' sub-menu within 'make menuconfig'." | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# ---- MAIN 'OPKGMAKE' FUNCTION BELOW ---- | |
# Build packages using OpenWRT (15.05 -> Snapshot) | |
# It should now properly auto-detect arch, board, version, branch. More functions, as well as even more in active development. | |
function opkgmake() { | |
export OPKG=$1 | |
export BOARD=${2:=} | |
startup-check | |
current-architecture | |
install_all_pkgs | |
opkgupdate | |
current-sdk-version | |
copy-board-config | |
echo -e "[STATUS]: Using the default OpenWRT build '.config' for: $BOARD" | |
echo -e "[STATUS]: Searching for earlier build packages, and deleting them. Displaying if you want to compare against the final build package." | |
find-opkg "$OPKG" "$ARCH" | |
opkgrm "$OPKG" | |
####------------------------------------------------------------------------#### | |
#### ---- MAIN PROCESS BELOW HERE ---- | |
mainmsg | |
sleep 1 | |
opkgmaker | |
find-opkg "$OPKG" "$ARCH" | |
if [[ ! -f $XFILE ]]; then | |
echo -e "\n[ERROR]: Compilation did NOT succeed!!" | |
echo -e "Try reading the above output CAREFULLY! Or try going deeper in depths within the 'custom-logs' folder." | |
echo -e "If you're still unable to find any traces/errors of the issue, try running 'opkgdbg' to crawl through the logs for errors, to output them." | |
restore-settings | |
return 1 | |
fi | |
mainmsg | |
cp "$XFILE" "$XDIR" | |
transfer-opkg | |
restore-settings | |
echo -e "[STATUS:] Finished building and transferring the package to the correct folder and device." | |
return 0 | |
} | |
# ---- END OF MAIN BUILD PROCESS! ---- | |
# ---------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE# Version 2, December 2004 | |
# Copyright (C) 2023 Andreas Nilsen <adde88@gmail.com> | |
# | |
# Everyone is permitted to copy and distribute verbatim or modified | |
# copies of this license document, and changing it is allowed as long | |
# as the name is changed. | |
# | |
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
# | |
# 0. You just DO WHAT THE FUCK YOU WANT TO. | |
# | |
# This script will contain some personal / private material. Keep that in mind if you want to use them, you better tweak them | |
# | |
# | |
# Source OpenWRT build helper scripts | |
[ -f /etc/.openwrt_aliases ] && . /etc/.openwrt_aliases | |
[ -f /etc/.openwrt_aliases ] && . /etc/.openwrt_aliases | |
# | |
# Some info for build scripts | |
export EMAIL="adde88@gmail.com" | |
export DEBFULLNAME="FSOCIETY" | |
export LANG=nb_NO.UTF-8 | |
export GITS='/root/gits' | |
# Compilation flags | |
export ARCHFLAGS="-arch x86_64" | |
export CFLAGS="-mtune=znver2 -O3" | |
export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |
# Plex Token and Debug command for UMS | |
export PLEX_TOKEN='pWhyzJxqSwqVgqK83tLK' | |
export PATH_NO_CONDA='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools:/usr/local/go/bin:/usr/lib/jvm/java-17-openjdk-amd64/bin:/usr/share/maven/bin:/usr/local/cuda/bin:/usr/local/go/bin:/usr/lib/jvm/java-17-openjdk-amd64/bin:/usr/local/cuda/bin' | |
# | |
# | |
alias umsdbg='journalctl -feu ums.service' | |
alias kismetdbg='journalctl -feu kismet.service' | |
# | |
alias activate='source ~/.zshrc' | |
# | |
function deactivate(){ | |
conda deactivate | |
export PATH=$PATH_NO_CONDA | |
unset CONDA_EXE _CE_M _CE_CONDA CONDA_PYTHON_EXE CONDA_SHLVL | |
return 0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: Return different return values depending on what folder you're in | |
function check_dir() { | |
[[ $PWD/ = $PWD1/ ]] && return 1 || return 0 | |
[[ $PWD/ = $PWD2/ ]] && return 2 || return 0 | |
[[ $PWD/ = $PWD3/ ]] && return 3 || return 0 | |
[[ $PWD/ = $PWD4/ ]] && return 4 || return 0 | |
[[ $PWD/ = $PWD5/ ]] && return 5 || return 0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# function to set custom parameters in UMS.conf | |
set_ums_var() { | |
console_output INFO "Setting UMS setting '${1}' to '${2}'" | |
sed -i "s+^${1} =$+${1} = ${2}+g" /etc/UMS.conf | |
} | |
# Fix users SSH keys permissions | |
function sshkeyfix() { | |
PS3='Would you like you create a new key-pair? ' | |
if [ -d ~/.ssh ]; then | |
chmod u=rw,go= ~/.ssh/id_* # chmod key with private settings | |
chmod a=r,u+w ~/.ssh/id_*.pub # chmod key with public settings | |
chmod u=rwx,go= ~/.ssh # chmod ~/.ssh directory with correct settings | |
[ -d ~/.ssh ] && echo '[SUCCESS]: Correctly set permissions for this users SSH keys and directory!' | |
return 0 | |
fi | |
echo'[ERROR]: Cannot locate SSH keys directory for this user!' | |
return 1 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Let's try to fix some shit. Unset and set some important variables needed to run properly: | |
export CURL_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt" | |
# | |
alias reboot='reboot -f --reboot' | |
alias wes='wes --color' | |
alias code='/usr/share/code/code --user-data-dir=/home/andreas/ --no-sandbox &' | |
alias stat='stat -c %a' | |
alias backup-custom='tar -zcvf - /root/custom | ssh root@192.168.1.7 "cat > /root/custom.tar.gz"' | |
alias backup-openwrt='tar -zcvf - /root/gits/openwrt-22.03 | ssh root@192.168.1.7 "cat > /root/openwrt-22.03-complete.tar.gz"' | |
alias dl='curl -L -J -O' | |
alias c='git clone --recursive' | |
alias gs='git status' | |
alias gp='git push' | |
alias ga='git add' | |
alias workoff='deactivate' | |
alias gdiff='git diff' | |
alias fetch='git fetch' | |
alias clone='git clone --recursive' | |
alias amend='git commit --amend' | |
#alias ll='ls -lh -L' | |
#alias la='ls -A -L' | |
alias show='git show' | |
alias psa='ps aux' | |
alias s='screen' | |
alias stash='git stash' | |
alias log='git log' | |
alias urd-encode='java -jar /root/gits/USB-Rubber-Ducky/Encoder/encoder.jar' | |
alias nstatp='netstat -tulpn' | |
alias untar='tar xvf' | |
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"' | |
alias url-quote='autoload -U url-quote-magic ; zle -N self-insert url-quote-magic' | |
alias whence='type -a' | |
alias wpi='strings -e l' | |
alias xnetmasq='terminal netmasq' | |
alias xnetstat='terminal netstat' | |
alias xo='xdg-open' | |
alias ...='cd ../../' | |
alias ....='cd ../../../' | |
alias .....='cd ../../../../' | |
alias ......='cd ../../../../../' | |
alias .......='cd ../../../../../../' | |
alias ........='cd ../../../../../../../' | |
alias .........='cd ../../../../../../../../' | |
alias ..........='cd ../../../../../../../../../' | |
alias ...........='cd ../../../../../../../../../../' | |
alias ............='cd ../../../../../../../../../../../' | |
alias .............='cd ../../../../../../../../../../../../' | |
alias zshaliases='nano /etc/.zsh_aliases' | |
alias zshconfig='nano /etc/.zshrc' | |
alias yt2mp3='youtube-dl --extract-audio --audio-format mp3' | |
alias gc='git commit -s -m "Default message: Simple new commit, with few changes"' | |
alias merge='git merge' | |
alias wow='git status' | |
alias 'open'='gnome-open' | |
alias whats-my-ip='dig +short myip.opendns.com @resolver1.opendns.com' | |
alias tmux='tmux -2' | |
alias apkstudio='apkstudio > /tmp/' | |
alias cs="php-cs-fixer fix" | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Function: In dev: Replaces string in file using sed. uses total of 3 args. | |
function replace-str() { | |
## [[ -z $1 ]] || [[ -z $2 ]] || [[ -z $3 ]] && echo -e '[ERROR]: Replacing string failed! Missing argument!' ; return 0 sed -i s/$1/$2/g $3 filename=$1 -- Delete OLD | |
filename=$1 | |
read -r "search?Enter search string: " | |
read -r "replace?Enter replacement string: " | |
if [[ -f $filename ]]; then | |
if [[ $search != "" && $replace != "" ]]; then | |
sed -i "s/${search}/${replace}/" "$filename" | |
return 0 | |
else | |
echo -e "[ERROR]: Un-defined variable(s)!" | |
echo -e "Did you perhaps not properly try to provide both the 'search' and 'replacement' strings?" | |
return 1 | |
fi | |
else | |
echo -e "[ERROR]: No filename specified!" | |
return 2 | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Fix apt key storage: Stores the GPG keys in /etc/apt/trusted.gpg.d/ | |
apt-fix-key(){ | |
local keyurl=$1 | |
local trustedkey=$2 | |
if [[ -z "$2" ]]; then | |
echo -e "[ERROR]: Missing second argument. (trustedkey)" | |
echo -e " This name will prefix the keyfile, and store it in this folder as such: '/etc/apt/trusted.gpg.d/filename.gpg'" | |
echo -e " Example: apt-fix-key https://url.com/folder/keyfile.gpg superkey - (This will save the key as superkey.gpg in the folder mentioned above)" | |
return 1 | |
elif [[ -z "$1" ]]; then | |
echo -e "[ERROR]: Missing first argument. (keyurl)" | |
echo -e " Example: apt-fix-key https://url.com/folder/keyfile.gpg superkey - (This will save the key as superkey.gpg in the folder mentioned above)" | |
return 2 | |
fi | |
curl -fsSL "${keyurl}" | gpg --dearmor -o /etc/apt/trusted.gpg.d/"${trustedkey}".gpg &>/dev/null | |
echo -e "[SUCCESS]: Downloaded and dearmored the GPG key belonging to: ${trustedkey} into APT's new and secure trusted GPG key system." | |
echo -e " Key-file: '/etc/apt/trusted.gpg.d/${trustedkey}.gpg'" | |
return 0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Generate 10 random alphanumeric characters | |
function rand10gen(){ < /dev/urandom tr -dc '[:alnum:]' | fold -w "${1:-10}" | head -n 1 ;} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Copy, with progress meter! | |
# Usage: xcp [source] [destination] | |
function xcp(){ | |
local source="$1" | |
local destination="$2" | |
local rand=rand10gen | |
if [[ $# -eq 0 ]]; then | |
echo -e '[ERROR]: No arguments provided' | |
echo -e ' Usage: xcp [source] [destination]' | |
return 1 | |
fi | |
time rsync -rah --info=progress2 --stats "$source" "$destination" 2>&1 | tee /tmp/copylog-"$rand".log | |
echo -e "[SUCCESS]: Copy Finished!\nLog-file can be found here: '/tmp/copylog-$rand.log" | |
return 0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Let's fix APT-KEY-ADD which is now deprecated | |
function apt-key-add2(){ | |
local fingerprint="$1" | |
local keyserver="$2" | |
if [[ $# -eq 0 ]]; then | |
echo -e '[ERROR]: No arguments provided' | |
echo -e ' Usage: apt-key-add2 [key-fingerprint] [optional-keyserver]' | |
return 1 | |
fi | |
if [[ -z $keyserver ]]; then | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys "$fingerprint" | |
echo -e '\n[SUCCESS]: Read above output to check if the GPG key was successfully fetched from keyserver: keyserver.ubuntu.com\n' | |
return 0 | |
fi | |
sudo apt-key adv --keyserver "$keyserver" --recv-keys "$fingerprint" | |
echo -e "\n[SUCCESS]: Still. Read above output to check if the GPG key was successfully fetched from keyserver: $keyserver\n" | |
return 0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Another attempt at fixing apt-key | |
function apt-key-add3(){ | |
local fkey="$1" | |
local fname="$2" | |
if [[ -f "/etc/apt/trusted.gpg.d/${fname}.gpg" ]]; then | |
echo -e '\n[ERROR:] Certificate Already Exists!' | |
eeturn 1 | |
fi | |
curl -sS "$fkey" | gpg --dearmor | tee /etc/apt/trusted.gpg.d/"$fname".gpg | |
if [ -f "/etc/apt/trusted.gpg.d/${fname}.gpg" ]; then | |
echo -e '\n[SUCCESS:] Certificate Exported Correctly!' | |
return 0 | |
else | |
echo -e '\n[ERROR:] Could not export certificate!' | |
return 2 | |
fi | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# This will launch a netcat listener within a custom screen session on a custom TCP port | |
function nc_listen() { | |
local session_id="$1" | |
local listen_port="$2" | |
if [[ "$*" == "" ]]; then | |
echo -e "No arguments provided" | |
echo -e "Usage: 'nc_listen [session_id] [tcp_listen_port]'" | |
return 1 | |
fi | |
screen -dmS "${session_id}" bash -c "while true; do nc -lp ${listen_port}; done" | |
echo -e "Sucessfully launched a 'netcat_listener' session!\nScreen-id: '${session_id}' is now active listening on TCP port: '$listen_port'" | |
screen -list | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Binwalk alias | |
alias binwalk='/usr/bin/binwalk --run-as=root' | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Convert UART/serial firmware dump from custom terminal output-log file to it's original complete firmware binary. Byte for Byte. | |
function fwdump_tobin() { | |
local FILE=$1 | |
local OFILE=$2 | |
if [[ "$*" == "" ]]; then | |
echo -e 'No arguments provided' | |
echo -e "Usage: 'fwdump_tobin [input_file] [output_file]'" | |
return 1 | |
fi | |
< "$FILE" awk -F":" '{print $2}' | cut -b -48 | tr -d " \t\n\r" | xxd -r -p - > "$OFILE" | |
chmod +x "$OFILE" | |
echo -e "\n Finished converting RAW binary dumped firmware from serial logfile, equal to its original content on NAND in the output file." | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Clone with GIT creds using SSH | |
function sshgit() { git clone --recursive git@github.com:"$1"/"$2" ;} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# hostapd taxonomy function | |
taxonomize() { | |
sig="$1" | |
mac="$2" | |
python -c "import taxonomy; print ';'.join(taxonomy.identify_wifi_device('$sig', '$mac'))" | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# Remove SSH key for host $1 | |
ssh-removehost () { | |
host=$1 | |
ssh-keygen -f ~/.ssh/known_hosts -R "$host" | |
return 0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# QEMU VM launcher, need kernel and drive (file) | |
function firmadyne-test () { | |
local _kernel=$1 | |
local _drive=$2 | |
if [[ "$*" == "" ]]; then | |
echo -e "No arguments provided" | |
echo -e "Usage: 'firmadyne-test [kernel] [fw_image]'" | |
return 1 | |
fi | |
qemu-system-mips \ | |
-m 256 \ | |
-M malta \ | |
-kernel "${_kernel}" \ | |
-drive file="${_drive}" \ | |
-append "firmadyne.syscall=0 root=/dev/sda1 console=ttyS0 nandsim.parts=64,64,64,64,64,64,64,64,64,64 rdinit=/firmadyne/preInit.sh rw debug ignore_loglevel print-fatal-signals=1" \ | |
-nographic -serial mon:stdio -monitor telnet::45454,server,nowait | |
} | |
alias cp_x='rsync -aP' | |
# ---------------------------------------------------------------------------------------------------------------- | |
# XXX: Copy func... | |
cp_z() | |
{ | |
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \ | |
| awk '{ | |
count += $NF | |
if (count % 10 == 0) { | |
percent = count / total_size * 100 | |
printf "%3d%% [", percent | |
for (i=0;i<=percent;i++) | |
printf "=" | |
printf ">" | |
for (i=percent;i<100;i++) | |
printf " " | |
printf "]\r" | |
} | |
} | |
END { print "" }' total_size="$(stat -c '%s' "${1}")" count=0 | |
} | |
# ---------------------------------------------------------------------------------------------------------------- | |
# DKMS Builder function | |
function dkms_b() { | |
local PDIR="$1" | |
local MODNAME="$2" | |
if [ -d "/usr/src" ]; then | |
cd /usr/src || echo -e "[ERROR]: Unable to locate '/usr/src/' directory !\nABORTING !" ; return 1 | |
fi | |
if [ -f "./dkms.conf" ]; then | |
VER=$(sed -n 's/\PACKAGE_VERSION="\(.*\)"/\1/p' dkms.conf) | |
else | |
echo -e "[ERROR]: Unable to locate 'dkms.conf' !\nABORTING!" | |
return 2 | |
fi | |
if [ -d "./$PDIR" ]; then | |
rsync -rvhP ./ /usr/src/"$PDIR" | |
else | |
echo -e '[ERROR]: Unable to locate module provided directory !\nABORTING!' | |
return 3 | |
fi | |
# DKMS Build process | |
dkms add -m "$MODNAME" -v "$VER" | |
dkms build -m "$MODNAME" -v "$VER" | |
dkms install -m "$MODNAME" -v "$VER" | |
echo -e "\n\n[SUCCESS]: Successfully compiled the custom/hacked/tweaked kernel-module: '$' for Linux kernel: '$(uname -r)' !" | |
return 0 | |
} | |
# XXX: Quick edit of these settings: | |
alias opkgconf='nano ~/.openwrt_aliases' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LANG=nb_NO.UTF-8 | |
#LANGUAGE=nb_NO:nb:no_NO:no:en | |
LC_CTYPE="nb_NO.UTF-8" | |
LC_NUMERIC="nb_NO.UTF-8" | |
LC_TIME="nb_NO.UTF-8" | |
LC_COLLATE="nb_NO.UTF-8" | |
LC_MONETARY="nb_NO.UTF-8" | |
LC_MESSAGES="nb_NO.UTF-8" | |
LC_PAPER="nb_NO.UTF-8" | |
LC_NAME="nb_NO.UTF-8" | |
LC_ADDRESS="nb_NO.UTF-8" | |
LC_TELEPHONE="nb_NO.UTF-8" | |
LC_MEASUREMENT="nb_NO.UTF-8" | |
LC_IDENTIFICATION="nb_NO.UTF-8" | |
LC_ALL= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment