Merge remote-tracking branch 'origin/next' into kernel-update
[people/teissler/ipfire-2.x.git] / src / pakfire / lib / functions.sh
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
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 ###############################################################################
21
22 . /etc/sysconfig/rc
23 . $rc_functions
24
25 extract_files() {
26 echo "Extracting files..."
27 tar xvf /opt/pakfire/tmp/files --no-overwrite-dir -p --numeric-owner -C /
28 echo "...Finished."
29 }
30
31 extract_backup_includes() {
32 echo "Extracting backup includes..."
33 tar xvf /opt/pakfire/tmp/files --no-overwrite-dir -p --numeric-owner -C / \
34 var/ipfire/backup/addons/includes
35 echo "...Finished."
36 }
37
38 remove_files() {
39 echo "Removing files..."
40 for i in $(cat /opt/pakfire/db/rootfiles/${NAME}); do
41 rm -rfv /${i}
42 done
43 echo "...Finished."
44 }
45
46 make_backup() {
47 if [ -e "/var/ipfire/backup/addons/includes/${1}" ]; then
48 echo "Creating Backup..."
49 /usr/local/bin/backupctrl addonbackup ${1}
50 echo "...Finished."
51 fi
52 }
53
54 restore_backup() {
55 if [ -e "/var/ipfire/backup/addons/backup/${1}.ipf" ]; then
56 echo "Restoring Backup..."
57 /usr/local/bin/backupctrl restoreaddon ${1}.ipf
58 echo "...Finished."
59 fi
60 }
61
62 restart_service() {
63 /etc/init.d/${1} restart
64 }
65
66 start_service() {
67 DELAY=0
68 while true
69 do
70 case "${1}" in
71 --delay|-d)
72 DELAY=${2}
73 shift 2
74 ;;
75 --background|-b)
76 BACKGROUND="&"
77 shift
78 ;;
79 -*)
80 log_failure_msg "Unknown Option: ${1}"
81 return 2 #invalid or excess argument(s)
82 ;;
83 *)
84 break
85 ;;
86 esac
87 done
88
89 if [ -e "/etc/init.d/${1}" ]; then
90 if [ -n "${BACKGROUND}" ]; then
91 (sleep ${DELAY} && /etc/init.d/${1} start) &
92 else
93 sleep ${DELAY} && /etc/init.d/${1} start
94 fi
95 fi
96 }
97
98 stop_service() {
99 if [ -e "/etc/init.d/${1}" ]; then
100 /etc/init.d/${1} stop
101 fi
102 }
103
104 rebuild_langcache() {
105 echo "Rebuilding language cache..."
106 perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
107 echo "...Finished."
108 }
109