Repository navigation
Expand file tree
/
Copy pathCreateSessionScript.sh
More file actions
95 lines (87 loc) · 4.42 KB
/
Copy pathCreateSessionScript.sh
File metadata and controls
95 lines (87 loc) · 4.42 KB
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
#!/bin/bash
#CreateSessionScript.sh
#Just a simple script to guide users to create/update their SessionScripts
bold=$(tput bold)
normal=$(tput sgr0)
clear
echo "#################################################################"
echo "# #"
echo "# Session Script assistant - It's more a guide #"
echo "# #"
echo "#################################################################"
echo ""
echo "--------"
echo "${bold}1st step${normal} - Created a folder in /opt/appstream/SessionScripts/custom_scripts/"
echo "(if it's not created already)"
echo ""
read -p "Hit enter to continue..."
#Creates a scripts directory - This directory will be used to save customer scripts for Session Scripts.
[ ! -d /opt/appstream/SessionScripts/custom_scripts/ ] && sudo mkdir /opt/appstream/SessionScripts/custom_scripts/
echo ""
echo "--------"
echo "${bold}2nd step${normal} - Created an executable file called 'my_session_script.sh' in /opt/appstream/SessionScripts/custom_scripts/"
echo ""
read -p "I will now open GEDIT so you can paste your script - Hit enter to open GEDIT"
sudo touch /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
sudo chmod ugo+rwx /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
echo '#!/bin/bash' > /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
echo "" >> /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
echo "#Put your script below this line" >> /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
echo "" >> /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
sudo gedit /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh 2> /dev/null
sudo chmod ugo+x /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh
echo ""
echo "Your script is now set as: "
echo ""
echo " ----------------------------------------------------------------------"
echo "| |"
echo "| /opt/appstream/SessionScripts/custom_scripts/my_session_script.sh |"
echo "| |"
echo " ----------------------------------------------------------------------"
echo ""
read -p "Copy the above and hit enter to continue..."
echo ""
echo "--------"
echo "${bold}3rd step${normal} - Update CONFIG.JSON's 'Filename' value. Check the tips below:"
echo ""
echo " 1. Review this page to see an example:"
echo -e " \e[34mhttps://docs.aws.amazon.com/appstream2/latest/developerguide/create-session-scripts.html\e[0m"
echo ""
echo " 2. If you dont have 'Arguments' to declare, leave them blank \"\""
echo ""
echo -e " 3. Validate your config.json with \e[34mhttps://jsonlint.com\e[0m"
echo ""
echo " 4. Try to test your script before creating the image"
echo ""
echo ""
read -p "Hit enter to open GEDIT - Dont forget to save before closing it."
sudo gedit /opt/appstream/SessionScripts/config.json 2> /dev/null
clear
#QUESTION - Does it need to run as SUDO?
echo "Creating the script..."
if (whiptail --title "Create Environment Variables" --yesno "Does the script needs to run as SUDO?" 12 78); then
#checks if the group 'as2-sudo-users' exists in the OS
if [ ! $(getent group as2-sudo-users) ]; then
groupadd as2-sudo-users
fi
#checks if the group 'as2-sudo-users' exists in the sudoers file
sudo cat /etc/sudoers | grep as2-sudo-users &> /dev/null
if [[ $? == 1 ]]; then
#Creates a backup of /etc/sudoers, just in case...
sudo cp /etc/sudoers /etc/sudoers_as2_old
#Adds the group 'as2-sudo-users' to the sudoers file allowing it to perform administrative tasks WITHOUT asking for password
echo "" | sudo tee -a /etc/sudoers
echo "## AS2 Linux Image Assistant start" | sudo tee -a /etc/sudoers
echo "## The following line allows users in the group 'as2-sudo-users' to use sudo" | sudo tee -a /etc/sudoers
echo "%as2-sudo-users ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
echo "" | sudo tee -a /etc/sudoers
echo "## AS2 Linux Image Assistant end" | sudo tee -a /etc/sudoers
echo "" | sudo tee -a /etc/sudoers
fi
#Adds the user as2-streaming-user to the sudoers file
sudo usermod -a -G as2-sudo-users as2-streaming-user
whiptail --msgbox --title "Create Session Script" "Script created successfully!" 12 78
else
whiptail --msgbox --title "Create Session Script" "Script created successfully" 12 78
fi
exit