-
Notifications
You must be signed in to change notification settings - Fork 2
/
aptigrate
executable file
·57 lines (46 loc) · 1.02 KB
/
aptigrate
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
#!/bin/bash
# default variables
default_dir="/var/log/aptigrate"
crondir="/var/spool/cron/crontabs"
# getting args
while getopts "o:c:" opt; do
case $opt in
o)
backup_dir="$OPTARG"
;;
c)
cron_exp="$OPTARG"
echo "$cron_exp"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# function definitions
create_cron() {
cronexp="$1 /usr/local/bin/aptigrate"
echo "$cronexp" | sudo tee $crondir/$USER>/dev/null
}
create_backup() {
apt list --manual-installed | sudo tee $backup_dir/backup.ap >/dev/null
}
# creating backup
if [ -z "$backup_dir" ]; then
apt list --manual-installed | sudo tee $default_dir/backup.ap >/dev/null
else
if [ -d "$backup_dir" ]; then
# Take action if $DIR exists.
echo "Creating a backup in "$backup_dir"..."
create_backup
else
mkdir $backup_dir >/dev/null 2>/dev/null
fi
fi
# creating cron
if [ -z "$cron_exp" ]; then
:
else
create_cron "$cron_exp"
fi