Compare commits
32 Commits
2291793f6d
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
e7f6697038 | ||
|
3be7c31aa5 | ||
|
77eb648a9a | ||
|
1e53f004f7 | ||
|
696a71bd8b | ||
|
713ea521c8 | ||
b6226ad3cb | |||
72549ac3bf | |||
eb875363e1 | |||
7b61dd700a | |||
01a838c7f2 | |||
89cbb8a4d4 | |||
4b409db718 | |||
ef2bb4f28a | |||
2e9d4712fa | |||
50c4834032 | |||
617326fd52 | |||
5501e3fa57 | |||
6cf389acdd | |||
b22dcd6831 | |||
4873410cd2 | |||
|
2a7519024c | ||
|
254e7834b7 | ||
|
8ff7e47140 | ||
|
6806beb733 | ||
|
dd157e834c | ||
|
f504eb3c63 | ||
|
05a05dfca6 | ||
|
22669044db | ||
|
2b6efc9a5d | ||
|
fc82020be3 | ||
|
47fbc1cb8a |
@@ -18,9 +18,8 @@ get_disks () {
|
|||||||
|
|
||||||
get_choices () {
|
get_choices () {
|
||||||
local PROMPT="$1"
|
local PROMPT="$1"
|
||||||
shift
|
|
||||||
local -n OUTPUT_VAR="$2"
|
local -n OUTPUT_VAR="$2"
|
||||||
shift
|
shift 2
|
||||||
local -a OPTIONS=( $@ )
|
local -a OPTIONS=( $@ )
|
||||||
|
|
||||||
select item in ${OPTIONS[@]} quit; do
|
select item in ${OPTIONS[@]} quit; do
|
||||||
@@ -42,11 +41,9 @@ get_choices () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_choice () {
|
get_choice () {
|
||||||
echo "1: $1"
|
|
||||||
local PROMPT="$1"
|
local PROMPT="$1"
|
||||||
local -n OUTPUT_VAR="$2"
|
local -n OUTPUT_VAR="$2"
|
||||||
shift
|
shift 2
|
||||||
shift
|
|
||||||
local -a OPTIONS=( $@ )
|
local -a OPTIONS=( $@ )
|
||||||
|
|
||||||
select item in ${OPTIONS[@]} quit; do
|
select item in ${OPTIONS[@]} quit; do
|
||||||
@@ -124,9 +121,8 @@ get_disks DISKS
|
|||||||
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
|
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
|
||||||
|
|
||||||
# If the disk is a nvme drive
|
# If the disk is a nvme drive
|
||||||
if [[ "$DISK" =~ ^/dev/nvmen[0-9]$ ]]
|
if [[ "$DISK" =~ ^/dev/nvmen[0-9]$ ]]; then
|
||||||
DISK_BASE=${DISK}p
|
DISK_BASE=${DISK}p
|
||||||
|
|
||||||
else
|
else
|
||||||
DISK_BASE="${DISK}"
|
DISK_BASE="${DISK}"
|
||||||
fi
|
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.
|
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
|
pacstrap /mnt base linux linux-headers linux-firmware sudo
|
||||||
|
|
||||||
## Setting up fstab
|
## Setting up fstab
|
||||||
|
@@ -64,6 +64,7 @@ do_emergency_email () {
|
|||||||
MAILSERVER=`dig $DOMAIN mx | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1`
|
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; }
|
## Setting up coprocess to send commands to telnet session coproc TELNET { telnet $MAILSERVER 25; }
|
||||||
|
coproc TELNET { telnet $MAILSERVER 25; }
|
||||||
|
|
||||||
## Commands to send email manually
|
## Commands to send email manually
|
||||||
local -a commands=(
|
local -a commands=(
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# do-daily-backup.sh #
|
# do-daily-btrfs-snapshot.sh #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# This script is my attempt at replicating the same function that timeshift #
|
# This script is my attempt at replicating the same function that timeshift #
|
||||||
# performs. This is a very simplified script to handle automated btrfs #
|
# performs. This is a very simplified script to handle automated btrfs #
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
# BEGIN: Variables
|
# BEGIN: Variables
|
||||||
|
|
||||||
## Reusable vars
|
## Reusable vars
|
||||||
DATE=`date +%Y-%m-%d`
|
DATE=$(date +%Y-%m-%d)
|
||||||
### Getting the name of the script (as it will be the first thing passed to bash when executing)
|
### Getting the name of the script (as it will be the first thing passed to bash when executing)
|
||||||
SCRIPT=`basename $0`
|
SCRIPT=$(basename $0)
|
||||||
BACKUP_DIR=/.backups
|
BACKUP_DIR=/.backups
|
||||||
### Setting dir to house log files
|
### Setting dir to house log files
|
||||||
LOG_DIR=/var/log/$SCRIPT
|
LOG_DIR=/var/log/$SCRIPT
|
||||||
@@ -50,8 +50,56 @@ DATE_REGEX='[0-9]{4}-[0-9]{2}-[0-9]{2}'
|
|||||||
# END: Variables
|
# 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_UNZIPPED=${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_UNZIPPED ${FILES_TO_ARCHIVE[@]}
|
||||||
|
|
||||||
|
## Compressing Archive
|
||||||
|
echo "Compressing Archive"
|
||||||
|
gzip $ARCHIVE_FILE_UNZIPPED
|
||||||
|
|
||||||
|
## 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
|
# BEGIN: Pre-Work Checks
|
||||||
|
|
||||||
|
## Setting up the script to direct all output to the log file for this snapshot session
|
||||||
exec > $LOG_FILE
|
exec > $LOG_FILE
|
||||||
|
|
||||||
## This will check to make sure that the log directory has been created, if not it will create it
|
## 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"
|
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
|
# END: Pre-Work Checks
|
||||||
@@ -104,8 +151,15 @@ for SUBVOL_INFO in ${SUBVOLS[@]}; do
|
|||||||
|
|
||||||
SNAPSHOT=$SUBVOL_BACKUP_DIR/$DATE
|
SNAPSHOT=$SUBVOL_BACKUP_DIR/$DATE
|
||||||
## If the snapshot doesn't already exist, then create a new read-only snapshot
|
## 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 doing a snapshot"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
handle_logs
|
||||||
|
|
||||||
echo "Finishing backup at `date`"
|
echo "Finishing backup at `date`"
|
||||||
|
|
||||||
# END: Work
|
# END: Work
|
||||||
|
345
install-discord-linux.rb
Executable file
345
install-discord-linux.rb
Executable file
@@ -0,0 +1,345 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# BEGIN: Includes & Requires
|
||||||
|
|
||||||
|
require 'erb'
|
||||||
|
require 'time'
|
||||||
|
require 'json'
|
||||||
|
require 'zlib'
|
||||||
|
require 'find'
|
||||||
|
require 'English'
|
||||||
|
require 'net/http'
|
||||||
|
require 'optparse'
|
||||||
|
require 'fileutils'
|
||||||
|
require 'rubygems/package'
|
||||||
|
|
||||||
|
# END: Includes & Requires
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Overrides
|
||||||
|
|
||||||
|
class Dir
|
||||||
|
def / (path)
|
||||||
|
output_path = File.join(self.path + '/' + path)
|
||||||
|
if File.directory? output_path
|
||||||
|
Dir.new(output_path)
|
||||||
|
else
|
||||||
|
output_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias to_s path
|
||||||
|
|
||||||
|
## For backwards compat
|
||||||
|
def chdir(dir = nil, &block)
|
||||||
|
if dir.nil?
|
||||||
|
Dir.chdir(self, &block)
|
||||||
|
else
|
||||||
|
Dir.chdir(dir, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class String
|
||||||
|
def / (other)
|
||||||
|
File.join(self, other)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# END: Overrides
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Variables
|
||||||
|
URL_DOWNLOAD_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
|
||||||
|
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||||
|
|
||||||
|
$CONFIG = Hash.new
|
||||||
|
$CONFIG[:icon_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'icons'
|
||||||
|
File.mkdir($CONFIG[:icon_dir]) if not File.exist?($CONFIG[:icon_dir])
|
||||||
|
$CONFIG[:discord_config_path] = Dir.new(Dir.home) / '.config' / 'discord'
|
||||||
|
$CONFIG[:local_application_install_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'applications'
|
||||||
|
File.mkdir($CONFIG[:local_application_install_dir]) if not File.exist?($CONFIG[:local_application_install_dir])
|
||||||
|
$CONFIG[:install_dir] = Dir.new(Dir.home) / '.opt'
|
||||||
|
$CONFIG[:desktop_path] = $CONFIG[:install_dir] / 'Discord' / 'discord.desktop'
|
||||||
|
File.mkdir($CONFIG[:install_dir]) if not File.exist?($CONFIG[:install_dir])
|
||||||
|
$CONFIG[:discord_path] = $CONFIG[:install_dir] / 'Discord'
|
||||||
|
$CONFIG[:desktop_file_path] = $CONFIG[:local_application_install_dir] / 'discord.desktop'
|
||||||
|
$CONFIG[:discord_version_file] = $CONFIG[:discord_path] / 'resources' / 'build_info.json'
|
||||||
|
$CONFIG[:action] = 'install'
|
||||||
|
$CONFIG[:keep_installer] = false
|
||||||
|
$CONFIG[:debug] = false
|
||||||
|
DISCORD_DESKTOP_TEMPLATE = ERB.new(<<ERB, trim_mode:'-')
|
||||||
|
[Desktop Entry]
|
||||||
|
Name=Discord
|
||||||
|
StartupWMClass=discord
|
||||||
|
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
|
||||||
|
GenericName=Internet Messenger
|
||||||
|
Exec=<%= $CONFIG[:discord_path] %>/Discord
|
||||||
|
Icon=discord
|
||||||
|
Type=Application
|
||||||
|
Categories=Network;InstantMessaging;
|
||||||
|
Path=<%= $CONFIG[:discord_path] %>
|
||||||
|
ERB
|
||||||
|
# END: Variables
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Handle CLI ARgs
|
||||||
|
|
||||||
|
OptionParser.new do |parser|
|
||||||
|
parser.banner = "#{ File.basename($0) } [action]"
|
||||||
|
parser.separator ""
|
||||||
|
parser.separator " Actions"
|
||||||
|
parser.separator "------------------------------------------------------------------------"
|
||||||
|
|
||||||
|
parser.on('-c', '--check', "Check and report installed & remote versions") do
|
||||||
|
$CONFIG[:action] = 'check'
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-i', '--install', "Check for & Install new version of discord (default)") do
|
||||||
|
$CONFIG[:action] = 'install'
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-u', '--uninstall', "Uninstall Discord (not-implemented)") do
|
||||||
|
$CONFIG[:action] = 'uninstall'
|
||||||
|
$CONFIG[:backup_filename] = Dir.home / 'discord-backup-' + Time.now.strftime('%Y-%m-%d') + '.tar.gz'
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-b', '--backup [FILENAME]', "Backup Discord Installation") do |backup_filename|
|
||||||
|
$CONFIG[:action] = 'backup'
|
||||||
|
if backup_filename.nil?
|
||||||
|
$CONFIG[:backup_filename] = Dir.home / 'discord-backup-' + Time.now.strftime('%Y-%m-%d') + '.tar.gz'
|
||||||
|
else
|
||||||
|
$CONFIG[:backup_filename] = backup_filename + ".tar.gz"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('--update-desktop', "Update desktop file"){
|
||||||
|
$CONFIG[:action] = 'update-desktop'
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.separator ""
|
||||||
|
parser.separator " General Flags"
|
||||||
|
parser.separator "------------------------------------------------------------------------"
|
||||||
|
parser.on('-h', '--help', "Show this help output") do
|
||||||
|
puts parser
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-d', '--debug', "Turn on debug logging") do
|
||||||
|
$CONFIG[:debug] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('--keep', "Keep discord tar.gz file (default: #{$CONFIG[:keep_installer].to_s})") do
|
||||||
|
$CONFIG[:keep_installer] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
end.parse!
|
||||||
|
|
||||||
|
# BEGIN: Handle CLI ARgs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Helper Classes
|
||||||
|
class DesktopFile
|
||||||
|
@@file = File.open($CONFIG[:desktop_path])
|
||||||
|
@@installed_file = File.open($CONFIG[:desktop_file_path])
|
||||||
|
|
||||||
|
def needs_update?
|
||||||
|
@@installed_file.read() != contents
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if needs_update?
|
||||||
|
File.open(@@file, 'w') do |file|
|
||||||
|
puts "Updating Desktop File, changes are needed"
|
||||||
|
file.write(contents)
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries"
|
||||||
|
%x[ desktop-file-install --dir=#{$CONFIG[:local_application_install_dir]} #{$CONFIG[:desktop_path]} ]
|
||||||
|
else
|
||||||
|
puts "Not updating file. Changes not needed"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
DISCORD_DESKTOP_TEMPLATE.def_method(DesktopFile, 'contents')
|
||||||
|
|
||||||
|
class Installer
|
||||||
|
URL_DOWNLOAD_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
|
||||||
|
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||||
|
@@desktop_file = DesktopFile.new
|
||||||
|
|
||||||
|
def needs_update?
|
||||||
|
local_version < remote_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def remote_version
|
||||||
|
if @remote_version.nil?
|
||||||
|
uri = URI(DOWNLOAD_URL)
|
||||||
|
response = Net::HTTP.get(uri)
|
||||||
|
if response =~ /discord-(?<version>\d+\.\d+\.\d+).tar.gz/
|
||||||
|
@remote_version = Gem::Version.new($LAST_MATCH_INFO['version'])
|
||||||
|
else
|
||||||
|
raise "Failed to retrieve remote version"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@remote_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def local_version
|
||||||
|
if @local_version.nil?
|
||||||
|
@local_version = if File.exist? $CONFIG[:discord_version_file]
|
||||||
|
data = JSON.load_file($CONFIG[:discord_version_file])
|
||||||
|
Gem::Version.new(data['version'])
|
||||||
|
else
|
||||||
|
Gem::Version.new('0.0.0')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@local_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def download
|
||||||
|
version = self.remote_version.to_s
|
||||||
|
uri = URI(URL_DOWNLOAD_BASE.gsub('{VERSION}',version))
|
||||||
|
puts "download_installer: Downloading The discord #{version} tar.gz"
|
||||||
|
file_contents = Net::HTTP.get(uri)
|
||||||
|
output_file = "discord-#{version}.tar.gz"
|
||||||
|
puts "download_installer: Output file will #{output_file}"
|
||||||
|
$CONFIG[:install_dir].chdir do
|
||||||
|
File.open(output_file, 'wb') do |file|
|
||||||
|
file.write(file_contents)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "download_installer: tar.gz was downloaded"
|
||||||
|
end
|
||||||
|
|
||||||
|
def install
|
||||||
|
installer_file = "discord-#{self.remote_version}.tar.gz"
|
||||||
|
puts "do_install: Extracting new installer"
|
||||||
|
$CONFIG[:install_dir].chdir do
|
||||||
|
File.open(installer_file, 'rb') do |file|
|
||||||
|
Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir])
|
||||||
|
end
|
||||||
|
|
||||||
|
if not $CONFIG[:keep_installer]
|
||||||
|
puts "do_install: Removing new installer (#{installer_file})"
|
||||||
|
File.unlink(installer_file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@@desktop_file.update
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# END: Helper Classes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Helper Functions
|
||||||
|
|
||||||
|
def make_backup
|
||||||
|
files = {
|
||||||
|
files: Array.new,
|
||||||
|
dirs: Array.new,
|
||||||
|
symlinks: Array.new
|
||||||
|
}
|
||||||
|
|
||||||
|
[ $CONFIG[:discord_config_path].path, $CONFIG[:discord_path].path ].each do |backup_dir|
|
||||||
|
puts "make_backup: Getting Files from #{backup_dir})"
|
||||||
|
Find.find("#{backup_dir}").each{ |item|
|
||||||
|
puts("#{item} was retrieved from #{backup_dir}") if $CONFIG[:debug]
|
||||||
|
if File.file?(item)
|
||||||
|
puts("#{item} was found to be a file") if $CONFIG[:debug]
|
||||||
|
files[:files] << item
|
||||||
|
elsif File.symlink?(item)
|
||||||
|
puts("#{item} was found to be a symlink") if $CONFIG[:debug]
|
||||||
|
files[:symlinks] << item
|
||||||
|
elsif File.directory?(item)
|
||||||
|
puts("#{item} was found to be a directory") if $CONFIG[:debug]
|
||||||
|
files[:dirs] << item
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.chdir(Dir.home) do
|
||||||
|
puts "make_backup: Beginning backup process (OUTPUT_FILE = #{$CONFIG[:backup_filename]})"
|
||||||
|
File.open($CONFIG[:backup_filename], "wb") do |backup_file|
|
||||||
|
Zlib::GzipWriter.wrap(backup_file) do |gzip|
|
||||||
|
Gem::Package::TarWriter.new(gzip) do |tar|
|
||||||
|
|
||||||
|
puts "\nmake_backup : files : Beginning backup process for files (Count: #{files[:files].count})"
|
||||||
|
file_count = files[:files].count
|
||||||
|
files[:files].each_with_index { |file, i|
|
||||||
|
puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug]
|
||||||
|
File.open(file, 'rb') { |file_to_archive|
|
||||||
|
contents = file_to_archive.read()
|
||||||
|
tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) { |io|
|
||||||
|
io.write(contents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts "\nmake_backup : directories : Beginning backup process for directories (Count: #{files[:dirs].count})"
|
||||||
|
dir_count = files[:dirs].count
|
||||||
|
files[:dirs].each_with_index {|dir,i|
|
||||||
|
puts "make_backup : directories : Backing up #{dir} (#{i+1}/#{dir_count})" if $CONFIG[:debug]
|
||||||
|
tar.mkdir(dir.sub("#{Dir.home}/",""), File.stat(dir).mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
puts "\nmake_backup : symlinks : Beginning backup process for symlinks (Count: #{files[:symlinks].count})"
|
||||||
|
symlink_count = files[:symlinks].count
|
||||||
|
files[:symlinks].each_with_index {|symlink,i|
|
||||||
|
puts "make_backup : symlinks : Backing up #{symlink} (#{i+1}/#{symlink_count})" if $CONFIG[:debug]
|
||||||
|
tar.add_symlink(symlink.sub("#{Dir.home}/",""), File.readlink(symlink), File.lstat(symlink).mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# END: Helper Functions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Work
|
||||||
|
|
||||||
|
installer = Installer.new
|
||||||
|
case $CONFIG[:action]
|
||||||
|
|
||||||
|
when 'install'
|
||||||
|
if installer.needs_update?
|
||||||
|
puts "main: Installed Version will be updated"
|
||||||
|
installer.download
|
||||||
|
installer.install
|
||||||
|
elsif installer.local_version == installer.remote_version
|
||||||
|
puts "main: Installed Version is up-to-date"
|
||||||
|
else
|
||||||
|
puts "main: What?"
|
||||||
|
end
|
||||||
|
|
||||||
|
when 'check'
|
||||||
|
puts
|
||||||
|
puts " Report"
|
||||||
|
puts "-------------------------------------"
|
||||||
|
puts " Remote Version: #{installer.remote_version.to_s}"
|
||||||
|
puts " Local Version: #{installer.local_version.to_s}"
|
||||||
|
puts " Needs Updating: #{installer.needs_update? ? "Yes" : "No"}"
|
||||||
|
|
||||||
|
when 'backup'
|
||||||
|
make_backup
|
||||||
|
|
||||||
|
when 'update-desktop'
|
||||||
|
DesktopFile.new.update
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# END: Work
|
@@ -1,5 +1,49 @@
|
|||||||
#!/usr/bin/bash
|
#!/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
|
# BEGIN: Variables
|
||||||
|
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
@@ -7,13 +51,16 @@ ACTION=""
|
|||||||
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||||
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+'
|
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+'
|
||||||
INSTALL_DIR=~/.opt
|
INSTALL_DIR=~/.opt
|
||||||
|
[[ ! -d $INSTALL_DIR ]] && mkdir -p $INSTALL_DIR
|
||||||
|
LOCAL_APPLICATION_DIR=~/.local/share/applications
|
||||||
EXISTING_INSTALL=$INSTALL_DIR/Discord
|
EXISTING_INSTALL=$INSTALL_DIR/Discord
|
||||||
BUILD_FILE=$EXISTING_INSTALL/resources/build_info.json
|
BUILD_FILE=$EXISTING_INSTALL/resources/build_info.json
|
||||||
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
|
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'
|
PACKAGE_DOWNLOAD_URL_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
|
||||||
ICON_DIR=~/.icons
|
ICON_DIR=~/.local/share/icons
|
||||||
DESKTOP_FILE_INSTALLED=0
|
DESKTOP_FILE_NEEDS_UPDATE=0
|
||||||
[[ -f /usr/share/applications/discord.desktop ]] && DESKTOP_FILE_INSTALLED=1
|
REMOVE_AFTER_INSTALL=1
|
||||||
|
|
||||||
# END: Variables
|
# END: Variables
|
||||||
|
|
||||||
@@ -21,7 +68,9 @@ DESKTOP_FILE_INSTALLED=0
|
|||||||
# BEGIN: Helper Functions
|
# BEGIN: Helper Functions
|
||||||
|
|
||||||
function log () {
|
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"
|
echo "$DATE : $MESSAGE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -55,10 +104,10 @@ function do_download(){
|
|||||||
## Getting filename from url
|
## Getting filename from url
|
||||||
### Removing all characters from the last / back to leave only the filename
|
### Removing all characters from the last / back to leave only the filename
|
||||||
FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}"
|
FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}"
|
||||||
log "File was downloaded as $FILENAME"
|
|
||||||
|
|
||||||
## Downloading the discord package (tar.gz)
|
## 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() {
|
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() {
|
function do_install() {
|
||||||
|
|
||||||
cd "$INSTALL_DIR"
|
cd "$INSTALL_DIR"
|
||||||
@@ -107,20 +162,10 @@ function do_install() {
|
|||||||
|
|
||||||
update_desktop_file
|
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
|
[[ ! -d $ICON_DIR ]] && mkdir -p $ICON_DIR
|
||||||
cp $EXISTING_INSTALL/discord.png $ICON_DIR/
|
cp $EXISTING_INSTALL/discord.png $ICON_DIR/
|
||||||
sudo desktop-file-isntall $DESKTOP_FILE
|
|
||||||
|
remove_installer
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_upgrade(){
|
function do_upgrade(){
|
||||||
@@ -136,9 +181,7 @@ function do_upgrade(){
|
|||||||
|
|
||||||
update_desktop_file
|
update_desktop_file
|
||||||
|
|
||||||
if [[ $DESKTOP_FILE_INSTALLED -eq 0 ]]; then
|
remove_installer
|
||||||
sudo desktop-file-install $DESKTOP_FILE
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# END: Helper Functions
|
# END: Helper Functions
|
||||||
@@ -197,3 +240,32 @@ esac
|
|||||||
|
|
||||||
|
|
||||||
# END: Work
|
# 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
|
||||||
|
Reference in New Issue
Block a user