-
Notifications
You must be signed in to change notification settings - Fork 3
/
install
executable file
·106 lines (81 loc) · 3 KB
/
install
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
#!/bin/bash
if [ -t 1 ]
then
# Some colors
declare -A colors
colors[none]="\e[0m"
colors[red]="\e[31m"
colors[green]="\e[32m"
colors[yellow]="\e[33m"
colors[blue]="\e[34m"
colors[magenta]="\e[35m"
colors[cyan]="\e[36m"
colors[lightgray]="\e[37m"
colors[white]="\e[97m"
fi
_scriptRoot="$(dirname $(realpath $0))"
# Used for updating the conf file
conf="/etc/zfsUnlocker/zfsUnlocker.conf"
head="#$(git -C "$_scriptRoot" rev-parse HEAD)"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# Check if we need sudo
[[ $UID != 0 ]] && SUDO=`which sudo`
$SUDO mkdir -p /etc/zfsUnlocker
$SUDO rsync -r --delete $DIR/modules.d /etc/zfsUnlocker/
if [ -f "$conf" ]
then
if [ "$head" != "$($SUDO head -n1 "$conf")" ] || [[ "$@" == *"force"* ]] # If different commit/version of the script detected, rebuild the conf.
then
writeConf=1
echo "Installing new version, existing conf will be renamed and replaced."
confBak="${conf}_$(date +%s).bak"
$SUDO mv -v "$conf" "$confBak"
fi
else
writeConf=1
echo -e "\nBefore using this make sure you setup $conf."
fi
if [ -n "$writeConf" ]
then
echo "${head}" | $SUDO tee -a "${conf}" > /dev/null
$SUDO chown root:root $conf ; $SUDO chmod 600 $conf
fi
echo "Evaluating module package dependencies"
moduleBasedir="/etc/zfsUnlocker/modules.d"
modules="$(ls -1v $moduleBasedir| grep -v disabled)"
# We need 'which'
which -v >/dev/null 2>&1 || yes | sudo pacman -S which
for module in $modules
do
if [ -f ${moduleBasedir}/${module}/packageDependencies ]
then
echo "${module}:"
while read packageDependency
do
echo -ne '\t'
pacman -Q $packageDependency || yes | sudo pacman --noconfirm -S "$packageDependency"
done < ${moduleBasedir}/${module}/packageDependencies
fi
if [ -n "$writeConf" ]
then
echo "#${module}" | $SUDO tee -a "${conf}" > /dev/null
cat ${moduleBasedir}/${module}/configVars | $SUDO tee -a "${conf}" > /dev/null
echo "" | $SUDO tee -a "${conf}" # spacer
fi
done
$SUDO cp $DIR/zfsUnlocker.hook /usr/lib/initcpio/hooks/zfsUnlocker
$SUDO cp $DIR/zfsUnlocker.install /usr/lib/initcpio/install/zfsUnlocker
find /etc/zfsUnlocker -type f -name 'hook' -exec $SUDO chmod 740 "{}" \;
# Append custom variables from previous file.
if [ -n "${confBak}" ]
then
variableDifferences="$(comm -23 <($SUDO grep -v '^#' "${confBak}" | sort -u) <($SUDO grep -v '^#' "${conf}" | sort -u))"
if [ -n "${variableDifferences}" ]
then
echo -e "${colors[red]}Old ${colors[none]}${conf}${colors[red]} moved to ${colors[none]}${confBak}${colors[red]}.${colors[none]}"
echo -e "${colors[red]}The script will attempt to append previously used variables to this new config. Please review the content before continuing.${colors[none]}"
echo -e "Appending previous config..."
echo "# Configuration copied from previous version [$($SUDO head -n1 ${confBak})] [${confBak}]:" | $SUDO tee -a "${conf}"
echo "${variableDifferences}" | $SUDO tee -a "${conf}"
fi
fi