-
Notifications
You must be signed in to change notification settings - Fork 4
/
eos-shifttime
executable file
·74 lines (65 loc) · 2.96 KB
/
eos-shifttime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
#
# This script enables an after-the-fact timeshift equivalent for Arch systems
# Give it a date (as in 2020-09-20) and it will use the Arch archive repos
# to revert to the package state that applied on that date.
#
# Note: no AUR package will be reverted.
#
# 21 September 2020 - freebird54
# 21 July 2021 - changes by manuel
#
# Get some useful definitions:
source /usr/share/endeavouros/scripts/eos-script-lib-yad || exit 1
export -f eos_yad
export -f eos_GetProgName
export -f eos_GetArch
# EOS_ROOTER
DIE() {
local msg="$1"
local title="$2" # optional, default is "Error"
[ -n "$title" ] || title="Error"
echo "$1" | eos_yad --text-info --title="$title" --text="Message from '$progname':" --image=error --button=yad-quit
exit 1
}
STOP() { DIE "$1" Warning; }
DateValidityCheck() {
[ -n "$REVERTDATE" ] || exit 1 # No date selected.
[ "$REVERTDATE" = "$stopdate" ] && STOP "Current date selected, nothing to do."
curl -Lsm 10 -o/dev/null --fail "$urlbase" || DIE "Archive at $REVERTDATE not found!"
}
Main()
{
local progname="$(eos_GetProgName)"
case "$(eos_GetArch)" in
x86_64) ;;
*) DIE "This program is supported only on x86_64 machines." ;; # because of mirrors...
esac
eos_assert_deps $progname yad || return 1
local date=$(/usr/bin/date +%Y%m%d-%H%M) # for temporary backup file
local stopdate="$(/usr/bin/date +%Y/%m/%d)" # for checking if user selected this date
local mlist=/etc/pacman.d/mirrorlist
local bak="$mlist.$progname.$date"
local txt="This app can revert (downgrade) packages of this system to the state they were in\non the selected date.\n"
txt+="Note: AUR packages will <i>not</i> be reverted.\n\n"
txt+="Please select the date to revert your packages to.\n"
local REVERTDATE=$(eos_yad --calendar --title "Select Date" --text="$txt" --image=dialog-question --date-format=%C%y/%m/%d \
--button='yad-cancel!!Do nothing':1 --button='Revert!dialog-yes!Downgrade':0)
local urlbase="https://archive.archlinux.org/repos/$REVERTDATE"
local cmd=""
local cmd2=""
local tmpmlist
DateValidityCheck
# Create a temporary mirrorlist for the specified date.
tmpmlist=$(mktemp)
printf "## Reversion mirrorlist\n\n" > $tmpmlist
printf "%s\n\n" "Server = $urlbase/\$repo/os/\$arch" >> $tmpmlist
cmd="mv $mlist '$bak'" # Backups original mirrorlist and
cmd+=";mv $tmpmlist $mlist" # uses the reverted list.
cmd+=";pacman -Syyuu" # Runs the 'downdate' command.
cmd+=";mv '$bak' $mlist" # Restores the original mirrorlist from backup.
cmd+=";chmod 0644 $mlist" # Make sure mirrorlist has proper permissions.
cmd2="$(echo "$cmd" | tr ';' '\n' | sed 's|^| |')"
RunInTerminal "printf 'Reverting all packages to $REVERTDATE\n\n'; echo 'Need elevated privileges to run commands:'; echo '$cmd2'; $EOS_ROOTER '$cmd'"
}
Main "$@"