summaryrefslogtreecommitdiff
path: root/pkg/linux/leap-install-helper.sh
blob: 566dd3d9190df1f7d9abee27e4b2c5afc38d7fa8 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash

# File: leap-install-helper.sh
# Copy the needed binaries and helper files to their destination.
# Copyright (C) 2014 LEAP Encryption Access Project.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

LOCAL_SBIN_FOLDER=/usr/local/sbin

POLKIT_FOLDER="/usr/share/polkit-1/actions"
POLKIT_FILE="se.leap.bitmask.bundle.policy"
POLKIT_PATH="${POLKIT_FOLDER}/${POLKIT_FILE}"

BITMASK_ROOT_FILE="bitmask-root"
BITMASK_ROOT_PATH="${LOCAL_SBIN_FOLDER}/${BITMASK_ROOT_FILE}"

OPENVPN_FILE="leap-openvpn"
OPENVPN_PATH="${LOCAL_SBIN_FOLDER}/${OPENVPN_FILE}"

# The following array stores global files that have been deprecated and we want
# to remove from the system path, after having dropped them there in the past.

DEPRECATED_FILES=(
  '/usr/share/polkit-1/actions/net.openvpn.gui.leap.policy'
)


# Variables for parsing and storing the script options.

FROM_PATH=NONE
REMOVE_OLD_FILES=NO
INSTALL_BITMASK_ROOT=NO
INSTALL_POLKIT_FILE=NO
INSTALL_OPENVPN=NO


# Process the options

while [[ $# > 1 ]]
do
key="$1"
shift

case $key in
    -f|--from-path)
    FROM_PATH="$1"
    shift
    ;;
    -r|--remove-old-files)
    REMOVE_OLD_FILES="$1"
    shift
    ;;
    --install-bitmask-root)
    INSTALL_BITMASK_ROOT="$1"
    shift
    ;;
    --install-polkit-file)
    INSTALL_POLKIT_FILE="$1"
    shift
    ;;
    --install-openvpn)
    INSTALL_OPENVPN="$1"
    shift
    ;;
    *)
    # unknown option
    ;;
esac
done
echo "LEAP_INSTALL_HELPER"
echo "-------------------"
echo FROM_PATH	          = "${FROM_PATH}"
echo REMOVE_OLD_FILES     = "${REMOVE_OLD_FILES}"
echo INSTALL_BITMASK_ROOT = "${INSTALL_BITMASK_ROOT}"
echo INSTALL_POLKIT_FILE  = "${INSTALL_POLKIT_FILE}"
echo INSTALL_OPENVPN      = "${INSTALL_OPENVPN}"
echo


#
# helper functions
#

function check_current_uid() {
  current_uid=`id | sed 's/^uid=//;s/(.*$//'`
  if [ $current_uid != 0 ]
  then
    echo "[ERROR] NEED TO BE RUN AS ROOT"
    exit 1
  fi
}

function check_from_path() {
  if [ $FROM_PATH == NONE ]
  then
    echo "[ERROR] YOU NEED TO GIVE --from-path VALUE..."
    exit 1
  fi
}

function remove_old_files() {
  for file in "${DEPRECATED_FILES[@]}"
  do
    rm $file
  done
}

function copy_bitmask_root() {
  mkdir -p "${LOCAL_SBIN_FOLDER}"
  cp "${FROM_PATH}/${BITMASK_ROOT_FILE}" "${BITMASK_ROOT_PATH}"
  chmod 744 "${BITMASK_ROOT_PATH}"

}

function copy_polkit_file() {
  cp "${FROM_PATH}/${POLKIT_FILE}" "${POLKIT_PATH}"
  chmod 644 "${POLKIT_PATH}"
}

function copy_openvpn_file() {
  mkdir -p "${LOCAL_SBIN_FOLDER}"
  cp "${FROM_PATH}/${OPENVPN_FILE}" "${OPENVPN_PATH}"
  chmod 744 "${OPENVPN_PATH}"

}


#
# Process options and run functions.
#

check_current_uid

if [ $INSTALL_BITMASK_ROOT == YES ] || [ $INSTALL_POLKIT_FILE == YES ] || [ $INSTALL_OPENVPN == YES ]
then
  check_from_path
fi

if [ $REMOVE_OLD_FILES == YES ]
then
  echo "REMOVING OLD FILES..."
  remove_old_files
fi

if [ $INSTALL_BITMASK_ROOT == YES ]
then
  echo "INSTALLING bitmask-root..."
  copy_bitmask_root
fi

if [ $INSTALL_POLKIT_FILE == YES ]
then
  echo "INSTALLING policykit file..."
  copy_polkit_file
fi

if [ $INSTALL_OPENVPN == YES ]
then
  echo "INSTALLING openvpn..."
  copy_openvpn_file
fi