-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made the script faster and more user friendly
- Loading branch information
1 parent
1f2757d
commit 87da2c6
Showing
13 changed files
with
299 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
|
||
datadir = sys.argv[1] | ||
|
||
# Packaging tools define DESTDIR and this isn't needed for them | ||
if 'DESTDIR' not in os.environ: | ||
print('Compiling GSettings schemas...') | ||
subprocess.call(['glib-compile-schemas', | ||
os.path.join(datadir, 'glib-2.0', 'schemas')]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
project( | ||
'repomenu-schemas', 'c', | ||
version: '3.38.0', | ||
default_options: [ | ||
'warning_level=2' | ||
], | ||
license: 'LGPL', | ||
meson_version: '>= 0.50.0' | ||
) | ||
|
||
gsettings_desktop_schemas_name = meson.project_name() | ||
gsettings_desktop_schemas_version = meson.project_version() | ||
|
||
message('Building ' + gsettings_desktop_schemas_name + ' ' + gsettings_desktop_schemas_version) | ||
|
||
cc = meson.get_compiler('c') | ||
host_system = host_machine.system() | ||
arch = host_machine.cpu_family() | ||
|
||
prefix = get_option('prefix') | ||
bindir = join_paths(prefix, get_option('bindir')) | ||
libdir = join_paths(prefix, get_option('libdir')) | ||
libexecdir = join_paths(prefix, get_option('libexecdir')) | ||
includedir = join_paths(prefix, get_option('includedir')) | ||
datadir = join_paths(prefix, get_option('datadir')) | ||
sysconfdir = join_paths(prefix, get_option('sysconfdir')) | ||
schemasdir = join_paths(datadir, 'glib-2.0/schemas') | ||
|
||
gnome = import('gnome') | ||
|
||
# Generate pc file | ||
# Can't use pkgconfig helper https://github.com/mesonbuild/meson/issues/2253 | ||
conf = configuration_data() | ||
conf.set('prefix', prefix) | ||
conf.set('VERSION', meson.project_version()) | ||
conf.set('includedir', includedir) | ||
|
||
pkg = configure_file(configuration: conf, | ||
input: 'repomenu-snapshots-schemas.pc.in', | ||
install: true, | ||
install_dir: join_paths(datadir, 'pkgconfig'), | ||
output: 'repomenu-schemas.pc') | ||
|
||
glib_mkenums = find_program('glib-mkenums') | ||
|
||
subdir('schemas') | ||
|
||
# Keep this in sync with post-install.py expected arguments | ||
meson.add_install_script('build-aux/meson/post-install.py', | ||
datadir) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
prefix=@prefix@ | ||
|
||
Name: repomenu-snapshots-schemas | ||
Description: Shared GSettings schemas for the desktop, including helper headers | ||
Version: @VERSION@ | ||
Cflags: -I@includedir@/repomenu-snapshots-schemas |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
schemas = [ | ||
'org.therepoclub.repomenu.snapshots.preferences.gschema.xml', | ||
] | ||
|
||
conf = configuration_data() | ||
conf.set('prefix', prefix) | ||
conf.set('exec_prefix', prefix) | ||
conf.set('libdir', libdir) | ||
conf.set('bindir', bindir) | ||
conf.set('libexecdir', libexecdir) | ||
conf.set('datarootdir', datadir) | ||
conf.set('datadir', datadir) | ||
conf.set('includedir', includedir) | ||
|
||
generated_schemas = [] | ||
foreach schema: schemas | ||
generated_schemas += configure_file( | ||
output: schema, | ||
input: schema + '.in', | ||
configuration: conf, | ||
) | ||
endforeach | ||
|
||
install_data(generated_schemas, install_dir: schemasdir) | ||
|
||
install_data( | ||
'repomenu-snapshots-schemas.convert', | ||
install_dir: join_paths(datadir, 'GConf', 'gsettings'), | ||
) |
20 changes: 20 additions & 0 deletions
20
schemas/org.therepoclub.repomenu.snapshots.preferences.gschema.xml.in
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<schemalist> | ||
<schema path="/org/therepoclub/repomenu/snapshots/preferences/" id="org.therepoclub.repomenu.snapshots.preferences"> | ||
<key type="s" name="pacman"> | ||
<default>'5'</default> | ||
<summary>Number of pacman snapshots to save</summary> | ||
<description>This is the number of pacman snapshots to save.</description> | ||
</key> | ||
<key type="s" name="root"> | ||
<default>'15'</default> | ||
<summary>Number of root snapshots to save</summary> | ||
<description>This is the number of root snapshots to save.</description> | ||
</key> | ||
<key type="s" name="home"> | ||
<default>'15'</default> | ||
<summary>Number of home snapshots to save</summary> | ||
<description>This is the number of home snapshots to save.</description> | ||
</key> | ||
</schema> | ||
</schemalist> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# From org.therepoclub.repomenu.snapshots.preferences | ||
[org.therepoclub.repomenu.snapshots.preferences] | ||
pacman = 10 | ||
root = 10 | ||
home = 10 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#!/usr/bin/env bash | ||
cmd=$(basename $0) | ||
## Script metadata | ||
SCRIPTNAME=${0##*/} | ||
VERSION="2021.09.19" | ||
DESCRIPTION="A bach BTRFS Sanpshot wrapper" | ||
AUTHOR="The-Repo-Club <[email protected]>" | ||
|
||
## Set Colors (copied from makepkg) | ||
ALL_OFF="\e[1;0m" | ||
|
@@ -12,30 +16,130 @@ CYAN="\e[1:36m" | |
|
||
readonly ALL_OFF RED GREEN YELLOW BLUE PURPLE CYAN | ||
|
||
runas=$(whoami) | ||
main(){ | ||
runas=$(whoami) | ||
|
||
if [ $runas != 'root' ]; then | ||
printf ${GREEN}"%s ${RED}command must be ran as root\n" "$cmd" | ||
exit | ||
fi | ||
if [ $runas != 'root' ]; then | ||
printf ${GREEN}"%s ${RED}command must be ran as root\n" "$SCRIPTNAME" | ||
exit | ||
fi | ||
|
||
IndexOf() { | ||
x="${1%%$2*}" | ||
[ "$x" = "$1" ] || printf '%d' "${#x}" | ||
} | ||
|
||
declare -A PathCounts | ||
declare -A Paths | ||
NL='\n' | ||
|
||
while IFS= read -r Line; do | ||
|
||
set -- $Line | ||
|
||
# Path is after the first "path " | ||
Path=$9 | ||
|
||
# Get the index of the first / | ||
PathL2Index=$( IndexOf "$Path" '/' ) | ||
|
||
# Ignore paths that don't have a 2nd level | ||
[ -z "$PathL2Index" ] && continue | ||
|
||
Id=$2 | ||
|
||
#number of root snapshots | ||
rsl="$(btrfs subvolume list / | awk '/snap/ && /@root/' | wc -l)" | ||
# Path is after the first / in Path | ||
PathL2=${Path:$(( PathL2Index + 1 ))} | ||
|
||
#number of home snapshots | ||
hsl="$(btrfs subvolume list / | awk '/snap/ && /@home/' | wc -l)" | ||
# Remove the 10 char date from the end to isolate the name | ||
NameL2=${PathL2%????????????????????} | ||
|
||
printf ${GREEN}"list of root snapshots:${YELLOW} $rsl ${ALL_OFF}\n" | ||
# Remove the 1st character "@" | ||
NameL2=${NameL2:1} | ||
|
||
#list of root snapshots by name | ||
btrfs subvolume list / | awk '/snap/ && /@root/ {print $1"="$2" "$9}' | ||
# If -pacman exists in the NameL2, it's category is pacman | ||
if [ "${NameL2##*-pacman}" = "$1" ]; then | ||
Category='pacman' | ||
else | ||
Category=$NameL2 | ||
fi | ||
|
||
# Add NameL2 to appropriate category | ||
Paths["$Category"]="${Paths["$Category"]}ID=$Id $Path$NL" | ||
|
||
# Increment count in appropriate category | ||
(( PathCounts["$Category"]++ )) | ||
|
||
done <<< $(btrfs subvolume list /) | ||
|
||
FirstRun=1 | ||
for Key in "${!Paths[@]}"; do | ||
[ -n "$FirstRun" ] || printf '\n' | ||
printf "${GREEN}list of %s snapshots: ${YELLOW}%s${ALL_OFF}\n" "$Key" "${PathCounts[$Key]}" | ||
printf "${Paths[$Key]}"; | ||
FirstRun= | ||
done | ||
|
||
printf "\n" | ||
read -rsn1 -p "Press any key to continue";printf "\n" | ||
} | ||
|
||
#=== FUNCTION ================================================================= | ||
# Name: version | ||
# Description: Prints version information | ||
#============================================================================== | ||
|
||
version() { | ||
printf " | ||
%s v%s - %s | ||
This program may be freely redistributed under | ||
the terms of the GNU General Public License v3.0. | ||
%s | ||
\n" "$SCRIPTNAME" "$VERSION" "$DESCRIPTION" "$AUTHOR" | ||
exit | ||
} | ||
|
||
printf "\n" | ||
#=== FUNCTION ================================================================= | ||
# Name: usage | ||
# Description: Prints the usage | ||
#============================================================================== | ||
|
||
printf ${GREEN}"list of home snapshots:${YELLOW} $hsl ${ALL_OFF}\n" | ||
usage() { | ||
|
||
#list of home snapshots by name | ||
btrfs subvolume list / | awk '/snap/ && /@home/ {print $1"="$2" "$9}' | ||
printf " | ||
Snapshot the @ and @home btrfs subvolumes. | ||
Usage: | ||
%s... | ||
%s [options]... | ||
Options: | ||
-h, --help Display help. | ||
-v, --version Print version information and exits. | ||
\n" "$SCRIPTNAME" "$SCRIPTNAME" | ||
} | ||
|
||
printf "\n" | ||
read -rsn1 -p"Press any key to continue";echo | ||
while true; do | ||
case $1 in | ||
-h|--help|-\?) | ||
usage | ||
exit 0 | ||
;; | ||
-v|--version) | ||
version | ||
exit 0 | ||
;; | ||
--) | ||
shift | ||
break | ||
;; | ||
-*) | ||
error "Unknown option: $1" | ||
usage | ||
exit 1 | ||
;; | ||
*) | ||
main | ||
break | ||
;; | ||
esac | ||
done |
Oops, something went wrong.