Last active
April 2, 2023 10:44
-
-
Save appleneko2001/d8c8889de4616484c63afc8b332acfc4 to your computer and use it in GitHub Desktop.
My linux cheatsheets
This file contains hidden or 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/sh | |
| # ! DONT FORGET CHANGE OUTPUT DIRECTORY TO MAKE IT FIT TO YOUR COMPUTER ! | |
| OUTPUT_DIR="/mnt/archive/journal/$(date +%Y)" | |
| if [ "${1+x}" ] | |
| then | |
| echo "Argument #1 should be used for restore operation ID" | |
| echo "due my skill issue. Plz do not abuse it :)" | |
| echo "TMP_ID=$1" | |
| TMP_ID=$1 | |
| fi | |
| if [ "$(whoami)" != "root" ] ; then | |
| echo "This script requires root privileges to archive journal files." >&2 | |
| return 1 | |
| fi | |
| SETUP_VARS(){ | |
| DATE_NAME="$(date +%F)_$(date +%T | tr : _).tar.xz" | |
| TMP_PATH="/tmp/$1" | |
| } | |
| CLEAN(){ | |
| echo "Cleaning..." | |
| rm -rfi "$TMP_PATH" | |
| } | |
| if [ ! DETECT_IS_ROOT ] | |
| then | |
| return 1 | |
| fi | |
| # DETERMINE VAR IS NOT SET: | |
| if [ ! "${TMP_ID+x}" ] | |
| then | |
| TMP_ID=$(head --bytes=16 /dev/urandom | od -A n -v -t x1 | tr -d ' ' | tr -d '\n') | |
| #echo $TMP_ID | |
| if [ ! "${TMP_ID+x}" ] ; then | |
| echo "WHAT THE FUCK TMP_ID is EMPTY!!!" >&2 | |
| echo "GONNA USE SOME HAND TYPED ID INSTEAD!!!" >&2 | |
| TMP_ID=journal_archive | |
| fi | |
| SETUP_VARS $TMP_ID | |
| mkdir "$TMP_PATH" | |
| for LOG_ENTRY_FILE in $(find /var/log/journal -name '*@*.journal' || exit) | |
| do | |
| echo "Found \"$LOG_ENTRY_FILE\"" | |
| mv "$LOG_ENTRY_FILE" "$TMP_PATH/" | |
| done | |
| else | |
| echo "Found previous failed archive operation..." | |
| SETUP_VARS $TMP_ID | |
| echo $OUTPUT_DIR | |
| echo $DATE_NAME | |
| echo $TMP_PATH | |
| fi | |
| if [ -z "$(ls -A "$TMP_PATH")" ] | |
| then | |
| echo "Nothing to archive. Aborting..." | |
| CLEAN | |
| return 2 | |
| fi | |
| echo "Archiving journal files..." >&2 | |
| TMP_TARNAME=/tmp/$TMP_ID.tar.xz | |
| echo "Creating archive... (it will be extremely slow because tar.xz with better ratio...)" | |
| if ! tar -cvf - "$TMP_PATH" | xz -8 -z -c - > "$TMP_TARNAME" | |
| then | |
| echo "Unable to create archive." | |
| rm "$TMP_TARNAME" | |
| echo "Exporting TMP_ID to allow next attempt..." | |
| export TMP_ID | |
| return 3 | |
| # CLEAN | |
| fi | |
| mkdir -p "$OUTPUT_DIR" || exit | |
| FIN_OUTPUT="$OUTPUT_DIR/$DATE_NAME" | |
| mv "$TMP_TARNAME" "$FIN_OUTPUT" || exit | |
| echo "Journal logs have been cleared and archived to \"$FIN_OUTPUT\"." >&2 | |
| CLEAN | |
| export TMP_ID="" | |
| return 0 | |
This file contains hidden or 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
| #!/usr/bin/env xdg-open | |
| [Desktop Entry] | |
| Categories=System | |
| Exec=/usr/bin/java -jar %f | |
| Icon=java | |
| Name=Java Package Loader | |
| Terminal=false | |
| Type=Application |
This file contains hidden or 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
| #!/usr/bin/env xdg-open | |
| [Desktop Entry] | |
| Categories=System | |
| Exec=/usr/bin/wine start /unix %f | |
| Icon=wine | |
| Name=Wine Windows Application Loader | |
| Terminal=false | |
| Type=Application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment