source: trunk/luci/modules/admin-fon/root/sbin/save-config.sh

Last change on this file was 2371, checked in by matthijs, 4 years ago

base-files: Source /etc/profile.local on (SSH) login

This allows adding things to the profile, without having to modify an
existing file. This additionally allows including these changes in the
backup and preserve them through upgrades.

Thanks to Thomas Horner for the base for this patch.

Closes: #1256

  • Property svn:executable set to *
File size: 5.0 KB
Line 
1#!/bin/ash
2
3# This script creates a file /tmp/sysupgrade.tgz containing all relevant
4# settings to be backed up. This is done mostly by putting complete
5# files into the tarball. However, some files in /etc/config only need
6# to be backed up partially (because only a small part is
7# user-changeable and the rest could change between firmware versions).
8# For this reason, there is an embedded script below, that generates
9# some uci commands to restore just those settings. These commands are
10# stored in /etc/uci-defaults/zzz-upgrade, where they will  be run at
11# next boot (after an upgrade) or by luci (after a settings restore).
12
13# Also note that this script is shipped in the main firmware for the
14# settings backup through the webgui, but also copied into the tarballs
15# for firmware releases.
16
17# This is the embedded script that cherry-picks various config options.
18sh << 'END_OF_SUBSCRIPT' > /etc/uci-defaults/zzz-upgrade
19. /etc/functions.sh
20
21# Preserve the pass_good variable, which seems to be the only
22# user-settable setting in the system config.
23config_load 'system'
24
25if [ "$(config_get fon pass_good)" = "1" ]; then
26    echo "uci set system.fon.pass_good=1"
27    echo "uci commit system"
28fi
29
30config_clear
31
32# Preserve the per-service 'fwall' setting, which seems to be the only
33# user-settable setting from the services config.
34echo "uci import -m services <<EOF"
35config_load 'services'
36save_service() {
37    val="$(config_get "$1" 'fwall')"
38    if [ -n "$val" ]; then
39        echo "config 'service' '$1'"
40        echo "  option 'fwall' '$val'"
41    fi
42}
43config_foreach save_service 'service'
44config_clear
45
46echo "EOF"
47echo "uci commit services"
48
49# Backup firewall settings for fmg images (just torrent is supported
50# right now)
51config_load 'fmg'
52echo "uci set fmg.torrent.fwall=$(config_get torrent fwall)"
53echo "uci commit fmg"
54config_clear
55
56# Preserve all port forwards (redirect sections) from the firewall
57# config. This is the only part of the firewall config that can be
58# changed by the user. By not backing up the rest of the file, we
59# prevent problems with changes made to the (default) firewall config in
60# r1585 and r1857 that would be overwritten when backing up the complete
61# file.
62echo "uci import -m firewall <<EOF"
63config_cb() {
64    [ "$1" = "redirect" ] && echo "config '$1' '$2'"
65}
66
67option_cb() {
68    local type=$(config_get "$CONFIG_SECTION" TYPE)
69    [ "$type" = "redirect" ] &&
70        echo "  option '$1' '$2'"
71}
72
73
74config_load 'firewall'
75config_clear
76echo "EOF"
77echo "uci commit firewall"
78reset_cb
79
80# Preserve all download and cookie sections from the dlmanager config.
81# This allows new providers to be added, without throwing away the
82# existing cookies (logins) and downloads. We use the callbacks instead
83# of foreach here, since we don't know all of the option names in
84# advance.
85echo "uci import -m luci_dlmanager <<EOF"
86config_cb() {
87    [ "$1" = "cookie" -o "$1" = "download" ] && echo "config '$1' '$2'"
88}
89
90option_cb() {
91    local type=$(config_get "$CONFIG_SECTION" TYPE)
92    [ "$type" = "cookie" -o  "$type" = "download" ] &&
93        echo "  option '$1' '$2'"
94}
95
96
97config_load 'luci_dlmanager'
98# Also keep some dlmanager settings
99echo "config 'dlmanager' 'dlmanager'"
100echo "  option base '$(config_get dlmanager base)'"
101echo "  option threads '$(config_get dlmanager threads)'"
102echo "  option when '$(config_get dlmanager when)'"
103echo "EOF"
104echo "uci commit luci_dlmanager"
105config_clear
106reset_cb
107
108# Save qos settings
109config_load 'qos'
110
111echo "uci set 'qos.wan.enabled=$(config_get wan enabled)'"
112echo "uci set 'qos.wan.download=$(config_get wan download)'"
113echo "uci set 'qos.wan.upload=$(config_get wan upload)'"
114echo "uci commit qos"
115
116config_clear
117
118# Keep OpenVPN settings
119config_load 'openvpn'
120
121echo "uci import -m openvpn <<EOF"
122echo "config 'openvpn' 'openvpn'"
123for o in enable lan wan keepalive max_clients proto port tls_auth client_to_client public; do
124        echo "  option '$o' '$(config_get openvpn $o)'"
125done
126save_client() {
127    echo "config 'client' '$1'"
128    echo "      option 'name' '$(config_get "$1" name)'"
129    echo "      option 'ip' '$(config_get "$1" ip)'"
130}
131config_foreach save_client 'client'
132echo "EOF"
133echo "uci commit openvpn"
134config_clear
135
136# Save luci language setting
137config_load 'luci'
138
139echo "uci set luci.main.lang=$(config_get main lang)"
140echo "uci commit luci"
141
142config_clear
143
144END_OF_SUBSCRIPT
145
146# Create the tarball, containing a bunch of complete config files and
147# the above generated uci commands.
148tar cvzf /tmp/sysupgrade.tgz /etc/uci-defaults /etc/passwd /etc/group /etc/dropbear /etc/samba/smbpasswd /etc/samba/secrets.tdb /etc/firewall.user /etc/config/upnpd /etc/config/registered /etc/config/gdata /etc/config/facebook /etc/config/flickr /etc/config/mountd /etc/config/fon /etc/config/ddns /etc/config/wizard /etc/pureftpd.passwd /etc/pureftpd.pdb /etc/config/pureftpd /etc/config/samba /etc/config/twitter /etc/config/luci_ethers /etc/openvpn/keys /etc/config/uploadd /etc/nixio /etc/config/luci_wol /etc/profile.local
149
150# Rememove the zzz-upgrade file again. It ended up in the tarball, no
151# need to run it again on the next upgrade.
152rm /etc/uci-defaults/zzz-upgrade
Note: See TracBrowser for help on using the repository browser.