Compare commits

..

19 Commits

Author SHA1 Message Date
ef2bb4f28a Added new handle_logs function 2024-06-06 17:15:31 -05:00
2e9d4712fa Moved keyring install to correct place 2024-05-12 22:31:21 -05:00
50c4834032 Fixed syntax issue and added archlinux-keyring install & configure 2024-05-12 22:27:05 -05:00
617326fd52 Removed un-necessary echo statement 2023-12-06 11:32:11 -06:00
5501e3fa57 Removed un-necessary shifts and reset index of variable 2023-12-06 11:31:10 -06:00
6cf389acdd Forgot to push on other computer (fixed variable setting) 2023-12-06 11:28:04 -06:00
b22dcd6831 Somehow deleted the coproc 2023-12-06 11:06:51 -06:00
4873410cd2 removed redirect into /dev/null for installer download (so that the user is aware that a download is happening) 2023-12-03 22:13:01 -06:00
Tristan Ancelet
2a7519024c Added 'Description' to doc 2023-12-01 12:48:34 -06:00
Tristan Ancelet
254e7834b7 corrected wget dep to curl 2023-12-01 12:47:29 -06:00
Tristan Ancelet
8ff7e47140 Capitalized letter 2023-12-01 12:46:25 -06:00
Tristan Ancelet
6806beb733 Added doc section explaining the script and my plans for it 2023-12-01 12:45:01 -06:00
Tristan Ancelet
dd157e834c Cleaned up 'log' function. Variable declarations somehow were inline (didn't affect function, just doesn't look right 2023-12-01 12:28:52 -06:00
Tristan Ancelet
f504eb3c63 Added log statement to notify user that the desktop file will be udated if there is a difference with the new desktop file setup after installation/update 2023-12-01 12:26:13 -06:00
Tristan Ancelet
05a05dfca6 Updated comments and log messages to correct them 2023-12-01 12:24:18 -06:00
Tristan Ancelet
22669044db Removed un-necessary desktop-file-install's and setup flagged conditional that will handle installing/updating the desktop file if needed 2023-12-01 12:22:49 -06:00
Tristan Ancelet
2b6efc9a5d Just realized there was an icon dir already existing in ($HOME/.local/share/icons). Removed my "custom" one and will use it instead. 2023-12-01 12:15:51 -06:00
Tristan Ancelet
fc82020be3 Updated log message to correct it and removed un-necessary sudo before desktop-file-install 2023-12-01 12:10:59 -06:00
Tristan Ancelet
47fbc1cb8a Added new section that will handle installing the desktop file if it isn't already 2023-12-01 12:08:37 -06:00
4 changed files with 156 additions and 30 deletions

View File

@@ -18,9 +18,8 @@ get_disks () {
get_choices () {
local PROMPT="$1"
shift
local -n OUTPUT_VAR="$2"
shift
shift 2
local -a OPTIONS=( $@ )
select item in ${OPTIONS[@]} quit; do
@@ -42,11 +41,9 @@ get_choices () {
}
get_choice () {
echo "1: $1"
local PROMPT="$1"
local -n OUTPUT_VAR="$2"
shift
shift
shift 2
local -a OPTIONS=( $@ )
select item in ${OPTIONS[@]} quit; do
@@ -124,9 +121,8 @@ get_disks DISKS
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
# If the disk is a nvme drive
if [[ "$DISK" =~ ^/dev/nvmen[0-9]$ ]]
if [[ "$DISK" =~ ^/dev/nvmen[0-9]$ ]]; then
DISK_BASE=${DISK}p
else
DISK_BASE="${DISK}"
fi
@@ -304,6 +300,9 @@ A program needed for privelege escalation. Basically to provide a user of an adm
Installing it here because it is not installed by default. An alternative is doas, a utility to perform the same funciton.
"
pacman -Sy archlinux-keyring
pacman-key --init
pacman-key --populate archlinux
pacstrap /mnt base linux linux-headers linux-firmware sudo
## Setting up fstab

View File

@@ -64,6 +64,7 @@ do_emergency_email () {
MAILSERVER=`dig $DOMAIN mx | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1`
## Setting up coprocess to send commands to telnet session coproc TELNET { telnet $MAILSERVER 25; }
coproc TELNET { telnet $MAILSERVER 25; }
## Commands to send email manually
local -a commands=(

View File

@@ -50,8 +50,56 @@ DATE_REGEX='[0-9]{4}-[0-9]{2}-[0-9]{2}'
# END: Variables
# BEGIN: Helper Functions
function handle_logs() {
cd $LOG_DIR
echo "Began Handling logs at: $(date)"
local ARCHIVE_FILE=archive.tar.gz
local ARCHIVE_FILE_UNZIPED=${ARCHIVE_FILE%.gz}
if [[ -f $ARCHIVE_FILE ]]; then
## Decompressing archive in case it exists
gunzip $ARCHIVE_FILE 2>/dev/null
fi
## Getting all files
local FILES=( $( ls -1tr *.log ) )
if [[ ${#FILES[@]} -le $LIMIT ]]; then
echo "Only had ${#FILES[@]} logs, and did not exceed $LIMIT. Not handling logs"
return
fi
## Getting files we are keeping
local FILES_TO_KEEP=${FILES[@]: -$LIMIT}
## Creating REGEX filter
FILES_TO_KEEP=${FILES_TO_KEEP//[[:space:]]/|}
## Filtering out logs to keep
local FILES_TO_ARCHIVE=( $( ls -1 *.log | grep -Ev "(${FILES_TO_KEEP})" ) )
echo "Adding archived logs to archive"
## Updating archive
tar uvf $ARCHIVE_FILE_UNZIPED ${FILES_TO_ARCHIVE[@]}
## Compressing Archive
echo "Compressing Archive"
gzip $ARCHIVE_FILE_UNZIPED
## Removing archived logs
echo "Removing archived files"
rm -vf ${FILES_TO_ARCHIVE[@]}
echo "Finished Handling logs at: $(date)"
}
# END: Helper Functions
# BEGIN: Pre-Work Checks
## Setting up the script to direct all output to the log file for this snapshot session
exec > $LOG_FILE
## This will check to make sure that the log directory has been created, if not it will create it
@@ -60,7 +108,6 @@ exec > $LOG_FILE
echo "$LOG_DIR did not exist. Creating"
}
## Setting up the script to direct all output to the log file for this snapshot session
# END: Pre-Work Checks
@@ -104,8 +151,15 @@ for SUBVOL_INFO in ${SUBVOLS[@]}; do
SNAPSHOT=$SUBVOL_BACKUP_DIR/$DATE
## If the snapshot doesn't already exist, then create a new read-only snapshot
[[ ! -d $SNAPSHOT ]] && /usr/sbin/btrfs subvol snapshot -r $DIR $SNAPSHOT
if [[ ! -d $SNAPSHOT ]]; then
/usr/sbin/btrfs subvol snapshot -r $DIR $SNAPSHOT
else
echo "$SNAPSHOT already existed. Not backing up"
fi
done
handle_logs
echo "Finishing backup at `date`"
# END: Work

View File

@@ -1,5 +1,49 @@
#!/usr/bin/bash
######################################################################################
# install-discord-linux.sh #
######################################################################################
# Description # #
############### #
# #
# This script was created to automate the install of discord on your system. #
# It installs it separately from a package manager (snap, apt, dnf, etc), so this #
# can be used to install it on any linux system regardless of distro #
# as long as the OS & processor supports it. #
# #
# This script was originally just setup to handle installing or updating the #
# existing installation. It can be setup in crontab to handle it automatically so #
# you never have to manually do it again. All you have to do is add it to your #
# crontab to run daily or hourly (assuming you have a cron service installed) #
# #
# EX: #
# """ #
# CRONTAB="$(crontab -l)" #
# if [[ $? -eq 0 ]]; then #
# CRONTAB+="\n0 0 * * * /path/to/script.sh" #
# echo -e "$CRONTAB" | crontab - #
# else #
# echo "0 0 * * * /path/to/script.sh" | crontab - #
# fi #
# """ #
# #
# Eventually I am wanting this script to also provide additional functionalities: #
# - Install BetterDiscord #
# - Handle multiple installations of discord (makes named config directories #
# and will symlink them based on what "profile" you want to use). This will also #
# allow you to have a installation that contains mods and others without. #
# - Handle manual configurations of discord (where applicable) #
# #
######################################################################################
# Dependencies # #
################ #
# #
# 1) curl #
# 2) bash (of course) #
# #
######################################################################################
# BEGIN: Variables
DEBUG=1
@@ -7,13 +51,16 @@ ACTION=""
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+'
INSTALL_DIR=~/.opt
[[ ! -d $INSTALL_DIR ]] && mkdir -p $INSTALL_DIR
LOCAL_APPLICATION_DIR=~/.local/share/applications
EXISTING_INSTALL=$INSTALL_DIR/Discord
BUILD_FILE=$EXISTING_INSTALL/resources/build_info.json
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
INSTALLED_DESKTOP_FILE=$LOCAL_APPLICATION_DIR/discord.desktop
PACKAGE_DOWNLOAD_URL_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
ICON_DIR=~/.icons
DESKTOP_FILE_INSTALLED=0
[[ -f /usr/share/applications/discord.desktop ]] && DESKTOP_FILE_INSTALLED=1
ICON_DIR=~/.local/share/icons
DESKTOP_FILE_NEEDS_UPDATE=0
REMOVE_AFTER_INSTALL=1
# END: Variables
@@ -21,7 +68,9 @@ DESKTOP_FILE_INSTALLED=0
# BEGIN: Helper Functions
function log () {
if [[ $DEBUG -eq 1 ]]; then local DATE=`date` local MESSAGE="${1:?"log: Message not provided"}"
if [[ $DEBUG -eq 1 ]]; then
local DATE=`date`
local MESSAGE="${1:?"log: Message not provided"}"
echo "$DATE : $MESSAGE"
fi
}
@@ -55,10 +104,10 @@ function do_download(){
## Getting filename from url
### Removing all characters from the last / back to leave only the filename
FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}"
log "File was downloaded as $FILENAME"
## Downloading the discord package (tar.gz)
curl "$PACKAGE_DOWNLOAD_URL" -o "$FILENAME" >/dev/null 2>&1
curl "$PACKAGE_DOWNLOAD_URL" -o "$FILENAME"
log "File was downloaded as $FILENAME"
}
function update_desktop_file() {
@@ -90,6 +139,12 @@ function update_desktop_file() {
}
function remove_installer () {
if [[ $REMOVE_AFTER_INSTALL -eq 1 ]]; then
rm -f $FILENAME
fi
}
function do_install() {
cd "$INSTALL_DIR"
@@ -107,20 +162,10 @@ function do_install() {
update_desktop_file
## If your icon dir (configured above) exists in the env variable
if [[ "$XDG_DATA_DIRS" != *$ICON_DIR* ]]; then
export XDG_DATA_DIRS=$XDG_DATA_DIRS:$ICON_DIR
if [[ $SHELL == *bash ]]; then
echo 'export XDG_DATA_DIRS=$XDG_DATA_DIRS':$ICON_DIR > ~/.bashrc
else
echo 'export XDG_DATA_DIRS=$XDG_DATA_DIRS':$ICON_DIR > ~/.profile
fi
fi
[[ ! -d $ICON_DIR ]] && mkdir -p $ICON_DIR
cp $EXISTING_INSTALL/discord.png $ICON_DIR/
sudo desktop-file-isntall $DESKTOP_FILE
remove_installer
}
function do_upgrade(){
@@ -136,9 +181,7 @@ function do_upgrade(){
update_desktop_file
if [[ $DESKTOP_FILE_INSTALLED -eq 0 ]]; then
sudo desktop-file-install $DESKTOP_FILE
fi
remove_installer
}
# END: Helper Functions
@@ -197,3 +240,32 @@ esac
# END: Work
# BEGIN: End Work Check
## If discord isn't already setup, go ahead and mark it for install/update
if [[ ! -f $INSTALLED_DESKTOP_FILE ]]; then
log "Desktop file not found in the local applications dir ($LOCAL_APPLICATION_DIR) installing now"
DESKTOP_FILE_NEEDS_UPDATE=1
else
# If there is a change for any reason update it
if [[ "$(<$DESKTOP_FILE)" != "$(<$INSTALLED_DESKTOP_FILE)" ]]; then
log "Desktop file for new version of discord has changed. Updating the existing installation"
DESKTOP_FILE_NEEDS_UPDATE=1
fi
fi
if [[ $DESKTOP_FILE_NEEDS_UPDATE -eq 1 ]]; then
log "Updating/Installing desktop file"
desktop-file-install --dir=$LOCAL_APPLICATION_DIR $DESKTOP_FILE
if [[ $? -ne 0 ]]; then
log "There was an issue with installtion"
else
log "Desktop file was successfully installed"
fi
fi
# END: End Work Check