common.sh in remote-config

at master

1#
2# common.sh
3#
4# This file contains utility functions and is sourced by remote scripts
5compare()
6{
7 one=`sha1sum /tmp/remote.$remotenum/$1 | awk '{print $1}'`
8 two=`sha1sum $2 | awk '{print $1}'`
9
10 if [ "$one" = "$two" ]
11 then
12 return 0
13 else
14 return 1
15 fi
16}
17
18redeploy()
19{
20 cp /tmp/remote.$remotenum/$1 $2
21 chown `id -un`:`id -gn` $2
22 if [ -n "$3" ]
23 then
24 if [ -z "$restart" ]
25 then
26 restart=$3
27 else
28 echo $restart | grep $3 || restart="$restart $3"
29 fi
30 fi
31}
32
33restart_services()
34{
35 if [ -n "$restart" ]
36 then
37 echo "Restarting services: $restart"
38 set -- $restart
39 systemctl restart "$@"
40 fi
41}
42
43install_packages()
44{
45 for package
46 do
47 if ! pacman -Q $package > /dev/null 2>&1
48 then
49 if [ -z "$packages" ]
50 then
51 packages=package
52 else
53 packages="$packages $package"
54 fi
55 fi
56 done
57
58 if [ -n "$packages" ]
59 then
60 echo "Installing packages: $packages"
61 set -- $packages
62 pacman -S --noconfirm "$@"
63 fi
64}
65
66start_services()
67{
68 for service
69 do
70 state=`systemctl show $service --property=ActiveState`
71 if [ ! "$state" = "ActiveState=active" ]
72 then
73 if [ -z "$services" ]
74 then
75 services=$service
76 else
77 services="$services $service"
78 fi
79 fi
80 done
81
82 if [ -n "$services" ]
83 then
84 echo "Starting services: $services"
85 set -- $services
86 systemctl start $services
87 fi
88}