]> git.ipfire.org Git - ipfire-2.x.git/blame - src/pakfire/lib/functions.sh
pakfire: Put tar options into an array
[ipfire-2.x.git] / src / pakfire / lib / functions.sh
CommitLineData
cde0e116 1#!/bin/bash
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
ace40c90 5# Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
cde0e116 21
c3bbdb21
MT
22. /etc/sysconfig/rc
23. $rc_functions
24
b6cad4d2
MT
25TAR_OPTIONS=(
26 --acls
27 --xattrs
28 --xattrs-include='*'
29 --no-overwrite-dir
30 --preserve-permissions
31 --numeric-owner
32)
33
cde0e116
MT
34extract_files() {
35 echo "Extracting files..."
b6cad4d2 36 tar -xavf /opt/pakfire/tmp/files* "${TAR_OPTIONS[@]}" -C /
7d3af7f7 37 echo "...Finished."
cde0e116 38}
fe7fe395 39
ace40c90
AF
40extract_backup_includes() {
41 echo "Extracting backup includes..."
b6cad4d2 42 tar xavf /opt/pakfire/tmp/files* "${TAR_OPTIONS[@]}" -C / \
ace40c90
AF
43 var/ipfire/backup/addons/includes
44 echo "...Finished."
45}
46
c3bbdb21
MT
47remove_files() {
48 echo "Removing files..."
343262e6
AF
49 for i in $(cat /opt/pakfire/db/rootfiles/${NAME}); do
50 rm -rfv /${i}
c3bbdb21 51 done
fe7fe395
MT
52 echo "...Finished."
53}
54
b8e5a9c5 55make_backup() {
83d95bf1
MT
56 if [ -e "/var/ipfire/backup/addons/includes/${1}" ]; then
57 echo "Creating Backup..."
58 /usr/local/bin/backupctrl addonbackup ${1}
59 echo "...Finished."
30945c78 60 fi
5ad5a6bc
MT
61}
62
b8e5a9c5 63restore_backup() {
83d95bf1
MT
64 if [ -e "/var/ipfire/backup/addons/backup/${1}.ipf" ]; then
65 echo "Restoring Backup..."
66 /usr/local/bin/backupctrl restoreaddon ${1}.ipf
67 echo "...Finished."
30945c78 68 fi
5ad5a6bc
MT
69}
70
fe7fe395 71restart_service() {
30945c78 72 /etc/init.d/${1} restart
fe7fe395 73}
c3bbdb21
MT
74
75start_service() {
76 DELAY=0
77 while true
30945c78 78 do
c3bbdb21
MT
79 case "${1}" in
80 --delay|-d)
81 DELAY=${2}
82 shift 2
83 ;;
84 --background|-b)
85 BACKGROUND="&"
86 shift
87 ;;
88 -*)
89 log_failure_msg "Unknown Option: ${1}"
90 return 2 #invalid or excess argument(s)
91 ;;
92 *)
93 break
61a70439 94 ;;
c3bbdb21 95 esac
30945c78 96 done
61a70439 97
e6fd1f2d 98 if [ -f "/etc/init.d/${1}" ]; then
70e5098c 99 if [ -n "${BACKGROUND}" ]; then
6bb14162
MT
100 (sleep ${DELAY} && /etc/init.d/${1} start) &
101 else
102 sleep ${DELAY} && /etc/init.d/${1} start
103 fi
83d95bf1 104 fi
c3bbdb21
MT
105}
106
107stop_service() {
e6fd1f2d 108 if [ -f "/etc/init.d/${1}" ]; then
83d95bf1 109 /etc/init.d/${1} stop
30945c78 110 fi
c3bbdb21 111}
a86255ef
MT
112
113rebuild_langcache() {
114 echo "Rebuilding language cache..."
115 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
116 echo "...Finished."
117}
118